Where does the annotations function of Symfony be implemented?

Source: Internet
Author: User
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 tokensand 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

  • Related Article

    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.