Skip to content

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 4, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

Fine-tuning #61492

Before:

controllers:
    resource: attributes
    type: tagged_services

After:

controllers:
    resource: routing.controllers

And when using MicroKernelTrait (the default recipe), there's nothing to configure to have routes loaded from #[Route] attributes:

#config/routes.yaml
# the file can be just empty from any config, and only have a comment saying what it's for
// config/routes.php
return Routes::config([
]);

The way to opt-out from this routing.controllers import would be to override the Kernel::configureRoutes() method.

if ($fileName = (new \ReflectionObject($this))->getFileName()) {
$routes->import($fileName, 'attribute');
}
$routes->import('routing.controllers');
Copy link
Member Author

@nicolas-grekas nicolas-grekas Nov 4, 2025

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

@nicolas-grekas nicolas-grekas added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Nov 4, 2025
if ($fileName = (new \ReflectionObject($this))->getFileName()) {
$routes->import($fileName, 'attribute');
}
$routes->import('routing.controllers');
Copy link
Member

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)

Copy link
Member Author

@nicolas-grekas nicolas-grekas Nov 4, 2025

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?

@yceruto
Copy link
Member

yceruto commented Nov 4, 2025

Nice!

config/routes.yaml
the file can be just empty from any config, and only have a comment saying what it's for

I'd even vote for removing it from the recipe

@javiereguiluz
Copy link
Member

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.

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Nice!

@fabpot
Copy link
Member

fabpot commented Nov 5, 2025

Thank you @nicolas-grekas.

@fabpot fabpot merged commit f656af9 into symfony:7.4 Nov 5, 2025
11 of 12 checks passed
@nicolas-grekas nicolas-grekas deleted the route-tagged branch November 5, 2025 12:38
This was referenced Nov 13, 2025
nicolas-grekas added a commit that referenced this pull request Nov 14, 2025
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Routing ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants