Skip to content

Commit 1b57d8c

Browse files
committed
Merge branch '4.2'
* 4.2: fixed CS Autoconfig: don't automatically tag decorators removed suggestion [PropertyAccess] Fixed PropertyPathBuilder remove that fails to reset internal indexes bumped Symfony version to 4.2.5 updated VERSION for 4.2.4 updated CHANGELOG for 4.2.4 bumped Symfony version to 3.4.24 updated VERSION for 3.4.23 update CONTRIBUTORS for 3.4.23 updated CHANGELOG for 3.4.23 [Routing][ServiceRouterLoader] Remove an outdated comment
2 parents 660b0d5 + a9b8a6a commit 1b57d8c

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

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
}

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)