<?php
use Laminas\Code\Annotation\Parser\GenericAnnotationParser;
use Laminas\Code\Annotation\AnnotationManager;
use Laminas\Code\Annotation\AnnotationInterface;
use Laminas\Code\Reflection\PropertyReflection;
final class Foo implements AnnotationInterface
{
public $value;
public $value2;
// handle content parsing of annotation
public function initialize($content)
{
// don't forget format errorhandling
$props = explode(',', $content);
foreach($props as $propStr) {
list($name, $value) = explode('=', trim($propStr));
$this->$name = $value;
}
}
}
class MyClass
{
/**
* @Foo(value=myValue, value2=1)
*/
private $myProp;
}
$parser = new GenericAnnotationParser();
$parser->registerAnnotation('Foo');
$annotationManager = new AnnotationManager();
$annotationManager->attach($parser);
$reflection = new PropertyReflection('MyClass', 'myProp');
$annotations = $reflection
->getAnnotations($annotationManager);
dump($annotations[0]);
^ Foo {#1406 +value: "myValue" +value2: "1" }