Where is Symfony's annotations function (routing, data validation, ORM, etc.) implemented?
I'm asking where the code is, not how it's implemented. The way I'm estimating is analysis
tokens
and the Reflection API for PHP. Is it implemented with the doctrine annotations component?
Reply content:
Where is Symfony's annotations function (routing, data validation, ORM, etc.) implemented?
I'm asking where the code is, not how it's implemented. The implementation approach I'm estimating is tokens
the parsing and the PHP reflection API. Is it implemented with the doctrine annotations component?
Annotation is directly implemented in (or commonly used annotation defined in) this bundle:
Https://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/index.html
But this bundle has Doctrine\common dependencies:
Https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/composer.json
So sorta, the bottom is the doctrine system, there is no reason to use the doctrine to realize it again.
Another dependency is the framework Core, which itself is not supported by annotation.
First, the implementation of the Symfony annotation uses the component doctrine\common\annotations
1. Each of the annotation has a corresponding class
1) Take route[1] For example, below, which is a subclass of [2]:
[1]Sensio\Bundle\FrameworkExtraBundle\Configration\Route[2]Symfony\Component\Routing\Annotation\Route
2) Other sub-categories [5], such as method[3],security[4]
[3]Sensio\Bundle\FrameworkExtraBundle\Configuration\Method[4]Sensio\Bundle\FrameworkExtraBundle\Configuration\Security[5]Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation
2. By running the command as in, found that the Symfony framework and annotation related services only one-"Annotation_reader"
Symfony through this service, in fact, is "Doctrine\common\annotations\cachedreader", each annotation into a annotation class (object), and then get the corresponding parameters, for processing
For example, a class that corresponds to a route is "Symfony\component\routing\loader\annotationclassloader", and the load method for this class is by using "Annotation_reader" and PHP's Reflection API (Reflectionclass) to handle the controller object and the annotation class (Route), eventually returning the RouteCollection object
3. As mentioned above, the implementation method does use the PHP reflection API (refer to "Symfony\component\routing\loader\annotationclassloader")
4. By using the "Annotation_reader" service and the PHP Reflection API (Reflectionclass), developers can even write their own annotation classes and ClassLoader, Here is a foreign article devoted to this (although it was a few years ago, but the content is not outdated)
Symfony2 & Doctrine common:creating powerful annotations