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

Closed
wants to merge 3 commits into from

Conversation

MatTheCat
Copy link
Contributor

@MatTheCat MatTheCat commented May 4, 2025

Q A
Branch? 7.4
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 added this to the 7.3 milestone May 4, 2025
@carsonbot carsonbot changed the title Deprecate RouteCollection overriding its routes' properties [Routing] Deprecate RouteCollection overriding its routes' properties May 5, 2025
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
@MatTheCat MatTheCat force-pushed the ticket_53171 branch 2 times, most recently from d22f78a to 1b7c04b Compare May 29, 2025 08:11
alamirault and others added 3 commits May 29, 2025 14:02
…ult)

This PR was merged into the 7.4 branch.

Discussion
----------

Replace `get_class()` calls by `::class`

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

Replace `get_class()` by `::class`
It was already done in past in symfony#47401

Commits
-------

e0a602b Replace get_class() calls by ::class
@MatTheCat
Copy link
Contributor Author

Realized my approach was wrong, hence the number of deprecations in tests. I’ll open a new PR if I manage to find a solution.

@MatTheCat MatTheCat closed this Jun 2, 2025
@MatTheCat MatTheCat deleted the ticket_53171 branch June 5, 2025 08:41
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.

6 participants