-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
efeefc6 to
687deb3
Compare
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
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php
Outdated
Show resolved
Hide resolved
|
@GromNaN the PR includes autoconfiguration rules to add the tag. |
src/Symfony/Bundle/FrameworkBundle/Routing/AttributeRouteControllerLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Outdated
Show resolved
Hide resolved
#[Route] attributes found on services tagged with routing.controller687deb3 to
219bea5
Compare
|
PR updated, thanks for the reviews. controllers:
resource: attributes
type: tagged_services |
219bea5 to
0ce304f
Compare
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 to
d0bbf04
Compare
|
Thank you @nicolas-grekas. |
| * | ||
| * @author Nicolas Grekas <[email protected]> | ||
| */ | ||
| class AttributeServicesLoader extends 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 it final 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 | MIT Commits ------- 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 | MIT re-reading #61492 I wonder if we don't have to add the new tag to this list Commits ------- 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 | MIT Fine-tuning #61492 Before: ```yaml controllers: resource: attributes type: tagged_services ``` After: ```yaml controllers: 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.php return 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
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 at symfony/recipes#1448