Skip to content

Commit 16389f6

Browse files
bug #62685 [DependencyInjection] Fix PriorityTaggedServiceTrait when tag attributes are not a list (GromNaN)
This PR was merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Fix `PriorityTaggedServiceTrait` when tag attributes are not a list | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Alternative to #62683 Ensure the attributes of the tag are in a list before iterating on them using sequential indexes. > In symfony/monolog-bundle#485, the tag attributes are filtered, which generates gaps in the keys. The PR mentioned above causes MonologBundle to fail. This can be fixed by symfony/monolog-bundle#563. However I believe the issue should also be addressed in Symfony. Commits ------- 5a4a036 [DependencyInjection] Fix PriorityTaggedServiceTrait when tag attributes are not a list
2 parents de6acd7 + 5a4a036 commit 16389f6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
8181
$phpAttributes = [];
8282
}
8383

84+
$attributes = array_values($attributes);
8485
for ($i = 0; $i < \count($attributes); ++$i) {
8586
if (!($attribute = $attributes[$i]) && $phpAttributes) {
8687
array_splice($attributes, $i--, 1, $phpAttributes);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,21 @@ public function testMultiTagsWithMixedAttributesAndNonStaticDefault()
449449
$this->assertArrayHasKey('foo', $services);
450450
$this->assertArrayHasKey('default', $services);
451451
}
452+
453+
public function testTagAttributesAreNotAList()
454+
{
455+
$container = new ContainerBuilder();
456+
$container->register('service1')->setTags([
457+
'my_custom_tag' => [1 => ['attributes' => 'not_a_list']],
458+
]);
459+
460+
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
461+
462+
$expected = [
463+
new Reference('service1'),
464+
];
465+
$this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container));
466+
}
452467
}
453468

454469
class PriorityTaggedServiceTraitImplementation

0 commit comments

Comments
 (0)