Latest release: v0.3

Annotations

Content

Usage

At first you should register AnnotationsExtension at your config file.

extensions:
    annotations: Nettrine\Annotations\DI\AnnotationsExtension
1
2

Configuration

annotations:
    debug: %debugMode%
    ignore: []
    cache: Doctrine\Common\Cache\FilesystemCache
1
2
3
4

Optionally you can configure ignored annotations:

annotations:
    ignore:
        - someIgnoredAnnotation
1
2
3

Refer already defined cache (instance of Doctrine\Common\Cache).

annotations:
    cache: @mycache
1
2

Example

Create own annotation. Specify your targets CLASS, METHOD, PROPERTY, ALL, ANNOTATION.

More you can find at official documentation.

use Doctrine\Common\Annotations\Annotation;

/**
 * @Annotation
 * @Target("CLASS")
 */
class SampleAnnotation
{

	/** @var string|NULL */
	private $value;

	/**
	 * @param string[] $values
	 */
	public function __construct(array $values)
	{
		$this->value = isset($values['value']) ? $values['value'] : NULL;
	}

	/**
	 * @return string|NULL
	 */
	public function getValue()
	{
		return $this->value;
	}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

Use annotation in your class.

/**
 * @SampleAnnotation(value="foo")
 */
class SampleClass
{

}
1
2
3
4
5
6
7

Now you can use Reader service from your Container.

/** @var Doctrine\Common\Annotations\Reader @inject */
public $reader;
1
2

And get class, method or property annotations.

$annotations = $this->reader->getClassAnnotations(new \ReflectionClass(SampleClass::class));
$annotations[0]->getValue(); //foo
1
2