From d2f6b0dc92c0a3e7e549ad9f3421fbebcad05e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Kami=C5=84ski?= Date: Sun, 24 Apr 2022 17:31:20 +0200 Subject: [PATCH] [HttpKernel] Document AsController attribute --- controller/service.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/controller/service.rst b/controller/service.rst index 017b99c61c1..f1fb3e6258b 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -28,6 +28,30 @@ in method parameters: resource: '../src/Controller/' tags: ['controller.service_arguments'] +.. versionadded:: 5.3 + + The ``#[AsController]`` attribute was introduced in Symfony 5.3. + +If you are using PHP 8.0 or later, you can use the ``#[AsController]`` PHP +attribute to automatically apply the ``controller.service_arguments`` tag to +your controller services:: + + // src/Controller/HelloController.php + namespace App\Controller; + + use Symfony\Component\HttpKernel\Attribute\AsController; + use Symfony\Component\Routing\Annotation\Route; + + #[AsController] + class HelloController + { + #[Route('/hello', name: 'hello', methods: ['GET'])] + public function index() + { + // ... + } + } + Registering your controller as a service is the first step, but you also need to update your routing config to reference the service properly, so that Symfony knows to use it.