Maslosoft Addendum Documentation
Easy to use php annotations
Creating Annotations
To make annotation engine recognize annotations and react on them, for each annotation separate class should be created.
Each annotation class name should end with Annotation
,
however when annotating classes this suffix should be omitted.
This class should extend from MetaAnnotation
and must define init()
method
as well should define propery value
with default of null
. It is
important to define value
as it might be later used with ParamsExpander
.
It is annotation class responsibility to set entity value
Annotation should set entity value, so that the annotation itself
will decide on what to do if it is called multiple time, or
how to handle incoming data. When extending from MetaAnnotation
,
annotation init()
method will have available
methods for obtaining and working with metadata:
getEntity()
- returns entity on which current annotation is defined - this might be of type:MetaType
- containing class (type) metadata, ie annotations defined aboveclass
keywordMetaMethod
- metadata for methodMetaMethod
- metadata for property
getMeta()
- returns wholeMeta
container, allowing to obtain for example type information from method or property annotation.
It is possible to limit where annotation can be placed or which other annotation our annotation should avoid
Example @Label
annotation class
namespace Maslosoft\AddendumTest\Annotations;
class LabelAnnotation extends \Maslosoft\Addendum\Collections\MetaAnnotation
{
public $value;
public function init()
{
$this->getEntity()->label = (string) $this->value;
}
}
See also this repository and blog post for extra details.