-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Allow using kernel parameters in routes #4745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* | ||
* @param $collection | ||
* @param RouteCollection|Route $collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong as the RouteCollection is typehinted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks.
👍 for consistency. |
Kernel parameters can now be used at any position in patterns, defaults and requirements.
+1 a much better solution to the problem than mine, closing #3316 |
How about escaping kernel params with |
@Tobion this would not be consistent with the way DI parameters are escaped elsewhere |
Looks good for me, thanx. |
Commits ------- 0555913 [FrameworkBundle] Allow using kernel parameters in routes Discussion ---------- [FrameworkBundle] Allow using kernel parameters in routes Kernel parameters can now be used at any position in patterns, defaults and requirements. Relates to: #3316, #3276 **Differences from 3316:** - The substitution is now done in the `Router`, - 3316 uses `$container->getParameterBag()` which is not part of the `ContainerInterface`. The way it been solved in this PR is that some code have been duplicated inside the `Router`, see `resolveString()`. **BC break:** Before this PR, nonexistent parameters would have be silently ignored (ie `%idontexist%` would not have been replaced). After this PR, they will throw an exception. However you can escape the value (ie `%%idontexist%%` will be accepted and replaced by `%idontexist%`). _This behavior is not mandatory and can be reverted if needed. However this keeps the router more consistent with the DI_. Any feedback ? @helmer @Koc --------------------------------------------------------------------------- by Seldaek at 2012-07-04T12:40:08Z :+1: for consistency. --------------------------------------------------------------------------- by helmer at 2012-07-04T13:07:11Z +1 a much better solution to the problem than mine, closing #3316 --------------------------------------------------------------------------- by Tobion at 2012-07-04T13:21:59Z How about escaping kernel params with `\%idontexist%` as I suggested it for route params in 4563? --------------------------------------------------------------------------- by stof at 2012-07-04T13:28:55Z @Tobion this would not be consistent with the way DI parameters are escaped elsewhere --------------------------------------------------------------------------- by Koc at 2012-07-04T14:24:25Z Looks good for me, thanx.
This still does not work with prefixes, it ends up writing the parameter to the UrlMatcher dump. The routes end up working fine because the prefix is simply added to the pattern. However, in the PhpMatcherDumper, the prefix is obtained by using getPrefix() from the RouteCollection which has not been resolved, so any time there is more than one route you end up getting something like
The only thing I can see right now is added a setPrefix to RouteCollection, but that is very misleading because you can't exactly undo the route prefixes as it updates the patterns directly.. |
Kernel parameters can now be used at any position in patterns, defaults and requirements.
Relates to: #3316, #3276
Differences from 3316:
Router
,$container->getParameterBag()
which is not part of theContainerInterface
. The way it been solved in this PR is that some code have been duplicated inside theRouter
, seeresolveString()
.BC break:
Before this PR, nonexistent parameters would have be silently ignored (ie
%idontexist%
would not have been replaced). After this PR, they will throw an exception. However you can escape the value (ie%%idontexist%%
will be accepted and replaced by%idontexist%
).This behavior is not mandatory and can be reverted if needed. However this keeps the router more consistent with the DI.
Any feedback ? @helmer @Koc