Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Deprecate RouteCollection overriding its routes' properties #60343

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

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented May 4, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? yes
Issues N/A
License MIT

In Symfony, route collections’ methods, schemes, host, defaults, requirements and condition end up overriding their routes’ which is counter-intuitive: it means e.g. every route in a collection whose method is POST will have the same, even if they were configured through the Route attribute with a GET method.

Even if doing this has currently no effect and is probably a mistake, changing this behavior would be a BC break so this PR starts by deprecating it.

Then, #53171 can be fixed in 8.0 by changing the conditions and moving the call to routes’ setter into it, e.g.

foreach ($this->routes as $route) {
-    if ('' !== $route->getHost() && $route->getHost() !== $pattern) {
-        trigger_deprecation('symfony/routing', '7.3', 'Overriding a route\'s host with its group\'s is deprecated, you should remove it from the route.');
+    if ('' === $route->getHost()) {
+        $route->setHost($pattern);
    }

-    $route->setHost($pattern);
}

I’ll be waiting for an approval before updating loaders tests because it looks like it’ll be tedious.

@carsonbot carsonbot changed the title Deprecate RouteCollection overriding its routes' properties [Routing] Deprecate RouteCollection overriding its routes' properties May 5, 2025
@MatTheCat
Copy link
Contributor Author

The idea is rather not to let these methods change a property which is already defined at the route level.

@MatTheCat
Copy link
Contributor Author

In my mind the collections’ properties already are the default for their routes’ so I’m not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants