关于Symfony2 Routing组件使用的疑惑

Doubts around Symfony2 Routing component usage

我正在设置 FOSRestBundle 并且有一些疑问,不知道是否与 Symfony2 路由组件相关或可以通过任何其他方式完成。这里,

1) 在执行该方法之前,如何检查是否根据请求 headers 设置了 X-PDONE-SESSION-ID?这可以在路由上使用注释来完成吗?关于如何检查的任何想法?

2) 我需要在路由 @QueryParam(name="token", requirements="") 中使用此 RegEx \b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|] 作为 requirements 来检查有效的 URL,如何?

我已阅读 here and here 但完全没有帮助。

(1) 可以使用 the book article you referenced as not being helpful:

中描述的方法完成

As you've seen, a route can be made to match only certain routing wildcards (via regular expressions), HTTP methods, or host names. But the routing system can be extended to have an almost infinite flexibility using conditions:

contact: path: /contact defaults: { _controller: AcmeDemoBundle:Main:contact } condition: "context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'"

The condition is an expression, and you can learn more about its syntax here: The Expression Syntax. With this, the route won't match unless the HTTP method is either GET or HEAD and if the User-Agent header matches firefox.


在 (2) 中,您显示了完整 URL 的正则表达式,而不仅仅是查询参数。据我所知,默认情况下无法更改路由组件使用的整个正则表达式。