The Doctrine Common annotations library defines 2 annotation readers that both implement the Reader
interface:
Doctrine\Common\Annotations\AnnotationReader
Doctrine\Common\Annotations\SimpleAnnotationReader
Anyone knows the difference between them?
The only hint I have is the docblock on SimpleAnnotationReader
:
This annotation reader is intended to be used in projects where you have full-control over all annotations that are available.
You can give it a list of excluded annotations like @param
and @return
to ignore. It can be a problem since it's hard to exclude any possible annotation that you don't want.
Code example:
AnnotationRegistry::registerAutoloadNamespace('My\Annotation', 'dir/');
$this->annotationReader = new SimpleAnnotationReader();
$this->annotationReader->addNamespace('My\Annotation');
I will not get errors if there is any unknown annotation in the file.
There's one catch though: if the user makes a typo in the annotation name, then the reader will silently ignore it :(
Source: while developing PHP-DI, I tested both. The SimpleAnnotationReader
is better for me because I want it to only read my @Inject
annotation. When using AnnotationReader
, I got errors if there was any unknown annotation in the file (for example @expectedException
from PHPUnit).
See also this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With