Maslosoft Addendum Documentation
Easy to use php annotations
Annotating Classes
The annotation are special kinds of PHPDoc documentation parts, which can be interpreted later to obtain extra information about class, it's methods and properties.
To annotate class add special documentation value. This value
can also take arguments based in particular annotation
implementation. As each of @AnnotationName
blocks
will load corresponding class and set it's parameters.
Each class with annotations must implement
AnnotatedInterface
. This interface is empty, it is
information that the class should be parsed by annotation engine.
Example of annotating class
namespace Acme\Components;
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
/**
* @Label('My Component')
*/
class MyComponent implements AnnotatedInterface
{
}
Having @Label
placed on MyComponent
will allow annotations
engine to create instance of LabelAnnotation
and set
it's value to Component
.
Obtaining data
To obtain pre-processed value of annotation the preferred
way is to use Meta
container, which will return object containing
metadata.
Meta container is designed to be very lightweight. Once data is cached, it will perform like normal PHP code.
In this example, we assume that @Label
will simply set label
property of Meta
:
$meta = Meta::create(MyComponent::class)
The value of $meta
is instance of Meta
; To get data
for class, we need to call type()
method which
will return instance of - yes You guessed it - MetaType
.
This object contains our label
value:
echo $meta->type()->label; //My Component
Will output My Component.
See also this repository and blog post for extra details.