Skip to content

[DependencyInjection] Remove #[TaggedIterator] and #[TaggedLocator] attributes #60845

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 1 commit into from
Jun 20, 2025
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
25 changes: 25 additions & 0 deletions UPGRADE-8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ Console
$application->addCommand(new CreateUserCommand());
```

DependencyInjection
-------------------

* Replace `#[TaggedIterator]` and `#[TaggedLocator]` attributes with `#[AutowireLocator]` and `#[AutowireIterator]`

*Before*
```php
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;

class MyService
{
public function __construct(#[TaggedIterator('app.my_tag')] private iterable $services) {}
}
```

*After*
```php
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;

class MyService
{
public function __construct(#[AutowireIterator('app.my_tag')] private iterable $services) {}
}
```

DoctrineBridge
--------------

Expand Down

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

8.0
---

* Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes, replaced by `#[AutowireLocator]` and `#[AutowireIterator]`

7.4
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
use Symfony\Component\DependencyInjection\Attribute\Target;
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass;
Expand Down Expand Up @@ -458,49 +454,6 @@ public static function getSubscribedServices(): array
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
}

/**
* @group legacy
*/
public function testSubscribedServiceWithLegacyAttributes()
{
$container = new ContainerBuilder();

$subscriber = new class implements ServiceSubscriberInterface {
public static function getSubscribedServices(): array
{
return [
new SubscribedService('tagged.iterator', 'iterable', attributes: new TaggedIterator('tag')),
new SubscribedService('tagged.locator', PsrContainerInterface::class, attributes: new TaggedLocator('tag')),
];
}
};

$container->setParameter('parameter.1', 'foobar');
$container->register('foo', $subscriber::class)
->addMethodCall('setContainer', [new Reference(PsrContainerInterface::class)])
->addTag('container.service_subscriber');

(new RegisterServiceSubscribersPass())->process($container);
(new ResolveServiceSubscribersPass())->process($container);

$foo = $container->getDefinition('foo');
$locator = $container->getDefinition((string) $foo->getMethodCalls()[0][1][0]);

$expected = [
'tagged.iterator' => new ServiceClosureArgument(new TypedReference('iterable', 'iterable', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'tagged.iterator', [new TaggedIterator('tag')])),
'tagged.locator' => new ServiceClosureArgument(new TypedReference(PsrContainerInterface::class, PsrContainerInterface::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'tagged.locator', [new TaggedLocator('tag')])),
];
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));

(new AutowirePass())->process($container);

$expected = [
'tagged.iterator' => new ServiceClosureArgument(new TaggedIteratorArgument('tag')),
'tagged.locator' => new ServiceClosureArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('tag', 'tag', needsIndexes: true))),
];
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
}

public function testBinding()
{
$container = new ContainerBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
use Symfony\Component\DependencyInjection\Attribute\AutowireCallable;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
use Symfony\Component\DependencyInjection\Attribute\Target;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -519,46 +517,6 @@ public function testAutowireAttribute()
$this->assertFalse($locator->has('service2'));
}

/**
* @group legacy
*/
public function testTaggedIteratorAndTaggedLocatorAttributes()
{
$container = new ContainerBuilder();
$container->setParameter('some.parameter', 'bar');
$resolver = $container->register('argument_resolver.service', \stdClass::class)->addArgument([]);

$container->register('bar', \stdClass::class)->addTag('foobar');
$container->register('baz', \stdClass::class)->addTag('foobar');

$container->register('foo', WithTaggedIteratorAndTaggedLocator::class)
->addTag('controller.service_arguments');

(new RegisterControllerArgumentLocatorsPass())->process($container);

$locatorId = (string) $resolver->getArgument(0);
$container->getDefinition($locatorId)->setPublic(true);

$container->compile();

/** @var ServiceLocator $locator */
$locator = $container->get($locatorId)->get('foo::fooAction');

$this->assertCount(2, $locator->getProvidedServices());

$this->assertTrue($locator->has('iterator1'));
$this->assertInstanceOf(RewindableGenerator::class, $argIterator = $locator->get('iterator1'));
$this->assertCount(2, $argIterator);

$this->assertTrue($locator->has('locator1'));
$this->assertInstanceOf(ServiceLocator::class, $argLocator = $locator->get('locator1'));
$this->assertCount(2, $argLocator);
$this->assertTrue($argLocator->has('bar'));
$this->assertTrue($argLocator->has('baz'));

$this->assertSame(iterator_to_array($argIterator), [$argLocator->get('bar'), $argLocator->get('baz')]);
}

public function testAutowireIteratorAndAutowireLocatorAttributes()
{
$container = new ContainerBuilder();
Expand Down Expand Up @@ -767,15 +725,6 @@ public function fooAction(
}
}

class WithTaggedIteratorAndTaggedLocator
{
public function fooAction(
#[TaggedIterator('foobar')] iterable $iterator1,
#[TaggedLocator('foobar')] ServiceLocator $locator1,
) {
}
}

class WithAutowireIteratorAndAutowireLocator
{
public function fooAction(
Expand Down
Loading