-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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 $
).