diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 1e45c669e89e..82837aa0e5e9 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * Add autoconfigurable attributes * Add support for per-env configuration in loaders * Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration + * Add support an integer return value for default_index_method 5.2.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php index 806545bee952..30b31eed1628 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php @@ -139,8 +139,12 @@ public static function getDefaultIndex(ContainerBuilder $container, string $serv $defaultIndex = $rm->invoke(null); + if (\is_int($defaultIndex)) { + $defaultIndex = (string) $defaultIndex; + } + if (!\is_string($defaultIndex)) { - throw new InvalidArgumentException(implode(sprintf('return a string (got "%s")', get_debug_type($defaultIndex)), $message)); + throw new InvalidArgumentException(implode(sprintf('return string|int (got "%s")', get_debug_type($defaultIndex)), $message)); } return $defaultIndex; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php index 2674ea4dde24..5c150a26d0eb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTaggedForInvalidDefaultMethodClass; +use Symfony\Component\DependencyInjection\Tests\Fixtures\IntTagClass; use Symfony\Component\DependencyInjection\TypedReference; class PriorityTaggedServiceTraitTest extends TestCase @@ -145,12 +146,15 @@ public function testTheIndexedTagsByDefaultIndexMethod() $definition->addTag('my_custom_tag', ['priority' => 100]); $definition->addTag('my_custom_tag', []); + $container->register('service3', IntTagClass::class)->addTag('my_custom_tag'); + $priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation(); $tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar'); $expected = [ 'bar_tab_class_with_defaultmethod' => new TypedReference('service2', BarTagClass::class), 'service1' => new TypedReference('service1', FooTagClass::class), + '10' => new TypedReference('service3', IntTagClass::class), ]; $services = $priorityTaggedServiceTraitImplementation->test($tag, $container); $this->assertSame(array_keys($expected), array_keys($services)); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/IntTagClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/IntTagClass.php new file mode 100755 index 000000000000..a3114a10b579 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/IntTagClass.php @@ -0,0 +1,18 @@ + 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