Moh*_*ndi 1 php parsing annotations symfony symfony4
例如,使用 Symfony 注释进行路由是相当惊人的,但我想知道这个框架如何解析注释并提取注释?例如:
/**
* @Route("/tehran", name="tehran")
*/
Run Code Online (Sandbox Code Playgroud)
然后将其用作下一个控制器方法的路由。
小智 5
Symfony 使用 Doctrine Annotations 模块来解析类中的文档块。
看:
https://github.com/doctrine/annotations
https://www.doctrine-project.org/projects/doctrine-annotations/en/current/index.html
它使用Reflection类来读取注释
https://secure.php.net/manual/fr/book.reflection.php
Symfony 将在第一次运行时读取您的注释(并将缓存解析的路由)。然后使用 UrlMatcher 将路由与当前请求进行匹配。
https://github.com/symfony/symfony/blob/3.2/src/Symfony/Component/Routing/Matcher/UrlMatcher.php