Skip to content
Permalink
Browse files

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
  • Loading branch information...
fabpot committed Mar 4, 2019
2 parents 7535383 + 05ecf82 commit f3ff8aa40bf12b7dcaf6a39e4c9a6c7bece7e9af
@@ -113,14 +113,17 @@ private function processDefinition(ContainerBuilder $container, $id, Definition
$definition->setShared($shared);
}
$i = \count($instanceofTags);
while (0 <= --$i) {
foreach ($instanceofTags[$i] as $k => $v) {
foreach ($v as $v) {
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
continue;
// Don't add tags to service decorators
if (null === $definition->getDecoratedService()) {
$i = \count($instanceofTags);
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);
}
$definition->addTag($k, $v);
}
}
}
@@ -307,4 +307,26 @@ public function testBindingsOnInstanceofConditionals()
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
}
public function testDecoratorsAreNotAutomaticallyTagged()
{
$container = new ContainerBuilder();
$decorator = $container->register('decorator', self::class);
$decorator->setDecoratedService('decorated');
$decorator->setInstanceofConditionals([
parent::class => (new ChildDefinition(''))->addTag('tag'),
]);
$decorator->setAutoconfigured(true);
$decorator->addTag('manual');
$container->registerForAutoconfiguration(parent::class)
->addTag('tag')
;
(new ResolveInstanceofConditionalsPass())->process($container);
(new ResolveChildDefinitionsPass())->process($container);
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
}
}

0 comments on commit f3ff8aa

Please sign in to comment.
You can’t perform that action at this time.