Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:7.4fromnicolas-grekas:routing-service-loader
Aug 22, 2025

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedAug 21, 2025
edited
Loading

QA
Branch?7.4
Bug fix?no
New feature?yes
Deprecations?no
Issues#60946
LicenseMIT

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:

controllers:resource:path:../src/Controller/namespace:App\Controllertype:attribute

config/routes.yaml after:

controllers:resource:attributestype:tagged_services

Recipe update atsymfony/recipes#1448

yceruto, jdreesen, and dmaicher reacted with hooray emoji
@nicolas-grekasnicolas-grekas marked this pull request as ready for reviewAugust 21, 2025 16:05
@carsonbotcarsonbot added this to the7.4 milestoneAug 21, 2025
@symfonysymfony deleted a comment fromcarsonbotAug 21, 2025
Copy link
Member

@GromNaNGromNaN left a comment
edited
Loading

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.

@MatTheCat
Copy link
Contributor

Seems this PR would fix#60946 (ping@Nayte91)?

nicolas-grekas reacted with thumbs up emojiNayte91 reacted with heart emoji

@stof
Copy link
Member

@GromNaN the PR includes autoconfiguration rules to add the tag.

GromNaN reacted with thumbs up emoji

@nicolas-grekasnicolas-grekas changed the title[FrameworkBundle] Auto-register#[Route] attributes found on services tagged withrouting.controller[Routing][FrameworkBundle] Auto-register routes from attributes found on controller servicesAug 22, 2025
@carsonbotcarsonbot changed the title[Routing][FrameworkBundle] Auto-register routes from attributes found on controller services[FrameworkBundle][Routing] Auto-register routes from attributes found on controller servicesAug 22, 2025
@nicolas-grekas
Copy link
MemberAuthor

PR updated, thanks for the reviews.

controllers:resource:attributestype:tagged_services

Copy link
Member

@ycerutoyceruto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Super !

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

@fabpotfabpot merged commit12fb3d1 intosymfony:7.4Aug 22, 2025
10 of 12 checks passed
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class AttributeServicesLoaderextends Loader
Copy link
Member

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)

GromNaN reacted with thumbs up emoji
@nicolas-grekasnicolas-grekas deleted the routing-service-loader branchAugust 22, 2025 16:06
nicolas-grekas added a commit that referenced this pull requestAug 25, 2025
…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
nicolas-grekas added a commit that referenced this pull requestAug 26, 2025
… 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
This was referencedOct 27, 2025
fabpot added a commit that referenced this pull requestNov 5, 2025
…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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@GromNaNGromNaNGromNaN approved these changes

@ycerutoycerutoyceruto approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

7 participants

@nicolas-grekas@MatTheCat@stof@fabpot@GromNaN@yceruto@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp