From f0922c70d6559f2fd0e8caf8a88b4bc4cabcd540 Mon Sep 17 00:00:00 2001 From: maranqz Date: Mon, 1 Mar 2021 20:45:45 +0300 Subject: [PATCH] [DependencyInjection] Add support an integer return for default_index_method --- .../Component/DependencyInjection/CHANGELOG.md | 1 + .../Compiler/PriorityTaggedServiceTrait.php | 6 +++++- .../PriorityTaggedServiceTraitTest.php | 4 ++++ .../Tests/Fixtures/IntTagClass.php | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 src/Symfony/Component/DependencyInjection/Tests/Fixtures/IntTagClass.php diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 1e45c669e89e4..82837aa0e5e96 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 806545bee9523..30b31eed16287 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 2674ea4dde24e..5c150a26d0eb8 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 0000000000000..a3114a10b5799 --- /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