I need to build a route which has a dynamic condition.
For the moment, I simply use requirements
in order the match against a static list a words:
/**
* @Route(
* "/{category}/{id}",
* requirements={
* "category"="^(foo|bar)$"
* }
* )
*
* ...
*/
But now I need these words to be retrieved dynamically from a service method.
While searching a solution, I gave a hope to the condition
expression language; but the only
variables which are accessible here are the context and the request. However, to achieve my goal I
need a full access to container services.
In other words, I would like the following pseudo-php to be executed in order to test the route:
if (in_array($category, MyService::getAllCategories())) {
/* Inform Symfony that the route matches (then use this controller) */
} else {
/* Inform Symfony that the route does not match and that the routing process
* has to go on. */
}
Please note that the main reason of my problem is that the {category}
parameter is placed early in
the url, and then can offuscate other routes. Then I can't just test my condition inside the
controller and return a 404 if the condition is not required. I surely could place this route at
the end in the routing process order, but I don't think it is a good solution.