From 412a45089424636f2aa2826ffbd1e28b2a525d0d Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 27 Dec 2023 13:41:29 +0100 Subject: [PATCH] Add a note about configuring controllers without autowire/autoconfigure --- controller/service.rst | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/controller/service.rst b/controller/service.rst index 50ee34a1aac..fff46377378 100644 --- a/controller/service.rst +++ b/controller/service.rst @@ -25,6 +25,40 @@ in method parameters: resource: '../src/Controller/' tags: ['controller.service_arguments'] +.. note:: + + If you don't use either :doc:`autowiring ` + or :ref:`autoconfiguration ` and you extend the + ``AbstractController``, you'll need to apply other tags and make some method + calls to register your controllers as services: + + .. code-block:: yaml + + # config/services.yaml + + # this extended configuration is only required when not using autowiring/autoconfiguration, + # which is uncommon and not recommended + + abstract_controller.locator: + class: Symfony\Component\DependencyInjection\ServiceLocator + arguments: + - + router: '@router' + request_stack: '@request_stack' + http_kernel: '@http_kernel' + session: '@session' + parameter_bag: '@parameter_bag' + # you can add more services here as you need them (e.g. the `serializer` + # service) and have a look at the AbstractController class to see + # which services are defined in the locator + + App\Controller\: + resource: '../src/Controller/' + tags: ['controller.service_arguments'] + calls: + - [setContainer, ['@abstract_controller.locator']] + + If you prefer, you can use the ``#[AsController]`` PHP attribute to automatically apply the ``controller.service_arguments`` tag to your controller services::