Skip to content

Commit a69bb1e

Browse files
feature #40337 [DependencyInjection] Add support an integer return for default_index_method (maranqz)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [DependencyInjection] Add support an integer return for default_index_method | Q | A | ------------- | --- | Branch? | 5.x for features | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #40319 | License | MIT | Doc PR | TODO Commits ------- f0922c7 [DependencyInjection] Add support an integer return for default_index_method
2 parents fc016dd + f0922c7 commit a69bb1e

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Add autoconfigurable attributes
1111
* Add support for per-env configuration in loaders
1212
* Add `ContainerBuilder::willBeAvailable()` to help with conditional configuration
13+
* Add support an integer return value for default_index_method
1314

1415
5.2.0
1516
-----

src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ public static function getDefaultIndex(ContainerBuilder $container, string $serv
139139

140140
$defaultIndex = $rm->invoke(null);
141141

142+
if (\is_int($defaultIndex)) {
143+
$defaultIndex = (string) $defaultIndex;
144+
}
145+
142146
if (!\is_string($defaultIndex)) {
143-
throw new InvalidArgumentException(implode(sprintf('return a string (got "%s")', get_debug_type($defaultIndex)), $message));
147+
throw new InvalidArgumentException(implode(sprintf('return string|int (got "%s")', get_debug_type($defaultIndex)), $message));
144148
}
145149

146150
return $defaultIndex;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass;
2121
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass;
2222
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTaggedForInvalidDefaultMethodClass;
23+
use Symfony\Component\DependencyInjection\Tests\Fixtures\IntTagClass;
2324
use Symfony\Component\DependencyInjection\TypedReference;
2425

2526
class PriorityTaggedServiceTraitTest extends TestCase
@@ -145,12 +146,15 @@ public function testTheIndexedTagsByDefaultIndexMethod()
145146
$definition->addTag('my_custom_tag', ['priority' => 100]);
146147
$definition->addTag('my_custom_tag', []);
147148

149+
$container->register('service3', IntTagClass::class)->addTag('my_custom_tag');
150+
148151
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
149152

150153
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
151154
$expected = [
152155
'bar_tab_class_with_defaultmethod' => new TypedReference('service2', BarTagClass::class),
153156
'service1' => new TypedReference('service1', FooTagClass::class),
157+
'10' => new TypedReference('service3', IntTagClass::class),
154158
];
155159
$services = $priorityTaggedServiceTraitImplementation->test($tag, $container);
156160
$this->assertSame(array_keys($expected), array_keys($services));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class IntTagClass
6+
{
7+
public static function getFooBar()
8+
{
9+
return 10;
10+
}
11+
12+
public static function getPriority(): int
13+
{
14+
// Should be more than FooTagClass. More because this class is after
15+
// FooTagClass (order by name). So we want to ensure it will be before it
16+
return 30;
17+
}
18+
}

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