-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Routing - Allow optional parameters throughout the route #31616
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
Routing - Allow optional parameters throughout the route #31616
Conversation
Coud you please check the tests as it seems broken due to this PR and we don't merge BC break it should not break BC. |
Status: Needs Work |
…ers, fix route matcher dump test optional locale regex and indicies
@Simperfit , sorry I thought I'd caught the broken tests. Those should now be fixed. This breaks BC because it's a change to how the route compiler compiles regex based on the passed route info, thus when routes are matched it matches routes that it previously wouldn't have, also for major versions is BC break not a possibility if following semver? A way this could be added without BC break would be to refactor the RouteCompiler to be more modular and then write a new RouteCompiler that can be swapped in when wanted to allow optional parameters in other places but the end of a route? Happy for this PR to be closed out if there is a better way to handle this / suggestions on providing optional route prefixes that would match both Cheers! |
The bc break it too high risk, isn't it? Btw, why would one define a default for a currently non-optional route param? If there is no reasons for such defaults, maybe we should deprecate them, to unlock this PR for 5.1? |
This has been rejected in the past (a very long time ago). In such situations, one should have several routes. |
@nicolas-grekas I agree the BC break is too high risk, unfortunately altering the compiler in anyway to accept optional parameters where they previously weren't allowed will be a BC. There is not any reason to set a default against a non optional route parameter, however in doing so it makes the parameter optional so I don't think you could really deprecate it (as it just sets the default into the defaults array and then ignores it). Previous behaviour was that setting a default on a parameter that came before another non optional segment would just disregard it as optional and therefore compile the regex as if it was required and therefore ignore the default. @fabpot No problem, I was trying to avoid the duplication with lots of routes but if this is the only suggested way I can stick with that, cheers |
Feature request defined #31166
The purpose of this PR is to allow optional parameters in earlier segments in routes. This would allow for routes such as:
/{locale}/some/route
, where locale is optional to match the following:The use case for the above example is to allow redirecting to a locale specific endpoint from the non locale specific endpoint.
This also allows for routes such as:
/{optional}/foo/{nonoptional}
, this would match /foo/anything as well as /something/foo/anything, but not /something/foo