Skip to content

Commit 88d9bf7

Browse files
committed
minor #16748 [HttpKernel] Document AsController attribute (SzymonKaminski)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Document AsController attribute This PR aims to resolve #15144. Commits ------- d2f6b0d [HttpKernel] Document AsController attribute
2 parents dd07a7d + d2f6b0d commit 88d9bf7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

controller/service.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ in method parameters:
2828
resource: '../src/Controller/'
2929
tags: ['controller.service_arguments']
3030
31+
.. versionadded:: 5.3
32+
33+
The ``#[AsController]`` attribute was introduced in Symfony 5.3.
34+
35+
If you are using PHP 8.0 or later, you can use the ``#[AsController]`` PHP
36+
attribute to automatically apply the ``controller.service_arguments`` tag to
37+
your controller services::
38+
39+
// src/Controller/HelloController.php
40+
namespace App\Controller;
41+
42+
use Symfony\Component\HttpKernel\Attribute\AsController;
43+
use Symfony\Component\Routing\Annotation\Route;
44+
45+
#[AsController]
46+
class HelloController
47+
{
48+
#[Route('/hello', name: 'hello', methods: ['GET'])]
49+
public function index()
50+
{
51+
// ...
52+
}
53+
}
54+
3155
Registering your controller as a service is the first step, but you also need to
3256
update your routing config to reference the service properly, so that Symfony
3357
knows to use it.

0 commit comments

Comments
 (0)