Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle][Routing] Auto-register routes from attributes found on controller services#61492
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
efeefc6 to687deb3Compare
GromNaN left a comment• 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.
routing.controller is a new tag. How will it be added to the class definition?
Edit: the tag is added to classes with#[Route] or#[AsController] attribute.
src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
MatTheCat commentedAug 21, 2025
stof commentedAug 21, 2025
@GromNaN the PR includes autoconfiguration rules to add the tag. |
src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
#[Route] attributes found on services tagged withrouting.controller687deb3 to219bea5Comparenicolas-grekas commentedAug 22, 2025
PR updated, thanks for the reviews. controllers:resource:attributestype:tagged_services |
219bea5 to0ce304fCompare
yceruto 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.
Super !
… on controller services
0ce304f tod0bbf04Comparefabpot commentedAug 22, 2025
Thank you@nicolas-grekas. |
12fb3d1 intosymfony:7.4Uh oh!
There was an error while loading.Please reload this page.
| * | ||
| * @author Nicolas Grekas <p@tchwork.com> | ||
| */ | ||
| class AttributeServicesLoaderextends Loader |
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 suggest making itfinal or@final. I don't see any need to support inheritance on this class (there is no useful place to hook into anyway)
…esLoader final (xabbuh)This PR was merged into the 7.4 branch.Discussion----------[Routing] make RoutingControllerPass and AttributeServicesLoader final| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | see#61492 (comment)| License | MITCommits-------9986139 make RoutingControllerPass and AttributeServicesLoader final
… of known DI tags (xabbuh)This PR was merged into the 7.4 branch.Discussion----------[DependencyInjection] add routing.controller to the list of known DI tags| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues || License | MITre-reading#61492 I wonder if we don't have to add the new tag to this listCommits-------593ee8f add routing.controller to the list of known DI tags
…ler services (nicolas-grekas)This PR was merged into the 7.4 branch.Discussion----------[Routing] Simplify importing routes defined on controller services| Q | A| ------------- | ---| Branch? | 7.4| Bug fix? | no| New feature? | no| Deprecations? | no| Issues | -| License | MITFine-tuning#61492Before:```yamlcontrollers: resource: attributes type: tagged_services```After:```yamlcontrollers: resource: routing.controllers```And when using `MicroKernelTrait` (the default recipe), there's nothing to configure to have routes loaded from `#[Route]` attributes:```yaml#config/routes.yaml# the file can be just empty from any config, and only have a comment saying what it's for``````php// config/routes.phpreturn Routes::config([]);```The way to opt-out from this `routing.controllers` import would be to override the `Kernel::configureRoutes()` method.Commits-------13e25ca [Routing] Simplify importing routes defined on controller services
Uh oh!
There was an error while loading.Please reload this page.
Currently, controllers have to be put in predetermined directories for their route attributes to be parsed.
This PR enables auto-registration of controllers based on their service definition, independently of where they're located in the app - which means they could be put anywhere now.
config/routes.yaml before:
config/routes.yaml after:
Recipe update atsymfony/recipes#1448