Skip to content

Commit fdd2ec2

Browse files
committed
[DependencyInjection] Don't ignore attributes on the actual decorator
1 parent e789e08 commit fdd2ec2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
8787
$instanceofDef->setAbstract(true)->setParent($parent ?: '.abstract.instanceof.'.$id);
8888
$parent = '.instanceof.'.$interface.'.'.$key.'.'.$id;
8989
$container->setDefinition($parent, $instanceofDef);
90-
$instanceofTags[] = $instanceofDef->getTags();
90+
$instanceofTags[] = [$interface, $instanceofDef->getTags()];
9191
$instanceofBindings = $instanceofDef->getBindings() + $instanceofBindings;
9292

9393
foreach ($instanceofDef->getMethodCalls() as $methodCall) {
@@ -126,8 +126,9 @@ private function processDefinition(ContainerBuilder $container, string $id, Defi
126126
// Don't add tags to service decorators
127127
$i = \count($instanceofTags);
128128
while (0 <= --$i) {
129-
foreach ($instanceofTags[$i] as $k => $v) {
130-
if (null === $definition->getDecoratedService() || \in_array($k, $tagsToKeep, true)) {
129+
[$interface, $tags] = $instanceofTags[$i];
130+
foreach ($tags as $k => $v) {
131+
if (null === $definition->getDecoratedService() || $interface === $definition->getClass() || \in_array($k, $tagsToKeep, true)) {
131132
foreach ($v as $v) {
132133
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
133134
continue;

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,26 @@ public function testDecoratorsAreNotAutomaticallyTagged()
318318
$decorator->setDecoratedService('decorated');
319319
$decorator->setInstanceofConditionals([
320320
parent::class => (new ChildDefinition(''))->addTag('tag'),
321+
self::class => (new ChildDefinition(''))->addTag('other-tag'),
321322
]);
322323
$decorator->setAutoconfigured(true);
323324
$decorator->addTag('manual');
324325

325326
$container->registerForAutoconfiguration(parent::class)
326327
->addTag('tag')
327328
;
329+
$container->registerForAutoconfiguration(self::class)
330+
->addTag('last-tag')
331+
;
328332

329333
(new ResolveInstanceofConditionalsPass())->process($container);
330334
(new ResolveChildDefinitionsPass())->process($container);
331335

332-
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
336+
$this->assertSame([
337+
'manual' => [[]],
338+
'other-tag' => [[]],
339+
'last-tag' => [[]],
340+
], $container->getDefinition('decorator')->getTags());
333341
}
334342

335343
public function testDecoratorsKeepBehaviorDescribingTags()

0 commit comments

Comments
 (0)