Below you will find pages that utilize the taxonomy term “Doctrine Common”
Symfony2: Creating a Metadata Factory for Processing Custom Annotations
Earlier I wrote about how to create a custom annotation class. I used the annotation reader from Doctrine Common to check for the existence of the custom annotation inside the DocComment block. It is also possible to process the annotations on beforehand, and collect the processed data in ClassMetadata
and PropertyMetadata
objects. These objects are created by a MetadataFactory
. The factory uses Drivers
to collect the metadata.
My purpose in this article is to create a custom annotation @DefaultValue
which allows me to define default values for properties of a class. It should work like this:
Symfony2 & Doctrine Common: creating powerful annotations
I was looking into the Doctrine Common library; it seems to me that especially the AnnotationReader
is quite interesting. Several Symfony2 bundles use annotation for quick configuration. For example adding an @Route
annotation to your actions allows you to add them “automatically” to the route collection. The bundles that leverage the possibilities of annotation all use the Doctrine Common AnnotationReader (in fact, the cached version) for retrieving all the annotations from your classes and methods. The annotation reader works like this: it looks for annotations, for which it tries to instantiate a class. This may be a class made available by adding a use
statement to your file. That is why you have to add use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
to any PHP file in which you use the @Route
annotation.