symfony如何解析和使用注释

问题描述 投票:-1回答:1

使用Symfony注释作为路由的例子是相当惊人的,但我想知道这个框架如何解析注释并提取注释?例如:

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

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

php symfony parsing annotations symfony4
1个回答
1
投票

Symfony使用Doctrine Annotations模块来解析您的类中的docblock。

看到:

https://github.com/doctrine/annotations

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

它使用Reflection类来读取注释

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.