symfony 如何解析和使用注解 [英] How symfony parse and use annotation

查看:34
本文介绍了symfony 如何解析和使用注解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如使用 Symfony 注释进行路由非常了不起,但我想知道这个框架如何解析注释并提取注释?例如:

Using Symfony annotation for example for routing is quite amazing, but I wonder how this framework parse the comments and extract the annotation? For example:

 /**
 * @Route("/tehran", name="tehran")
 */

然后将其用作下一个控制器方法的路由.

and then use it as a route to next controller method.

推荐答案

Symfony 使用 Doctrine Annotations 模块从你的类中解析文档块.

Symfony uses the Doctrine Annotations module to parse the docblock from your class.

见:

https://github.com/doctrine/annotations

https://www.doctrine-project.org/projects/doctrine-annotations/en/current/index.html

它使用反射类来读取注释

It uses Reflection class to read the annotations

https://secure.php.net/manual/fr/book.reflection.php

Symfony 将在第一次运行时读取您的注释(并将缓存解析的路由).然后使用 UrlMatcher 将路由与当前请求匹配.

Symfony will read from your annotations on the first run (and will cache the parsed routes). Then the routes are matched with the current request using an UrlMatcher.

https://github.com/symfony/symfony/blob/3.2/src/Symfony/Component/Routing/Matcher/UrlMatcher.php

这篇关于symfony 如何解析和使用注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆