Skip to content

Commit c90cd42

Browse files
committed
feature #60845 [DependencyInjection] Remove #[TaggedIterator] and #[TaggedLocator] attributes (GromNaN)
This PR was merged into the 8.0 branch. Discussion ---------- [DependencyInjection] Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes | Q | A | ------------- | --- | Branch? | 8.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT The new attributes `#[AutowireLocator]` and `#[AutowireIterator]` were introduced in Symfony 6.4 by #51392 and #51832. These replace the previous attributes `#[TaggedIterator]` and `#[TaggedLocator]` which were introduced in Symfony 5.4 by #40406 and subsequently deprecated in 7.1 by #54371 Commits ------- c096714 Remove TaggedIterator and TaggedLocator attributes
2 parents 478f5c3 + c096714 commit c90cd42

File tree

6 files changed

+30
-182
lines changed

6 files changed

+30
-182
lines changed

UPGRADE-8.0.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ Console
8484
$application->addCommand(new CreateUserCommand());
8585
```
8686

87+
DependencyInjection
88+
-------------------
89+
90+
* Replace `#[TaggedIterator]` and `#[TaggedLocator]` attributes with `#[AutowireLocator]` and `#[AutowireIterator]`
91+
92+
*Before*
93+
```php
94+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
95+
96+
class MyService
97+
{
98+
public function __construct(#[TaggedIterator('app.my_tag')] private iterable $services) {}
99+
}
100+
```
101+
102+
*After*
103+
```php
104+
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
105+
106+
class MyService
107+
{
108+
public function __construct(#[AutowireIterator('app.my_tag')] private iterable $services) {}
109+
}
110+
```
111+
87112
DoctrineBridge
88113
--------------
89114

src/Symfony/Component/DependencyInjection/Attribute/TaggedIterator.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Symfony/Component/DependencyInjection/Attribute/TaggedLocator.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
8.0
5+
---
6+
7+
* Remove `#[TaggedIterator]` and `#[TaggedLocator]` attributes, replaced by `#[AutowireLocator]` and `#[AutowireIterator]`
8+
49
7.4
510
---
611

src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterServiceSubscribersPassTest.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Psr\Container\ContainerInterface as PsrContainerInterface;
1616
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
17-
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
18-
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
1917
use Symfony\Component\DependencyInjection\Attribute\Autowire;
2018
use Symfony\Component\DependencyInjection\Attribute\AutowireDecorated;
21-
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
22-
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
2319
use Symfony\Component\DependencyInjection\Attribute\Target;
2420
use Symfony\Component\DependencyInjection\Compiler\AutowirePass;
2521
use Symfony\Component\DependencyInjection\Compiler\RegisterServiceSubscribersPass;
@@ -458,49 +454,6 @@ public static function getSubscribedServices(): array
458454
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
459455
}
460456

461-
/**
462-
* @group legacy
463-
*/
464-
public function testSubscribedServiceWithLegacyAttributes()
465-
{
466-
$container = new ContainerBuilder();
467-
468-
$subscriber = new class implements ServiceSubscriberInterface {
469-
public static function getSubscribedServices(): array
470-
{
471-
return [
472-
new SubscribedService('tagged.iterator', 'iterable', attributes: new TaggedIterator('tag')),
473-
new SubscribedService('tagged.locator', PsrContainerInterface::class, attributes: new TaggedLocator('tag')),
474-
];
475-
}
476-
};
477-
478-
$container->setParameter('parameter.1', 'foobar');
479-
$container->register('foo', $subscriber::class)
480-
->addMethodCall('setContainer', [new Reference(PsrContainerInterface::class)])
481-
->addTag('container.service_subscriber');
482-
483-
(new RegisterServiceSubscribersPass())->process($container);
484-
(new ResolveServiceSubscribersPass())->process($container);
485-
486-
$foo = $container->getDefinition('foo');
487-
$locator = $container->getDefinition((string) $foo->getMethodCalls()[0][1][0]);
488-
489-
$expected = [
490-
'tagged.iterator' => new ServiceClosureArgument(new TypedReference('iterable', 'iterable', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'tagged.iterator', [new TaggedIterator('tag')])),
491-
'tagged.locator' => new ServiceClosureArgument(new TypedReference(PsrContainerInterface::class, PsrContainerInterface::class, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, 'tagged.locator', [new TaggedLocator('tag')])),
492-
];
493-
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
494-
495-
(new AutowirePass())->process($container);
496-
497-
$expected = [
498-
'tagged.iterator' => new ServiceClosureArgument(new TaggedIteratorArgument('tag')),
499-
'tagged.locator' => new ServiceClosureArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('tag', 'tag', needsIndexes: true))),
500-
];
501-
$this->assertEquals($expected, $container->getDefinition((string) $locator->getFactory()[0])->getArgument(0));
502-
}
503-
504457
public function testBinding()
505458
{
506459
$container = new ContainerBuilder();

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use Symfony\Component\DependencyInjection\Attribute\AutowireCallable;
2020
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
2121
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
22-
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
23-
use Symfony\Component\DependencyInjection\Attribute\TaggedLocator;
2422
use Symfony\Component\DependencyInjection\Attribute\Target;
2523
use Symfony\Component\DependencyInjection\ChildDefinition;
2624
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -519,46 +517,6 @@ public function testAutowireAttribute()
519517
$this->assertFalse($locator->has('service2'));
520518
}
521519

522-
/**
523-
* @group legacy
524-
*/
525-
public function testTaggedIteratorAndTaggedLocatorAttributes()
526-
{
527-
$container = new ContainerBuilder();
528-
$container->setParameter('some.parameter', 'bar');
529-
$resolver = $container->register('argument_resolver.service', \stdClass::class)->addArgument([]);
530-
531-
$container->register('bar', \stdClass::class)->addTag('foobar');
532-
$container->register('baz', \stdClass::class)->addTag('foobar');
533-
534-
$container->register('foo', WithTaggedIteratorAndTaggedLocator::class)
535-
->addTag('controller.service_arguments');
536-
537-
(new RegisterControllerArgumentLocatorsPass())->process($container);
538-
539-
$locatorId = (string) $resolver->getArgument(0);
540-
$container->getDefinition($locatorId)->setPublic(true);
541-
542-
$container->compile();
543-
544-
/** @var ServiceLocator $locator */
545-
$locator = $container->get($locatorId)->get('foo::fooAction');
546-
547-
$this->assertCount(2, $locator->getProvidedServices());
548-
549-
$this->assertTrue($locator->has('iterator1'));
550-
$this->assertInstanceOf(RewindableGenerator::class, $argIterator = $locator->get('iterator1'));
551-
$this->assertCount(2, $argIterator);
552-
553-
$this->assertTrue($locator->has('locator1'));
554-
$this->assertInstanceOf(ServiceLocator::class, $argLocator = $locator->get('locator1'));
555-
$this->assertCount(2, $argLocator);
556-
$this->assertTrue($argLocator->has('bar'));
557-
$this->assertTrue($argLocator->has('baz'));
558-
559-
$this->assertSame(iterator_to_array($argIterator), [$argLocator->get('bar'), $argLocator->get('baz')]);
560-
}
561-
562520
public function testAutowireIteratorAndAutowireLocatorAttributes()
563521
{
564522
$container = new ContainerBuilder();
@@ -767,15 +725,6 @@ public function fooAction(
767725
}
768726
}
769727

770-
class WithTaggedIteratorAndTaggedLocator
771-
{
772-
public function fooAction(
773-
#[TaggedIterator('foobar')] iterable $iterator1,
774-
#[TaggedLocator('foobar')] ServiceLocator $locator1,
775-
) {
776-
}
777-
}
778-
779728
class WithAutowireIteratorAndAutowireLocator
780729
{
781730
public function fooAction(

0 commit comments

Comments
 (0)
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