Skip to content

[DependencyInjection] Deprecate TaggedIterator and TaggedLocator attributes #20006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions reference/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ Dependency Injection
* :ref:`Target <autowiring-multiple-implementations-same-type>`
* :ref:`When <service-container_limiting-to-env>`

.. deprecated:: 7.1

The
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedIterator`
and
:class:`Symfony\\Component\\DependencyInjection\\Attribute\\TaggedLocator`
were deprecated in Symfony 7.1.

EventDispatcher
~~~~~~~~~~~~~~~

Expand Down
24 changes: 18 additions & 6 deletions service_container/service_subscribers_locators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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,
) {
}
Expand Down Expand Up @@ -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,
) {
}
Expand Down Expand Up @@ -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,
) {
}
Expand Down
24 changes: 12 additions & 12 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}
Expand Down Expand Up @@ -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
) {
}
Expand Down Expand Up @@ -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
) {
}
Expand Down Expand Up @@ -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
) {
}
Expand Down Expand Up @@ -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
) {
}
Expand Down Expand Up @@ -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
) {
}
Expand Down
Loading