Where does the annotations function of symfony be implemented?

Source: Internet
Author: User
Where is the annotations function of symfony (used in routing, data verification, ORM, and other places) implemented? I asked where the code is, not how it is implemented. I guess the implementation method is to analyze the reflection APIs of tokens and php. Is it implemented using the doctrine annotations component? Where is the annotations function of symfony (used in routing, data verification, ORM, and other places) implemented?
I asked where the code is, not how it is implemented. I guess the implementation method is analysis. tokensAnd php reflection APIs. Is it implemented using the doctrine annotations component?

Reply content:

Where is the annotations function of symfony (used in routing, data verification, ORM, and other places) implemented?
I asked where the code is, not how it is implemented. I guess the implementation method is analysis.tokensAnd php reflection APIs. Is it implemented using the doctrine annotations component?

Annotation is directly implemented in (or commonly used annotation is defined in) this bundle:
Https://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/index.html
However, this bundle has Doctrine \ Common dependency:
Https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/composer.json
Therefore, the bottom layer is the Doctrine system, and there is no reason to use Doctrine to implement it again.
Another dependency is Framework Core, which is not supported by Annotation.

1. Symfony's annotation implementation uses this component Doctrine \ Common \ Annotations1. each annotation has a corresponding class.

1) Taking Route [1] as an example, it is a subclass of [2:

[1]Sensio\Bundle\FrameworkExtraBundle\Configration\Route[2]Symfony\Component\Routing\Annotation\Route

2) Others, such as Method [3], Security [4], all subclass of [5]

[3]Sensio\Bundle\FrameworkExtraBundle\Configuration\Method[4]Sensio\Bundle\FrameworkExtraBundle\Configuration\Security[5]Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationAnnotation
2. Run the commands shown in figure. We found that the Symfony framework has only one annotation-"annotation_reader" service"

Through this service, Symfony is actually "Doctrine \ Common \ Annotations \ CachedReader", which converts each annotation to an annotation class (object) and then obtains corresponding parameters for processing.

For example, a class corresponding to Route is "Symfony \ Component \ Routing \ Loader \ AnnotationClassLoader". The load method of this class uses the reflection API (ReflectionClass) of "annotation_reader" and PHP) the Controller object and annotation class (Route) are processed, and the RouteCollection object is returned.

3. as mentioned above, PHP reflection APIs are indeed used for implementation (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 class and ClassLoader, here is a foreign article dedicated to this (although it was a few years ago, but the content is not outdated)

Symfony2 & Doctrine Common: creating powerful annotations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.