Skip to content

Parameter annotations #218

@thekid

Description

@thekid

Scope of Change

Annotations on method parameters will be allowed.

Rationale

Originally motivated from XP Framework's pull request #33 - Stubbles IoC container and dependency injection.

Functionality

Influenced by syntax discussion in xp-framework/xp-framework#116

Syntax

While the original idea was to add /*[@inject(name= 'db')]*/ in front of the parameter inside the declaration, it was decided for visual reasons and being inspired by C#'s attribute targets (see http://msdn.microsoft.com/library/z0w1kczw.aspx) to use the following form:

<?php
  class Example extends Object {

    #[@$conn: inject(name= 'db')[
    public function setConnection(DBConnection $conn)  {
      // ...
    }
  }
?>

Reflection

The lang.reflect.Parameter class will be extended by the following methods:

  public bool hasAnnotation(string $name, [string $key= null])
  public var getAnnotation(string $name, [string $key= null]) throws lang.ElementNotFoundException
  public bool hasAnnotations()
  public var[] getAnnotations()

Security considerations

n/a

Speed impact

Slower as method signatures need to be parsed, too.

Dependencies

This adds $details[DETAILS_TARGET_ANNO] to the class meta information. It contains annotations with targets. Parameter annotation are just special targets whose name matches the parameter name (including the $).

Related documents

xp-framework/xp-framework#33

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions