8000 Autoconfig: don't automatically tag decorators · symfony/symfony@41f877a · GitHub
[go: up one dir, main page]

Skip to content

Commit 41f877a

Browse files
committed
Autoconfig: don't automatically tag decorators
1 parent 6ca28d7 commit 41f877a

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,17 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
110110
$definition->setShared($shared);
111111
}
112112

113-
$i = \count($instanceofTags);
114-
while (0 <= --$i) {
115-
foreach ($instanceofTags[$i] as $k => $v) {
116-
foreach ($v as $v) {
117-
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
118-
continue;
113+
// Don't add tags to service decorators
114+
if (null === $definition->getDecoratedService()) {
115+
$i = \count($instanceofTags);
116+
while (0 <= --$i) {
117+
foreach ($instanceofTags[$i] as $k => $v) {
118+
foreach ($v as $v) {
119+
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
120+
continue;
121+
}
122+
$definition->addTag($k, $v);
119123
}
120-
$definition->addTag($k, $v);
121124
}
122125
}
123126
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,26 @@ public function testBindings()
283283
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
284284
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
285285
}
286+
287+
public function testDecoratorsAreNotAutomaticallyTagged()
288+
{
289+
$container = new ContainerBuilder();
290+
291+
$decorator = $container->register('decorator', self::class);
292+
$decorator->setDecoratedService('decorated');
293+
$decorator->setInstanceofConditionals([
294+
parent::class => (new ChildDefinition(''))->addTag('tag'),
295+
]);
296+
$decorator->setAutoconfigured(true);
297+
$decorator->addTag('manual');
298+
299+
$container->registerForAutoconfiguration(parent::class)
300+
->addTag('tag')
301+
;
302+
303+
(new ResolveInstanceofConditionalsPass())->process($container);
304+
(new ResolveChildDefinitionsPass())->process($container);
305+
306+
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
307+
}
286308
}

0 commit comments

Comments
 (0)
0