Maslosoft Addendum Documentation
Easy to use php annotations
Registering Namespace
Annotation engine will search for annotation classes only on registered namespaces. It uses embedded dependency injection to obtain configuration. While this name might sound scary, without going into details, attaching namespaces can be done with one method call.
As for now PHP does not contain ::namespace
magic constant,
so it is highly advisable to define class constant pointing
to namespace with const Ns = __NAMESPACE__
Attaching Configuration
use Maslosoft\Addendum\Addendum;
use Maslosoft\EmbeDi\Adapters\ArrayAdapter;
use Maslosoft\EmbeDi\EmbeDi;
$config = [
'addendum' => [
'class' => Addendum::class,
'namespaces' => [
'Acme\\Project\\Annotations'
]
]
];
EmbeDi::fly()->addAdapter(new ArrayAdapter($config));
The above snipped can be a bit more clean when used with one of annotations class
with predefined Ns
constant:
use Maslosoft\Addendum\Addendum;
use Maslosoft\EmbeDi\Adapters\ArrayAdapter;
use Maslosoft\EmbeDi\EmbeDi;
use Acme\Project\Annotations\MyAnnotation;
$config = [
'addendum' => [
'class' => Addendum::class,
'namespaces' => [
MyAnnotation::Ns
]
]
];
EmbeDi::fly()->addAdapter(new ArrayAdapter($config));
See also this repository and blog post for extra details.