From b2a8a19ab00aac89aff04224df02209966b690a0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 7 Nov 2025 16:57:12 +0100 Subject: [PATCH] [DependencyInjection] Deprecate default index/priority methods when defining tagged locators/iterators --- UPGRADE-8.1.md | 8 +++ .../Argument/TaggedIteratorArgument.php | 51 ++++++++++++++----- .../Attribute/AutowireIterator.php | 32 ++++++++---- .../Attribute/AutowireLocator.php | 34 +++++++++---- .../DependencyInjection/CHANGELOG.md | 1 + .../Compiler/PriorityTaggedServiceTrait.php | 6 ++- .../DependencyInjection/Dumper/XmlDumper.php | 10 ++-- .../DependencyInjection/Dumper/YamlDumper.php | 8 +-- .../Configurator/ContainerConfigurator.php | 40 +++++++++++++-- .../Loader/YamlFileLoader.php | 11 +++- .../Argument/TaggedIteratorArgumentTest.php | 28 ++++++---- .../Tests/Compiler/IntegrationTest.php | 42 +++++++++++++-- .../PriorityTaggedServiceTraitTest.php | 34 ++++++++++++- .../Compiler/ServiceLocatorTagPassTest.php | 6 +-- .../Tests/CrossCheckTest.php | 4 ++ .../Tests/Dumper/XmlDumperTest.php | 48 ++++++++++++++++- .../Tests/Dumper/YamlDumperTest.php | 4 ++ .../Tests/Fixtures/BarTagClass.php | 12 +++++ .../Tests/Fixtures/FooTagClass.php | 9 ++++ ...IteratorConsumerWithDefaultIndexMethod.php | 3 ++ ...ndexMethodAndWithDefaultPriorityMethod.php | 3 ++ ...ratorConsumerWithDefaultPriorityMethod.php | 3 ++ ...dLocatorConsumerWithDefaultIndexMethod.php | 3 ++ ...ndexMethodAndWithDefaultPriorityMethod.php | 3 ++ ...catorConsumerWithDefaultPriorityMethod.php | 3 ++ .../legacy_services_with_tagged_arguments.xml | 39 ++++++++++++++ .../xml/services_with_tagged_arguments.xml | 4 +- .../Tests/Loader/YamlFileLoaderTest.php | 6 +++ 28 files changed, 382 insertions(+), 73 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_services_with_tagged_arguments.xml diff --git a/UPGRADE-8.1.md b/UPGRADE-8.1.md index 4aefd06c644b8..e6fa09a550333 100644 --- a/UPGRADE-8.1.md +++ b/UPGRADE-8.1.md @@ -1,10 +1,18 @@ UPGRADE FROM 8.0 to 8.1 ======================= +Symfony 8.1 is a minor release. According to the Symfony release process, there should be no significant +backward compatibility breaks. Minor backward compatibility breaks are prefixed in this document with +`[BC BREAK]`, make sure your code is compatible with these entries before upgrading. +Read more about this in the [Symfony documentation](https://symfony.com/doc/8.1/setup/upgrade_minor.html). + +If you're upgrading from a version below 8.0, follow the [8.0 upgrade guide](UPGRADE-8.0.md) first. + DependencyInjection ------------------- * Deprecate configuring options `alias`, `parent`, `synthetic`, `file`, `arguments`, `properties`, `configurator` or `calls` when using `from_callable` + * Deprecate default index/priority methods when defining tagged locators/iterators; use the `#[AsTaggedItem]` attribute instead FrameworkBundle --------------- diff --git a/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php b/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php index 2a9fdd72b73ee..942f468672e74 100644 --- a/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php +++ b/src/Symfony/Component/DependencyInjection/Argument/TaggedIteratorArgument.php @@ -21,27 +21,33 @@ class TaggedIteratorArgument extends IteratorArgument private mixed $indexAttribute = null; private ?string $defaultIndexMethod = null; private ?string $defaultPriorityMethod = null; + private bool $needsIndexes = false; + private array $exclude = []; + private bool $excludeSelf = true; /** - * @param string $tag The name of the tag identifying the target services - * @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 bool $needsIndexes Whether indexes are required and should be generated when computing the map - * @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 array $exclude Services to exclude from the iterator - * @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator + * @param string $tag The name of the tag identifying the target services + * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the tagged collection + * @param bool $needsIndexes Whether indexes are required and should be generated when computing the map + * @param string[] $exclude Services to exclude from the iterator + * @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator */ public function __construct( private string $tag, ?string $indexAttribute = null, - ?string $defaultIndexMethod = null, - private bool $needsIndexes = false, - ?string $defaultPriorityMethod = null, - private array $exclude = [], - private bool $excludeSelf = true, + bool|string|null $needsIndexes = false, + array|bool $exclude = [], + bool|string|null $excludeSelf = true, ) { parent::__construct([]); + if (\func_num_args() > 5 || !\is_bool($needsIndexes) || !\is_array($exclude) || !\is_bool($excludeSelf)) { + [, , $defaultIndexMethod, $needsIndexes, $defaultPriorityMethod, $exclude, $excludeSelf] = \func_get_args() + [2 => null, false, null, [], true]; + trigger_deprecation('symfony/dependency-injection', '7.4', 'The $defaultIndexMethod and $defaultPriorityMethod arguments of tagged locators and iterators are deprecated, use the #[AsTaggedItem] attribute instead.'); + } else { + $defaultIndexMethod = $defaultPriorityMethod = false; + } + if (null === $indexAttribute && $needsIndexes) { $indexAttribute = preg_match('/[^.]++$/', $tag, $m) ? $m[0] : $tag; } @@ -49,6 +55,9 @@ public function __construct( $this->indexAttribute = $indexAttribute; $this->defaultIndexMethod = $defaultIndexMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Name' : null); $this->defaultPriorityMethod = $defaultPriorityMethod ?: ($indexAttribute ? 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $indexAttribute))).'Priority' : null); + $this->needsIndexes = $needsIndexes; + $this->exclude = $exclude; + $this->excludeSelf = $excludeSelf; } public function getTag(): string @@ -61,8 +70,15 @@ public function getIndexAttribute(): ?string return $this->indexAttribute; } - public function getDefaultIndexMethod(): ?string + /** + * @deprecated since Symfony 8.1, use the #[AsTaggedItem] attribute instead of default methods + */ + public function getDefaultIndexMethod(/* bool $triggerDeprecation = true */): ?string { + if (!\func_num_args() || func_get_arg(0)) { + trigger_deprecation('symfony/dependency-injection', '7.4', 'The "%s()" method is deprecated, use the #[AsTaggedItem] attribute instead of default methods.', __METHOD__); + } + return $this->defaultIndexMethod; } @@ -71,8 +87,15 @@ public function needsIndexes(): bool return $this->needsIndexes; } - public function getDefaultPriorityMethod(): ?string + /** + * @deprecated since Symfony 8.1, use the #[AsTaggedItem] attribute instead of default methods + */ + public function getDefaultPriorityMethod(/* bool $triggerDeprecation = true */): ?string { + if (!\func_num_args() || func_get_arg(0)) { + trigger_deprecation('symfony/dependency-injection', '7.4', 'The "%s()" method is deprecated, use the #[AsTaggedItem] attribute instead of default methods.', __METHOD__); + } + return $this->defaultPriorityMethod; } diff --git a/src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php b/src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php index 2f845c86aaaeb..f8be526a8dc72 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/AutowireIterator.php @@ -22,21 +22,31 @@ class AutowireIterator extends Autowire /** * @see ServiceSubscriberInterface::getSubscribedServices() * - * @param string $tag A tag name to search 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|array $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 + * @param string $tag A tag name to search 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|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( string $tag, ?string $indexAttribute = null, - ?string $defaultIndexMethod = null, - ?string $defaultPriorityMethod = null, - string|array $exclude = [], - bool $excludeSelf = true, + string|array|null $exclude = [], + bool|string|null $excludeSelf = true, + ...$_, ) { - parent::__construct(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf)); + if (\func_num_args() > 4 || !\is_bool($excludeSelf) || null === $exclude || (\is_string($exclude) && str_starts_with($exclude, 'get') && !\array_key_exists('defaultIndexMethod', $_))) { + [, , $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf] = \func_get_args() + [2 => null, null, [], true]; + } else { + $defaultIndexMethod = \array_key_exists('defaultIndexMethod', $_) ? $_['defaultIndexMethod'] : false; + $defaultPriorityMethod = \array_key_exists('defaultPriorityMethod', $_) ? $_['defaultPriorityMethod'] : false; + } + + if (false !== $defaultIndexMethod || false !== $defaultPriorityMethod) { + parent::__construct(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf)); + + return; + } + + parent::__construct(new TaggedIteratorArgument($tag, $indexAttribute, false, (array) $exclude, $excludeSelf)); } } diff --git a/src/Symfony/Component/DependencyInjection/Attribute/AutowireLocator.php b/src/Symfony/Component/DependencyInjection/Attribute/AutowireLocator.php index 5268aadf78eec..cda3bd7037ab7 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/AutowireLocator.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/AutowireLocator.php @@ -28,26 +28,38 @@ class AutowireLocator extends Autowire /** * @see ServiceSubscriberInterface::getSubscribedServices() * - * @param string|array $services A tag name or an explicit list of service ids - * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the locator - * @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|array $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 + * @param string|array $services A tag name or an explicit list of service ids + * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the locator + * @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( string|array $services, ?string $indexAttribute = null, - ?string $defaultIndexMethod = null, - ?string $defaultPriorityMethod = null, - string|array $exclude = [], - bool $excludeSelf = true, + string|array|null $exclude = [], + bool|string|null $excludeSelf = true, + ...$_, ) { + if (\func_num_args() > 4 || !\is_bool($excludeSelf) || null === $exclude || (\is_string($exclude) && str_starts_with($exclude, 'get') && !\array_key_exists('defaultIndexMethod', $_))) { + [, , $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf] = \func_get_args() + [2 => null, null, [], true]; + } else { + $defaultIndexMethod = \array_key_exists('defaultIndexMethod', $_) ? $_['defaultIndexMethod'] : false; + $defaultPriorityMethod = \array_key_exists('defaultPriorityMethod', $_) ? $_['defaultPriorityMethod'] : false; + } + if (\is_string($services)) { - parent::__construct(new ServiceLocatorArgument(new TaggedIteratorArgument($services, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf))); + if (false !== $defaultIndexMethod || false !== $defaultPriorityMethod) { + parent::__construct(new ServiceLocatorArgument(new TaggedIteratorArgument($services, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf))); + + return; + } + parent::__construct(new ServiceLocatorArgument(new TaggedIteratorArgument($services, $indexAttribute, true, (array) $exclude, $excludeSelf))); return; } + if (false !== $defaultIndexMethod || false !== $defaultPriorityMethod) { + trigger_deprecation('symfony/dependency-injection', '7.4', 'The $defaultIndexMethod and $defaultPriorityMethod arguments of tagged locators and iterators attributes are deprecated, use the #[AsTaggedItem] attribute instead of default methods.'); + } $references = []; diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index e2632babb4efd..f6dc27475aad8 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Deprecate configuring options `alias`, `parent`, `synthetic`, `file`, `arguments`, `properties`, `configurator` or `calls` when using `from_callable` + * Deprecate default index/priority methods when defining tagged locators/iterators; use the `#[AsTaggedItem]` attribute instead 8.0 --- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php index 751f8a535c870..39bc6d697b4de 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -43,9 +43,9 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam if ($tagName instanceof TaggedIteratorArgument) { $indexAttribute = $tagName->getIndexAttribute(); - $defaultIndexMethod = $tagName->getDefaultIndexMethod(); + $defaultIndexMethod = $tagName->getDefaultIndexMethod(false); $needsIndexes = $tagName->needsIndexes(); - $defaultPriorityMethod = $tagName->getDefaultPriorityMethod() ?? 'getDefaultPriority'; + $defaultPriorityMethod = $tagName->getDefaultPriorityMethod(false) ?? 'getDefaultPriority'; $exclude = array_merge($exclude, $tagName->getExclude()); $tagName = $tagName->getTag(); } @@ -163,6 +163,8 @@ public static function getDefault(string $serviceId, \ReflectionClass $r, string throw new InvalidArgumentException(implode('be public', $message)); } + trigger_deprecation('symfony/dependency-injection', '7.4', 'Calling "%s::%s()" to get the "%s" index is deprecated, use the #[AsTaggedItem] attribute instead.', $class, $defaultMethod, $indexAttribute); + $default = $rm->invoke(null); if ('priority' === $indexAttribute) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php index ca579b1e5d772..1fc27e513795b 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php @@ -308,11 +308,13 @@ private function convertParameters(array $parameters, string $type, string $keyA if (null !== $tag->getIndexAttribute()) { $xmlAttr .= \sprintf(' index-by="%s"', $this->encode($tag->getIndexAttribute())); - if (null !== $tag->getDefaultIndexMethod()) { - $xmlAttr .= \sprintf(' default-index-method="%s"', $this->encode($tag->getDefaultIndexMethod())); + $defaultPrefix = 'getDefault'.str_replace(' ', '', ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $tag->getIndexAttribute()))); + + if ($tag->getDefaultIndexMethod(false) !== $defaultPrefix.'Name') { + $xmlAttr .= \sprintf(' default-index-method="%s"', $this->encode($tag->getDefaultIndexMethod(false))); } - if (null !== $tag->getDefaultPriorityMethod()) { - $xmlAttr .= \sprintf(' default-priority-method="%s"', $this->encode($tag->getDefaultPriorityMethod())); + if ($tag->getDefaultPriorityMethod(false) !== $defaultPrefix.'Priority') { + $xmlAttr .= \sprintf(' default-priority-method="%s"', $this->encode($tag->getDefaultPriorityMethod(false))); } } if (1 === \count($excludes = $tag->getExclude())) { diff --git a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php index f5501260a6689..843c483eeb70b 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php @@ -265,11 +265,11 @@ private function dumpValue(mixed $value): mixed 'index_by' => $tag->getIndexAttribute(), ]; - if (null !== $tag->getDefaultIndexMethod()) { - $content['default_index_method'] = $tag->getDefaultIndexMethod(); + if (null !== $tag->getDefaultIndexMethod(false)) { + $content['default_index_method'] = $tag->getDefaultIndexMethod(false); } - if (null !== $tag->getDefaultPriorityMethod()) { - $content['default_priority_method'] = $tag->getDefaultPriorityMethod(); + if (null !== $tag->getDefaultPriorityMethod(false)) { + $content['default_priority_method'] = $tag->getDefaultPriorityMethod(false); } } if ($excludes = $tag->getExclude()) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php index ff1f63e705ac4..f7e12177403ec 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php @@ -143,18 +143,50 @@ function iterator(array $values): IteratorArgument /** * Creates a lazy iterator by tag name. + * + * @param string $tag The name of the tag identifying the target services + * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the tagged collection + * @param string|string[] $exclude Services to exclude from the iterator + * @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator */ -function tagged_iterator(string $tag, ?string $indexAttribute = null, ?string $defaultIndexMethod = null, ?string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): TaggedIteratorArgument +function tagged_iterator(string $tag, ?string $indexAttribute = null, string|array|null $exclude = [], bool|string|null $excludeSelf = true, ...$_): TaggedIteratorArgument { - return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf); + if (\func_num_args() > 4 || !\is_bool($excludeSelf) || null === $exclude || (\is_string($exclude) && str_starts_with($exclude, 'get') && !\array_key_exists('defaultIndexMethod', $_))) { + [, , $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf] = \func_get_args() + [2 => null, null, [], true]; + } else { + $defaultIndexMethod = \array_key_exists('defaultIndexMethod', $_) ? $_['defaultIndexMethod'] : false; + $defaultPriorityMethod = \array_key_exists('defaultPriorityMethod', $_) ? $_['defaultPriorityMethod'] : false; + } + + if (false !== $defaultIndexMethod || false !== $defaultPriorityMethod) { + return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, false, $defaultPriorityMethod, (array) $exclude, $excludeSelf); + } + + return new TaggedIteratorArgument($tag, $indexAttribute, false, (array) $exclude, $excludeSelf); } /** * Creates a service locator by tag name. + * + * @param string $tag The name of the tag identifying the target services + * @param string|null $indexAttribute The name of the attribute that defines the key referencing each service in the tagged collection + * @param string|string[] $exclude Services to exclude from the iterator + * @param bool $excludeSelf Whether to automatically exclude the referencing service from the iterator */ -function tagged_locator(string $tag, ?string $indexAttribute = null, ?string $defaultIndexMethod = null, ?string $defaultPriorityMethod = null, string|array $exclude = [], bool $excludeSelf = true): ServiceLocatorArgument +function tagged_locator(string $tag, ?string $indexAttribute = null, string|array|null $exclude = [], bool|string|null $excludeSelf = true, ...$_): ServiceLocatorArgument { - return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf)); + if (\func_num_args() > 4 || !\is_bool($excludeSelf) || null === $exclude || (\is_string($exclude) && str_starts_with($exclude, 'get') && !\array_key_exists('defaultIndexMethod', $_))) { + [, , $defaultIndexMethod, $defaultPriorityMethod, $exclude, $excludeSelf] = \func_get_args() + [2 => null, null, [], true]; + } else { + $defaultIndexMethod = \array_key_exists('defaultIndexMethod', $_) ? $_['defaultIndexMethod'] : false; + $defaultPriorityMethod = \array_key_exists('defaultPriorityMethod', $_) ? $_['defaultPriorityMethod'] : false; + } + + if (false !== $defaultIndexMethod || false !== $defaultPriorityMethod) { + return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod, true, $defaultPriorityMethod, (array) $exclude, $excludeSelf)); + } + + return new ServiceLocatorArgument(new TaggedIteratorArgument($tag, $indexAttribute, true, (array) $exclude, $excludeSelf)); } /** diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 785740df6db87..271364e84b072 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -867,7 +867,16 @@ private function resolveServices(mixed $value, string $file, bool $isParameter = throw new InvalidArgumentException(\sprintf('"!%s" tag contains unsupported key "%s"; supported ones are "%s".', $value->getTag(), implode('", "', $diff), implode('", "', $supportedKeys))); } - $argument = new TaggedIteratorArgument($argument['tag'], $argument['index_by'] ?? null, $argument['default_index_method'] ?? null, $forLocator, $argument['default_priority_method'] ?? null, (array) ($argument['exclude'] ?? null), $argument['exclude_self'] ?? true); + $tag = $argument['tag']; + $indexBy = $argument['index_by'] ?? null; + $exclude = (array) ($argument['exclude'] ?? null); + $excludeSelf = $argument['exclude_self'] ?? true; + + if (\array_key_exists('default_index_method', $argument) || \array_key_exists('default_priority_method', $argument)) { + $argument = new TaggedIteratorArgument($tag, $indexBy, $argument['default_index_method'] ?? null, $forLocator, $argument['default_priority_method'] ?? null, $exclude, $excludeSelf); + } else { + $argument = new TaggedIteratorArgument($tag, $indexBy, $forLocator, $exclude, $excludeSelf); + } } elseif (\is_string($argument) && $argument) { $argument = new TaggedIteratorArgument($argument, null, null, $forLocator); } else { diff --git a/src/Symfony/Component/DependencyInjection/Tests/Argument/TaggedIteratorArgumentTest.php b/src/Symfony/Component/DependencyInjection/Tests/Argument/TaggedIteratorArgumentTest.php index df7d393c04e7a..6c6ae36db558b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Argument/TaggedIteratorArgumentTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Argument/TaggedIteratorArgumentTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Argument; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; @@ -23,42 +25,44 @@ public function testWithTagOnly() $this->assertSame('foo', $taggedIteratorArgument->getTag()); $this->assertNull($taggedIteratorArgument->getIndexAttribute()); - $this->assertNull($taggedIteratorArgument->getDefaultIndexMethod()); + $this->assertNull($taggedIteratorArgument->getDefaultIndexMethod(false)); $this->assertFalse($taggedIteratorArgument->needsIndexes()); - $this->assertNull($taggedIteratorArgument->getDefaultPriorityMethod()); + $this->assertNull($taggedIteratorArgument->getDefaultPriorityMethod(false)); } public function testOnlyTagWithNeedsIndexes() { - $taggedIteratorArgument = new TaggedIteratorArgument('foo', null, null, true); + $taggedIteratorArgument = new TaggedIteratorArgument('foo', null, true); $this->assertSame('foo', $taggedIteratorArgument->getTag()); $this->assertSame('foo', $taggedIteratorArgument->getIndexAttribute()); - $this->assertSame('getDefaultFooName', $taggedIteratorArgument->getDefaultIndexMethod()); - $this->assertSame('getDefaultFooPriority', $taggedIteratorArgument->getDefaultPriorityMethod()); + $this->assertSame('getDefaultFooName', $taggedIteratorArgument->getDefaultIndexMethod(false)); + $this->assertSame('getDefaultFooPriority', $taggedIteratorArgument->getDefaultPriorityMethod(false)); } public function testOnlyTagWithNeedsIndexesAndDotTag() { - $taggedIteratorArgument = new TaggedIteratorArgument('foo.bar', null, null, true); + $taggedIteratorArgument = new TaggedIteratorArgument('foo.bar', null, true); $this->assertSame('foo.bar', $taggedIteratorArgument->getTag()); $this->assertSame('bar', $taggedIteratorArgument->getIndexAttribute()); - $this->assertSame('getDefaultBarName', $taggedIteratorArgument->getDefaultIndexMethod()); - $this->assertSame('getDefaultBarPriority', $taggedIteratorArgument->getDefaultPriorityMethod()); + $this->assertSame('getDefaultBarName', $taggedIteratorArgument->getDefaultIndexMethod(false)); + $this->assertSame('getDefaultBarPriority', $taggedIteratorArgument->getDefaultPriorityMethod(false)); } public function testOnlyTagWithNeedsIndexesAndDotsTag() { - $taggedIteratorArgument = new TaggedIteratorArgument('foo.bar.baz.qux', null, null, true); + $taggedIteratorArgument = new TaggedIteratorArgument('foo.bar.baz.qux', null, true); $this->assertSame('foo.bar.baz.qux', $taggedIteratorArgument->getTag()); $this->assertSame('qux', $taggedIteratorArgument->getIndexAttribute()); - $this->assertSame('getDefaultQuxName', $taggedIteratorArgument->getDefaultIndexMethod()); - $this->assertSame('getDefaultQuxPriority', $taggedIteratorArgument->getDefaultPriorityMethod()); + $this->assertSame('getDefaultQuxName', $taggedIteratorArgument->getDefaultIndexMethod(false)); + $this->assertSame('getDefaultQuxPriority', $taggedIteratorArgument->getDefaultPriorityMethod(false)); } #[DataProvider('defaultIndexMethodProvider')] + #[IgnoreDeprecations] + #[Group('legacy')] public function testDefaultIndexMethod(?string $indexAttribute, ?string $defaultIndexMethod, ?string $expectedDefaultIndexMethod) { $taggedIteratorArgument = new TaggedIteratorArgument('foo', $indexAttribute, $defaultIndexMethod); @@ -106,6 +110,8 @@ public static function defaultIndexMethodProvider() } #[DataProvider('defaultPriorityMethodProvider')] + #[IgnoreDeprecations] + #[Group('legacy')] public function testDefaultPriorityIndexMethod(?string $indexAttribute, ?string $defaultPriorityMethod, ?string $expectedDefaultPriorityMethod) { $taggedIteratorArgument = new TaggedIteratorArgument('foo', $indexAttribute, null, false, $defaultPriorityMethod); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php index bf61835f00f7e..32cf48c80798f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Symfony\Component\Config\FileLocator; @@ -343,6 +345,8 @@ public static function getYamlCompileTests() ]; } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceWithIndexAttribute() { $container = new ContainerBuilder(); @@ -367,6 +371,8 @@ public function testTaggedServiceWithIndexAttribute() $this->assertSame(['bar' => $container->get(BarTagClass::class), 'foo_tag_class' => $container->get(FooTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceWithIndexAttributeAndDefaultMethod() { $container = new ContainerBuilder(); @@ -418,6 +424,8 @@ public function testLocatorConfiguredViaAttribute() self::assertSame('foo', $s->locator->get('subscribed1')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceWithIndexAttributeAndDefaultMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -442,6 +450,8 @@ public function testTaggedServiceWithIndexAttributeAndDefaultMethodConfiguredVia $this->assertSame(['bar_tab_class_with_defaultmethod' => $container->get(BarTagClass::class), 'foo' => $container->get(FooTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedIteratorWithDefaultIndexMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -466,6 +476,8 @@ public function testTaggedIteratorWithDefaultIndexMethodConfiguredViaAttribute() $this->assertSame(['bar_tag_class' => $container->get(BarTagClass::class), 'foo_tag_class' => $container->get(FooTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedIteratorWithDefaultPriorityMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -490,6 +502,8 @@ public function testTaggedIteratorWithDefaultPriorityMethodConfiguredViaAttribut $this->assertSame([0 => $container->get(FooTagClass::class), 1 => $container->get(BarTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedIteratorWithDefaultIndexMethodAndWithDefaultPriorityMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -514,6 +528,8 @@ public function testTaggedIteratorWithDefaultIndexMethodAndWithDefaultPriorityMe $this->assertSame(['foo_tag_class' => $container->get(FooTagClass::class), 'bar_tag_class' => $container->get(BarTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -540,6 +556,8 @@ public function testTaggedLocatorConfiguredViaAttribute() self::assertSame($container->get(FooTagClass::class), $locator->get('foo')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorConfiguredViaAttributeWithoutIndex() { $container = new ContainerBuilder(); @@ -566,6 +584,8 @@ public function testTaggedLocatorConfiguredViaAttributeWithoutIndex() self::assertSame($container->get(FooTagClass::class), $locator->get(FooTagClass::class)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorWithDefaultIndexMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -592,6 +612,8 @@ public function testTaggedLocatorWithDefaultIndexMethodConfiguredViaAttribute() self::assertSame($container->get(FooTagClass::class), $locator->get('foo_tag_class')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorWithDefaultPriorityMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -621,6 +643,8 @@ public function testTaggedLocatorWithDefaultPriorityMethodConfiguredViaAttribute self::assertSame([FooTagClass::class, BarTagClass::class], array_keys($factories->getValue($locator))); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorWithDefaultIndexMethodAndWithDefaultPriorityMethodConfiguredViaAttribute() { $container = new ContainerBuilder(); @@ -652,6 +676,8 @@ public function testTaggedLocatorWithDefaultIndexMethodAndWithDefaultPriorityMet self::assertSame($container->get(FooTagClass::class), $locator->get('foo_tag_class')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testNestedDefinitionWithAutoconfiguredConstructorArgument() { $container = new ContainerBuilder(); @@ -699,6 +725,8 @@ public function testFactoryWithAutoconfiguredArgument() self::assertSame($container->get(FooTagClass::class), $locator->get('my_service')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceWithDefaultPriorityMethod() { $container = new ContainerBuilder(); @@ -723,6 +751,8 @@ public function testTaggedServiceWithDefaultPriorityMethod() $this->assertSame([$container->get(FooTagClass::class), $container->get(BarTagClass::class)], $param); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceLocatorWithIndexAttribute() { $container = new ContainerBuilder(); @@ -735,7 +765,7 @@ public function testTaggedServiceLocatorWithIndexAttribute() ->addTag('foo_bar') ; $container->register('foo_bar_tagged', FooBarTaggedClass::class) - ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', 'foo', null, true))) + ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', 'foo', true))) ->setPublic(true) ; @@ -754,6 +784,8 @@ public function testTaggedServiceLocatorWithIndexAttribute() $this->assertSame(['bar' => $container->get('bar_tag'), 'foo_tag_class' => $container->get('foo_tag')], $same); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceLocatorWithMultipleIndexAttribute() { $container = new ContainerBuilder(); @@ -768,7 +800,7 @@ public function testTaggedServiceLocatorWithMultipleIndexAttribute() ->addTag('foo_bar') ; $container->register('foo_bar_tagged', FooBarTaggedClass::class) - ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', 'foo', null, true))) + ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', 'foo', true))) ->setPublic(true) ; @@ -788,6 +820,8 @@ public function testTaggedServiceLocatorWithMultipleIndexAttribute() $this->assertSame(['bar' => $container->get('bar_tag'), 'bar_duplicate' => $container->get('bar_tag'), 'foo_tag_class' => $container->get('foo_tag')], $same); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedServiceLocatorWithIndexAttributeAndDefaultMethod() { $container = new ContainerBuilder(); @@ -827,7 +861,7 @@ public function testTaggedServiceLocatorWithFallback() ->addTag('foo_bar') ; $container->register('foo_bar_tagged', FooBarTaggedClass::class) - ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', null, null, true))) + ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('foo_bar', null, true))) ->setPublic(true) ; @@ -853,7 +887,7 @@ public function testTaggedServiceLocatorWithDefaultIndex() ->addTag('app.foo_bar', ['foo_bar' => 'baz']) ; $container->register('foo_bar_tagged', FooBarTaggedClass::class) - ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('app.foo_bar', null, null, true))) + ->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('app.foo_bar', null, true))) ->setPublic(true) ; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php index 8983e7fcf6c8b..d8309e1fe9e86 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument; use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; @@ -115,6 +117,8 @@ public function testOnlyTheFirstNonIndexedTagIsListed() $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testOnlyTheIndexedTagsAreListed() { $container = new ContainerBuilder(); @@ -141,6 +145,8 @@ public function testOnlyTheIndexedTagsAreListed() $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test($tag, $container)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTheIndexedTagsByDefaultIndexMethod() { $container = new ContainerBuilder(); @@ -173,6 +179,8 @@ public function testTheIndexedTagsByDefaultIndexMethod() } #[DataProvider('provideInvalidDefaultMethods')] + #[IgnoreDeprecations] + #[Group('legacy')] public function testTheIndexedTagsByDefaultIndexMethodFailure(string $defaultIndexMethod, ?string $indexAttribute, string $expectedExceptionMessage) { $this->expectException(InvalidArgumentException::class); @@ -198,6 +206,8 @@ public static function provideInvalidDefaultMethods(): iterable yield ['getMethodShouldBePublicInsteadPrivate', 'foo', \sprintf('Either method "%s::getMethodShouldBePublicInsteadPrivate()" should be public or tag "my_custom_tag" on service "service1" is missing attribute "foo".', FooTaggedForInvalidDefaultMethodClass::class)]; } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedItemAttributes() { $container = new ContainerBuilder(); @@ -225,7 +235,7 @@ public function testTaggedItemAttributes() $priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation(); - $tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar', exclude: ['service4', 'service5']); + $tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar', false, null, ['service4', 'service5']); $expected = [ 'service3' => new TypedReference('service3', HelloNamedService2::class), 'multi_hello_2' => new TypedReference('service6', MultiTagHelloNamedService::class), @@ -240,6 +250,8 @@ public function testTaggedItemAttributes() $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test($tag, $container)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testResolveIndexedTags() { $container = new ContainerBuilder(); @@ -268,6 +280,8 @@ public function testResolveIndexedTags() $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test($tag, $container)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testAttributesAreMergedWithTags() { $container = new ContainerBuilder(); @@ -293,6 +307,8 @@ public function testAttributesAreMergedWithTags() $this->assertEquals($expected, $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testAttributesAreFallbacks() { $container = new ContainerBuilder(); @@ -310,6 +326,8 @@ public function testAttributesAreFallbacks() $this->assertEquals(['z' => new TypedReference('service_attr_first', MultiTagHelloNamedService::class)], $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedIteratorWithDefaultNameMethod() { $container = new ContainerBuilder(); @@ -322,6 +340,8 @@ public function testTaggedIteratorWithDefaultNameMethod() $this->assertEquals([new Reference('service')], $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testIndexedIteratorUsesTagAttributeOverDefaultMethod() { $container = new ContainerBuilder(); @@ -339,6 +359,8 @@ public function testIndexedIteratorUsesTagAttributeOverDefaultMethod() $this->assertSame('service.a', (string) $services['from_tag']); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testIndexedIteratorUsesDefaultMethodAsFallback() { $container = new ContainerBuilder(); @@ -355,6 +377,8 @@ public function testIndexedIteratorUsesDefaultMethodAsFallback() $this->assertInstanceOf(TypedReference::class, $services['from_static_method']); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testIndexedIteratorUsesTagIndexAndDefaultPriorityMethod() { $container = new ContainerBuilder(); @@ -376,6 +400,8 @@ public function testIndexedIteratorUsesTagIndexAndDefaultPriorityMethod() $this->assertSame(['tag_index', 'another_index'], array_keys($services)); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorWithProvidedIndexAttributeAndNonStaticDefaultIndexMethod() { $container = new ContainerBuilder(); @@ -389,6 +415,8 @@ public function testTaggedLocatorWithProvidedIndexAttributeAndNonStaticDefaultIn $this->assertEquals(['foo' => new TypedReference('service', NonStaticDefaultIndexClass::class)], $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedLocatorWithoutIndexAttributeAndNonStaticDefaultIndexMethod() { $this->expectException(InvalidArgumentException::class); @@ -420,6 +448,8 @@ public function testMergingAsTaggedItemWithEmptyTagAndNonStaticBusinessMethod() $this->assertEquals(['bar' => new TypedReference('service', AsTaggedItemClassWithBusinessMethod::class)], $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testPriorityFallbackWithoutIndexAndStaticPriorityMethod() { $container = new ContainerBuilder(); @@ -433,6 +463,8 @@ public function testPriorityFallbackWithoutIndexAndStaticPriorityMethod() $this->assertEquals([new Reference('service')], $services); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testMultiTagsWithMixedAttributesAndNonStaticDefault() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php index ad9c62d9b387f..6ede05a70ece2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -177,7 +177,7 @@ public function testTaggedServices() $container->register('baz', TestDefinition2::class)->addTag('test_tag'); $container->register('foo', ServiceLocator::class) - ->setArguments([new TaggedIteratorArgument('test_tag', null, null, true)]) + ->setArguments([new TaggedIteratorArgument('test_tag', null, true)]) ->addTag('container.service_locator') ; @@ -198,7 +198,7 @@ public function testTaggedServicesKeysAreKept() $container->register('baz', TestDefinition2::class)->addTag('test_tag', ['index' => 1]); $container->register('foo', ServiceLocator::class) - ->setArguments([new TaggedIteratorArgument('test_tag', 'index', null, true)]) + ->setArguments([new TaggedIteratorArgument('test_tag', 'index', true)]) ->addTag('container.service_locator') ; @@ -217,7 +217,7 @@ public function testIndexedByServiceIdWithDecoration() $locator = new Definition(Locator::class); $locator->setPublic(true); - $locator->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('test_tag', null, null, true))); + $locator->addArgument(new ServiceLocatorArgument(new TaggedIteratorArgument('test_tag', null, true))); $container->setDefinition(Locator::class, $locator); diff --git a/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php b/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php index 3b8ada9feb2a3..1bda112cb2580 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/CrossCheckTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -31,6 +33,8 @@ public static function setUpBeforeClass(): void } #[DataProvider('crossCheckYamlLoadersDumpers')] + #[IgnoreDeprecations] + #[Group('legacy')] public function testYamlCrossCheck($fixture) { $tmp = tempnam(sys_get_temp_dir(), 'sf'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php index 27a8968dcf4ec..686c22056eb2e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\AbstractArgument; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; @@ -188,6 +190,50 @@ public function testDumpAutowireData() } public function testTaggedArguments() + { + $taggedIterator = new TaggedIteratorArgument('foo_tag', 'barfoo'); + $taggedIterator2 = new TaggedIteratorArgument('foo_tag', null, false, ['baz']); + $taggedIterator3 = new TaggedIteratorArgument('foo_tag', null, false, ['baz', 'qux'], false); + + $container = new ContainerBuilder(); + + $container->register('foo', 'Foo')->addTag('foo_tag'); + $container->register('baz', 'Baz')->addTag('foo_tag'); + $container->register('qux', 'Qux')->addTag('foo_tag'); + + $container->register('foo_tagged_iterator', 'Bar') + ->setPublic(true) + ->addArgument($taggedIterator) + ; + $container->register('foo2_tagged_iterator', 'Bar') + ->setPublic(true) + ->addArgument($taggedIterator2) + ; + $container->register('foo3_tagged_iterator', 'Bar') + ->setPublic(true) + ->addArgument($taggedIterator3) + ; + + $container->register('foo_tagged_locator', 'Bar') + ->setPublic(true) + ->addArgument(new ServiceLocatorArgument($taggedIterator)) + ; + $container->register('foo2_tagged_locator', 'Bar') + ->setPublic(true) + ->addArgument(new ServiceLocatorArgument($taggedIterator2)) + ; + $container->register('foo3_tagged_locator', 'Bar') + ->setPublic(true) + ->addArgument(new ServiceLocatorArgument($taggedIterator3)) + ; + + $dumper = new XmlDumper($container); + $this->assertXmlStringEqualsGeneratedXmlFile('services_with_tagged_arguments.xml', $dumper->dump()); + } + + #[IgnoreDeprecations] + #[Group('legacy')] + public function testLegacyTaggedArguments() { $taggedIterator = new TaggedIteratorArgument('foo_tag', 'barfoo', 'foobar', false, 'getPriority'); $taggedIterator2 = new TaggedIteratorArgument('foo_tag', null, null, false, null, ['baz']); @@ -226,7 +272,7 @@ public function testTaggedArguments() ; $dumper = new XmlDumper($container); - $this->assertXmlStringEqualsGeneratedXmlFile('services_with_tagged_arguments.xml', $dumper->dump()); + $this->assertXmlStringEqualsGeneratedXmlFile('legacy_services_with_tagged_arguments.xml', $dumper->dump()); } public function testServiceClosure() diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php index 6bc39ce67f335..823142146e385 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php @@ -12,6 +12,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Dumper; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\AbstractArgument; @@ -114,6 +116,8 @@ public function testInlineServices() $this->assertStringEqualsGeneratedFile('services_inline.yml', $dumper->dump()); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedArguments() { $taggedIterator = new TaggedIteratorArgument('foo', 'barfoo', 'foobar', false, 'getPriority'); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php index 158faa35247cd..8a6837dfe38a7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php @@ -2,18 +2,30 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures; +use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; + +#[AsTaggedItem('bar_tag_class')] class BarTagClass { + /** + * @deprecated since Symfony 8.1 + */ public static function getDefaultFooName() { return 'bar_tag_class'; } + /** + * @deprecated since Symfony 8.1 + */ public static function getFooBar() { return 'bar_tab_class_with_defaultmethod'; } + /** + * @deprecated since Symfony 8.1 + */ public static function getPriority(): int { return 0; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php index 75bbc2c21d9cc..2a04906585841 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php @@ -2,13 +2,22 @@ namespace Symfony\Component\DependencyInjection\Tests\Fixtures; +use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem; + +#[AsTaggedItem('foo_tag_class')] class FooTagClass { + /** + * @deprecated since Symfony 8.1 + */ public static function getDefaultFooName() { return 'foo_tag_class'; } + /** + * @deprecated since Symfony 8.1 + */ public static function getPriority(): int { // Should be more than BarTagClass. More because this class is after diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethod.php index 4f9f6c950a794..12b1610574918 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethod.php @@ -4,6 +4,9 @@ use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedIteratorConsumerWithDefaultIndexMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php index e6fa728e51b84..4fabbe1e724d1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php @@ -4,6 +4,9 @@ use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedIteratorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultPriorityMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultPriorityMethod.php index f0c71d9da4f3e..115807c796892 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultPriorityMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedIteratorConsumerWithDefaultPriorityMethod.php @@ -4,6 +4,9 @@ use Symfony\Component\DependencyInjection\Attribute\AutowireIterator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedIteratorConsumerWithDefaultPriorityMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethod.php index 350e5e7c0b6c2..277eb4a27ea56 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethod.php @@ -5,6 +5,9 @@ use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedLocatorConsumerWithDefaultIndexMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php index f2c67965cd61d..7820c3a1afa35 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod.php @@ -5,6 +5,9 @@ use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedLocatorConsumerWithDefaultIndexMethodAndWithDefaultPriorityMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultPriorityMethod.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultPriorityMethod.php index 1c437605ebe3a..8efc737a4fe94 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultPriorityMethod.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/TaggedLocatorConsumerWithDefaultPriorityMethod.php @@ -5,6 +5,9 @@ use Psr\Container\ContainerInterface; use Symfony\Component\DependencyInjection\Attribute\AutowireLocator; +/** + * @deprecated since Symfony 8.1 + */ final class TaggedLocatorConsumerWithDefaultPriorityMethod { public function __construct( diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_services_with_tagged_arguments.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_services_with_tagged_arguments.xml new file mode 100644 index 0000000000000..a74212440108d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/legacy_services_with_tagged_arguments.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + baz + qux + + + + + + + + + + + baz + qux + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_tagged_arguments.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_tagged_arguments.xml index a74212440108d..93c48975c8df3 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_tagged_arguments.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_tagged_arguments.xml @@ -12,7 +12,7 @@ - + @@ -24,7 +24,7 @@ - + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 9e9f3b911e4c9..081fccfd7c4a6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -415,6 +415,8 @@ public function testTagWithoutNameThrowsException() } } + #[IgnoreDeprecations] + #[Group('legacy')] public function testTaggedArgumentsWithIndex() { $container = new ContainerBuilder(); @@ -528,6 +530,8 @@ public function testTagWithNonStringNameThrowsException() $loader->load('tag_name_no_string.yml'); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testParsesIteratorArgument() { $container = new ContainerBuilder(); @@ -994,6 +998,8 @@ public function testFqcnLazyProxy() $this->assertSame([['interface' => 'SomeInterface']], $definition->getTag('proxy')); } + #[IgnoreDeprecations] + #[Group('legacy')] public function testServiceWithSameNameAsInterfaceAndFactoryIsNotTagged() { $container = new ContainerBuilder();