8000 bug #30417 Autoconfig: don't automatically tag decorators (dunglas) · symfony/symfony@f3ff8aa · GitHub
[go: up one dir, main page]

Skip to content

Commit f3ff8aa

Browse files
committed
bug #30417 Autoconfig: don't automatically tag decorators (dunglas)
This PR was submitted for the 4.1 branch but it was merged into the 4.2 branch instead (closes #30417). Discussion ---------- Autoconfig: don't automatically tag decorators | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | yes | New feature? | no <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #30391 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | n/a Commits ------- 05ecf82 Autoconfig: don't automatically tag decorators
2 parents 7535383 + 05ecf82 commit f3ff8aa

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
@@ -113,14 +113,17 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
113113
$definition->setShared($shared);
114114
}
115115

116-
$i = \count($instanceofTags);
117-
while (0 <= --$i) {
118-
foreach ($instanceofTags[$i] as $k => $v) {
119-
foreach ($v as $v) {
120-
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
121-
continue;
116+
// Don't add tags to service decorators
117+
if (null === $definition->getDecoratedService()) {
118+
$i = \count($instanceofTags);
119+
while (0 <= --$i) {
120+
foreach ($instanceofTags[$i] as $k => $v) {
121+
foreach ($v as $v) {
122+
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
123+
continue;
124+
}
125+
$definition->addTag($k, $v);
122126
}
123-
$definition->addTag($k, $v);
124127
}
125128
}
126129
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,26 @@ public function testBindingsOnInstanceofConditionals()
307307
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
308308
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
309309
}
310+
311+
public function testDecoratorsAreNotAutomaticallyTagged()
312+
{
313+
$container = new ContainerBuilder();
314+
315+
$decorator = $container->register('decorator', self::class);
316+
$decorator->setDecoratedService('decorated');
317+
$decorator->setInstanceofConditionals([
318+
parent::class => (new ChildDefinition(''))->addTag('tag'),
319+
]);
320+
$decorator->setAutoconfigured(true);
321+
$decorator->addTag('manual');
322+
323+
$container->registerForAutoconfiguration(parent::class)
324+
->addTag('tag')
325+
;
326+
327+
(new ResolveInstanceofConditionalsPass())->process($container);
328+
(new ResolveChildDefinitionsPass())->process($container);
329+
330+
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
331+
}
310332
}

0 commit comments

Comments
 (0)
0