From 7c1a4b44ca4b5a1f6689db600746088b9265143b Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Sat, 2 Dec 2023 11:43:57 +0100 Subject: [PATCH] Add attribute configuration block for reusable locator --- .../service_subscribers_locators.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst index 397e7141bf4..ec57eb8f12b 100644 --- a/service_container/service_subscribers_locators.rst +++ b/service_container/service_subscribers_locators.rst @@ -570,6 +570,23 @@ Now you can inject the service locator in any other services: .. configuration-block:: + .. code-block:: php-attributes + + // src/CommandBus.php + namespace App; + + use Psr\Container\ContainerInterface; + use Symfony\Component\DependencyInjection\Attribute\Autowire; + + class CommandBus + { + public function __construct( + #[Autowire(service: 'app.command_handler_locator')] + private ContainerInterface $locator, + ) { + } + } + .. code-block:: yaml # config/services.yaml