-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
86b8d7f to
8682655
Compare
| 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.
the kernel being autoconfigured, it'll get the routing.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 the routing.controller tag win over routes defined in routes.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 with routing.controller. This second issue could be solved by importing those before the routes.yaml (or routes.php) file though (but still after the routes/*.yaml files where recipes are importing third-party routes)
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 between routes/* and routes.yaml
Doesn't that solve everything?
8682655 to
13e25ca
Compare
|
Nice!
I'd even vote for removing it from the recipe |
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!
|
Thank you @nicolas-grekas. |
…n controllers (nicolas-grekas) This PR was merged into the 7.4 branch. Discussion ---------- [FrameworkBundle] Revert auto-import of #[Route] defined on controllers | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #62401 | License | MIT Something we did in #62302 but that leads to #62401 Commits ------- fd44c2e [FrameworkBundle] Revert auto-import of #[Route] defined on controllers
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.