Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 105 lines (77 sloc) 1.77 KB

Annotations

Content

Usage

At first you should register AnnotationsExtension at your config file.

extensions:
    annotations: Nettrine\Annotations\DI\AnnotationsExtension

Configuration

annotations:
    debug: %debugMode%
    ignore: []
    cache: Doctrine\Common\Cache\FilesystemCache

Optionally you can configure ignored annotations:

annotations:
    ignore:
        - someIgnoredAnnotation

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

annotations:
    cache: @mycache

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;
	}

}

Use annotation in your class.

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

}

Now you can use Reader service from your Container.

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

And get class, method or property annotations.

$annotations = $this->reader->getClassAnnotations(new \ReflectionClass(SampleClass::class));
$annotations[0]->getValue(); //foo
You can’t perform that action at this time.