0

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?

I have read here and here but wasn't helpful at all.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
ReynierPM
  • 17,594
  • 53
  • 193
  • 363

1 Answers1

1

(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.

Wouter J
  • 41,455
  • 15
  • 107
  • 112
  • For (1) how I can just check if `X-PDONE-SESSION-ID` is set on request headers not matter which value comes? (in theory should be a PHP session ID). Around (2) I just need to check if parameter is a valid URL or doesn't, how? I just wrote a Regex cause I don't know another way to check this, any advice on this one? – ReynierPM May 14 '15 at 21:13