Commit 981b556
committed
feature symfony#60081 [FrameworkBundle] Enable controller service with
This PR was merged into the 7.3 branch.
Discussion
----------
[FrameworkBundle] Enable controller service with `#[Route]` attribute
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | -
| License | MIT
The `#[AsController]` attribute has 2 purposes:
- Add the tag ` controller.service_argument` that configures the service and service argument injection ([RegisterControllerArgumentLocatorsPass](https://github.com/symfony/symfony/blob/79ea49c772ce4b39f414cde5648ad347c3bbcfd7/src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php#L56))
- Allow the class in the controller resolver ([symfony#52471](symfony#52471))
In this PR, I propose to add the tag `argument_resolver.service` on services when the class has the `#[Route]` attribute. Removing the need for `#[AsController]` on classes that use the `#[Route]` attribute.
I assume that if there is a route, it is a controller.
Diff (from the [docs](https://symfony.com/doc/7.2/controller/service.html)):
```diff
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
- #[AsController]
class HelloController
{
#[Route('/hello', name: 'hello', methods: ['GET'])]
public function index(): Response
{
// ...
}
}
```
Commits
-------
2e59467 Enable controller service with #[Route] attribute instead of #[AsController]#[Route] attribute (GromNaN)File tree
2 files changed
+7
-1
lines changed- src/Symfony/Bundle/FrameworkBundle
- DependencyInjection
2 files changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
| |||
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
432 | | - | |
| 433 | + | |
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
| |||
739 | 740 | | |
740 | 741 | | |
741 | 742 | | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
742 | 746 | | |
743 | 747 | | |
744 | 748 | | |
| |||
0 commit comments