-
Notifications
You must be signed in to change notification settings - Fork 2
Annotations
jamolkhon edited this page Feb 21, 2012
·
4 revisions
Each annotation is a class that implements Sharbat\Inject\Annotation
interface. All Sharbat annotations are namespaced and written inside phpDoc blocks in the following manner:
/**
* \Sharbat\Inject\@InScope(\Sharbat\Inject\Singleton)
*/
class ASingletonClass {
/**
* \Sharbat\Inject\@Inject(ADependencyClass)
*/
private $aDependencyClass;
}
Typing fully qualified name every time is not fun. One would want to write them like @Inject
and @Singleton
. This is definitely doable. For each annotation create a class (preferably with the same name) in the global namespace, that extends the target annotation class.
class Inject extends \Sharbat\Inject\Inject {}
class Singleton extends \Sharbat\Inject\InScope {
public function __construct() {
parent::__construct('\Sharbat\Inject\Singleton');
}
}
Result:
/**
* @Singleton
*/
class ASingletonClass {
/**
* @Inject(ADependencyClass)
*/
private $aDependencyClass;
}