From c09671462a63addb3c964f813778fd3b3b24661b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 20 Jun 2025 09:58:31 +0200 Subject: [PATCH] Remove TaggedIterator and TaggedLocator attributes --- UPGRADE-8.0.md | 25 +++++++++ .../Attribute/TaggedIterator.php | 42 --------------- .../Attribute/TaggedLocator.php | 42 --------------- .../DependencyInjection/CHANGELOG.md | 5 ++ .../RegisterServiceSubscribersPassTest.php | 47 ----------------- ...sterControllerArgumentLocatorsPassTest.php | 51 ------------------- 6 files changed, 30 insertions(+), 182 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Attribute/TaggedIterator.php delete mode 100644 src/Symfony/Component/DependencyInjection/Attribute/TaggedLocator.php diff --git a/UPGRADE-8.0.md b/UPGRADE-8.0.md index 099ceb671b369..18707ddb21f16 100644 --- a/UPGRADE-8.0.md +++ b/UPGRADE-8.0.md @@ -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 -------------- diff --git a/src/Symfony/Component/DependencyInjection/Attribute/TaggedIterator.php b/src/Symfony/Component/DependencyInjection/Attribute/TaggedIterator.php deleted file mode 100644 index cd558def31f55..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Attribute/TaggedIterator.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Attribute; - -/** - * Autowires an iterator of services based on a tag name. - * - * @deprecated since Symfony 7.1, use {@see AutowireIterator} instead. - */ -#[\Attribute(\Attribute::TARGET_PARAMETER)] -class TaggedIterator extends AutowireIterator -{ - /** - * @param string $tag The tag to look for to populate the iterator - * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the tagged collection - * @param string|null $defaultIndexMethod The static method that should be called to get each service's key when their tag doesn't define the previous attribute - * @param string|null $defaultPriorityMethod The static method that should be called to get each service's priority when their tag doesn't define the "priority" attribute - * @param string|string[] $exclude A service id or a list of service ids to exclude - * @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator - */ - public function __construct( - public string $tag, - public ?string $indexAttribute = null, - public ?string $defaultIndexMethod = null, - public ?string $defaultPriorityMethod = null, - public string|array $exclude = [], - public bool $excludeSelf = true, - ) { - trigger_deprecation('symfony/dependency-injection', '7.1', 'The "%s" attribute is deprecated, use "%s" instead.', self::class, AutowireIterator::class); - - parent::__construct($tag, $indexAttribute, $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf); - } -} diff --git a/src/Symfony/Component/DependencyInjection/Attribute/TaggedLocator.php b/src/Symfony/Component/DependencyInjection/Attribute/TaggedLocator.php deleted file mode 100644 index d122930f56eb8..0000000000000 --- a/src/Symfony/Component/DependencyInjection/Attribute/TaggedLocator.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\DependencyInjection\Attribute; - -/** - * Autowires a locator of services based on a tag name. - * - * @deprecated since Symfony 7.1, use {@see AutowireLocator} instead. - */ -#[\Attribute(\Attribute::TARGET_PARAMETER)] -class TaggedLocator extends AutowireLocator -{ - /** - * @param string $tag The tag to look for to populate the locator - * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the tagged collection - * @param string|null $defaultIndexMethod The static method that should be called to get each service's key when their tag doesn't define the previous attribute - * @param string|null $defaultPriorityMethod The static method that should be called to get each service's priority when their tag doesn't define the "priority" attribute - * @param string|string[] $exclude A service id or a list of service ids to exclude - * @param bool $excludeSelf Whether to automatically exclude the referencing service from the locator - */ - public function __construct( - public string $tag, - public ?string $indexAttribute = null, - public ?string $defaultIndexMethod = null, - public ?string $defaultPriorityMethod = null, - public string|array $exclude = [], - public bool $excludeSelf = true, - ) { - trigger_deprecation('symfony/dependency-injection', '7.1', 'The "%s" attribute is deprecated, use "%s" instead.', self::class, AutowireLocator::class); - - parent::__construct($tag, $indexAttribute, $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf); - } -} diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 5c6c41cfdf27b..0d87d8d9a8535 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + + * Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes, replaced by `#[AutowireLocator]` and `#[AutowireIterator]` + 7.4 --- diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php index e7b36d3ce496a..dedf309f0fd89 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php @@ -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; @@ -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(); diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index a4b1e91d0afe1..1b10277e733bc 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -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; @@ -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(); @@ -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( pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy