I'm setting up FOSRestBundle and have some doubts, don't know if related to Symfony2 Routing component or can be done in any other way. Here,
1) How do I check if X-PDONE-SESSION-ID
is set on request headers before execute the method? Can this be done using annotations on routing? Any ideas on how to check that?
2) I need to use this RegEx \b(?:(?:https?):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]
as requirements
in the route @QueryParam(name="token", requirements="")
for check valid URLs, how?
(1) can be done using the method described in 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.
In (2), you show a regex for a complete URL and not just a query parameter. It isn't possible to change the whole regex used by the Routing component by default as far as I know.