Skip to content

Commit

Permalink
[DI] Dedup tags when using instanceof/autoconfigure
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Jun 17, 2017
1 parent 99573dc commit 9f877ef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Expand Up @@ -107,6 +107,9 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
while (0 <= --$i) {
foreach ($instanceofTags[$i] as $k => $v) {
foreach ($v as $v) {
if ($definition->hasTag($k) && in_array($v, $definition->getTag($k))) {
continue;
}
$definition->addTag($k, $v);
}
}
Expand Down
Expand Up @@ -130,6 +130,29 @@ public function testProcessUsesAutoconfiguredInstanceof()
$this->assertSame(array('local_instanceof_tag' => array(array()), 'autoconfigured_tag' => array(array())), $def->getTags());
}

public function testAutoconfigureInstanceofDoesNotDuplicateTags()
{
$container = new ContainerBuilder();
$def = $container->register('normal_service', self::class);
$def
->addTag('duplicated_tag')
->addTag('duplicated_tag', array('and_attributes' => 1))
;
$def->setInstanceofConditionals(array(
parent::class => (new ChildDefinition(''))->addTag('duplicated_tag'),
));
$def->setAutoconfigured(true);
$container->registerForAutoconfiguration(parent::class)
->addTag('duplicated_tag', array('and_attributes' => 1))
;

(new ResolveInstanceofConditionalsPass())->process($container);
(new ResolveDefinitionTemplatesPass())->process($container);

$def = $container->getDefinition('normal_service');
$this->assertSame(array('duplicated_tag' => array(array(), array('and_attributes' => 1))), $def->getTags());
}

public function testProcessDoesNotUseAutoconfiguredInstanceofIfNotEnabled()
{
$container = new ContainerBuilder();
Expand Down

0 comments on commit 9f877ef

Please sign in to comment.