Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Routing] Simplify importing routes defined on controller services#62302
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
86b8d7f to8682655Compare| if ($fileName = (new \ReflectionObject($this))->getFileName()) { | ||
| $routes->import($fileName,'attribute'); | ||
| } | ||
| $routes->import('routing.controllers'); |
nicolas-grekasNov 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
the kernel being autoconfigured, it'll get therouting.controller tag once it uses a#[Route] attribute
| if ($fileName = (new \ReflectionObject($this))->getFileName()) { | ||
| $routes->import($fileName,'attribute'); | ||
| } | ||
| $routes->import('routing.controllers'); |
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 makes any route defined on a class with therouting.controller tag win over routes defined inroutes.yaml, while the existing solution respects the order of route definitions and so the current import might not be last. This could be a BC break if a project relies on such override.
And it also makes it impossible to override a route definition coming from a third-party bundle if that bundle defines a service tagged withrouting.controller. This second issue could be solved by importing thosebefore theroutes.yaml (orroutes.php) file though (but still after theroutes/*.yaml files where recipes are importing third-party routes)
nicolas-grekasNov 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
I moved the import betweenroutes/* androutes.yaml
Doesn't that solve everything?
8682655 to13e25caCompareyceruto commentedNov 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Nice!
I'd even vote for removing it from the recipe |
javiereguiluz commentedNov 5, 2025
I'd keep it for now because it's not that rare to have to add some manual config in this file. |
fabpot left a comment
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.
Nice!
fabpot commentedNov 5, 2025
Thank you@nicolas-grekas. |
f656af9 intosymfony:7.4Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Fine-tuning#61492
Before:
After:
And when using
MicroKernelTrait(the default recipe), there's nothing to configure to have routes loaded from#[Route]attributes:The way to opt-out from this
routing.controllersimport would be to override theKernel::configureRoutes()method.