Skip to content

Commit 5eda507

Browse files
committed
[DependencyInjection] Ensure Definition::getTags() contains a list of attributes for each tag
1 parent de6acd7 commit 5eda507

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/DependencyInjection/Definition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public function isAutoconfigured(): bool
422422
*/
423423
public function setTags(array $tags): static
424424
{
425-
$this->tags = $tags;
425+
$this->tags = array_map(array_values(...), $tags);
426426

427427
return $this;
428428
}

src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,19 @@ public function testSetGetConfigurator()
216216
$this->assertEquals('foo', $def->getConfigurator(), '->getConfigurator() returns the configurator');
217217
}
218218

219+
public function testSetTagsAreInList()
220+
{
221+
$def = new Definition('stdClass');
222+
$def->setTags([
223+
'tag1' => [5 => ['attr1' => 'value1'], 3 => []],
224+
'tag2' => [1 => ['attr2' => 'value2']],
225+
]);
226+
$this->assertEquals([
227+
'tag1' => [['attr1' => 'value1'], []],
228+
'tag2' => [['attr2' => 'value2']],
229+
], $def->getTags(), '->setTags() reindex the tags arrays');
230+
}
231+
219232
public function testClearTags()
220233
{
221234
$def = new Definition('stdClass');

0 commit comments

Comments
 (0)