From d669eb32e6af05f5f34ce3953abf385336eeaed3 Mon Sep 17 00:00:00 2001 From: Matthieu Lempereur Date: Sun, 30 Jun 2024 16:16:58 +0200 Subject: [PATCH] deprecate TaggedIterator and TaggedLocator attributes --- reference/attributes.rst | 8 +++++++ .../service_subscribers_locators.rst | 24 ++++++++++++++----- service_container/tags.rst | 24 +++++++++---------- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/reference/attributes.rst b/reference/attributes.rst index 4428dc4c587..ba34afd524d 100644 --- a/reference/attributes.rst +++ b/reference/attributes.rst @@ -44,6 +44,14 @@ Dependency Injection * :ref:`Target ` * :ref:`When ` +.. deprecated:: 7.1 + + The + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedIterator` + and + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedLocator` + were deprecated in Symfony 7.1. + EventDispatcher ~~~~~~~~~~~~~~~ diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst index 25ebe97e7e7..9c36f8c82cd 100644 --- a/service_container/service_subscribers_locators.rst +++ b/service_container/service_subscribers_locators.rst @@ -307,6 +307,18 @@ This is done by having ``getSubscribedServices()`` return an array of ]; } +.. deprecated:: 7.1 + + The + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedIterator` + and + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedLocator` + were deprecated in Symfony 7.1. + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\AutowireIterator` + and + :class:`Symfony\\Component\\DependencyInjection\\Attribute\\AutowireLocator` + should be used instead. + .. note:: The above example requires using ``3.2`` version or newer of ``symfony/service-contracts``. @@ -432,13 +444,13 @@ or directly via PHP attributes: namespace App; use Psr\Container\ContainerInterface; - use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; + use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; class CommandBus { public function __construct( // creates a service locator with all the services tagged with 'app.handler' - #[TaggedLocator('app.handler')] + #[AutowireLocator('app.handler')] private ContainerInterface $locator, ) { } @@ -674,12 +686,12 @@ to index the services: namespace App; use Psr\Container\ContainerInterface; - use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; + use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; class CommandBus { public function __construct( - #[TaggedLocator('app.handler', indexAttribute: 'key')] + #[AutowireLocator('app.handler', indexAttribute: 'key')] private ContainerInterface $locator, ) { } @@ -789,12 +801,12 @@ get the value used to index the services: namespace App; use Psr\Container\ContainerInterface; - use Symfony\Component\DependencyInjection\Attribute\TaggedLocator; + use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; class CommandBus { public function __construct( - #[TaggedLocator('app.handler', 'defaultIndexMethod: 'getLocatorKey')] + #[AutowireLocator('app.handler', 'defaultIndexMethod: 'getLocatorKey')] private ContainerInterface $locator, ) { } diff --git a/service_container/tags.rst b/service_container/tags.rst index 1900ce28fb2..68509bc5620 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -674,13 +674,13 @@ directly via PHP attributes: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( // the attribute must be applied directly to the argument to autowire - #[TaggedIterator('app.handler')] + #[AutowireIterator('app.handler')] iterable $handlers ) { } @@ -766,12 +766,12 @@ iterator, add the ``exclude`` option: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( - #[TaggedIterator('app.handler', exclude: ['App\Handler\Three'])] + #[AutowireIterator('app.handler', exclude: ['App\Handler\Three'])] iterable $handlers ) { } @@ -849,12 +849,12 @@ disabled by setting the ``exclude_self`` option to ``false``: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( - #[TaggedIterator('app.handler', exclude: ['App\Handler\Three'], excludeSelf: false)] + #[AutowireIterator('app.handler', exclude: ['App\Handler\Three'], excludeSelf: false)] iterable $handlers ) { } @@ -999,12 +999,12 @@ you can define it in the configuration of the collecting service: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( - #[TaggedIterator('app.handler', defaultPriorityMethod: 'getPriority')] + #[AutowireIterator('app.handler', defaultPriorityMethod: 'getPriority')] iterable $handlers ) { } @@ -1073,12 +1073,12 @@ to index the services: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( - #[TaggedIterator('app.handler', indexAttribute: 'key')] + #[AutowireIterator('app.handler', indexAttribute: 'key')] iterable $handlers ) { } @@ -1187,12 +1187,12 @@ get the value used to index the services: // src/HandlerCollection.php namespace App; - use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; + use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; class HandlerCollection { public function __construct( - #[TaggedIterator('app.handler', defaultIndexMethod: 'getIndex')] + #[AutowireIterator('app.handler', defaultIndexMethod: 'getIndex')] iterable $handlers ) { }