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

查看:104
本文介绍了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注释"模块来解析类中的文档块.

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

请参阅:

https://github.com/doctrine/annotations

https://doctrine-common.readthedocs.io/en /latest/reference/annotations.html

它使用Reflection类读取注释

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.

http://api.symfony.com/3.2 /Symfony/Component/Routing/Matcher/UrlMatcher.html

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

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