[Routing] Add addCondition() to combine a condition with the existing ones - #66004
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Today a route import can only replace the conditions of the routes it imports:
This wipes any
#[Route(condition: ...)]set on the imported controllers. That is documented, and it is consistent with how an import appliesdefaultsandrequirements, but it means a group-wide guard and a per-route condition cannot coexist: whichever side you write, the other is silently discarded. That is what #53171 is about.The underlying reason is a missing primitive.
RouteandRouteCollectionboth havesetCondition()and neither hasaddCondition(), so "also require this" is not expressible anywhere in the component. This PR adds it:Route::addCondition()andRouteCollection::addCondition(), combining as(existing) and (new)addCondition()on the route, collection and import configuratorsadd_conditionkey on imports and route definitionsconditionkeeps its current meaning, so nothing changes for anyone who does not opt in.The alternative I did not take
The other way to resolve #53171 is to flip the default: deprecate an import-level
conditionthat collides with a route-level one, and make the two combine in 9.0. That needs an escape hatch, because the colliding route is usually in a third-party bundle you cannot edit, so the deprecation would otherwise be impossible to silence. And the escape hatch has to be tri-state (an explicit "replace", an explicit "combine", and the unset case that still deprecates), which is a larger config surface than this whole PR, for a change that only moves a default.Status
This is prospective on my side. If we do not want the added API, then the honest outcome for #53171 is to close it as won't fix: the current behaviour is documented, it is consistent across the properties an import can set, and reversing it is a BC break nobody has found a cheap migration for. #53511 and #60343 both died trying.
Reported by @mbuliard. @MatTheCat built the deprecation route in #60343 and withdrew it, and @stof set out the constraints that make the flip expensive.