8000 [DependencyInjection] fix empty instanceof-conditionals created by At… · symfony/symfony@5c3ee39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c3ee39

Browse files
[DependencyInjection] fix empty instanceof-conditionals created by AttributeAutoconfigurationPass
1 parent 444b40c commit 5c3ee39

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ protected function processValue($value, bool $isRoot = false)
4848
$configurator($conditionals, $attribute->newInstance(), $reflector);
4949
}
5050
}
51-
$instanceof[$reflector->getName()] = $conditionals;
52-
$value->setInstanceofConditionals($instanceof);
51+
if (!isset($instanceof[$reflector->getName()]) && new ChildDefinition('') != $conditionals) {
52+
$instanceof[$reflector->getName()] = $conditionals;
53+
$value->setInstanceofConditionals($instanceof);
54+
}
5355

5456
return parent::processValue($value, $isRoot);
5557
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Attribute\AsTaggedItem;
16+
use Symfony\Component\DependencyInjection\Compiler\AttributeAutoconfigurationPass;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
19+
/**
20+
* @requires PHP 8
21+
*/
22+
class AttributeAutoconfigurationPassTest extends TestCase
23+
{
24+
public function testProcessAddsNoEmptyInstanceofConditionals()
25+
{
26+
$container = new ContainerBuilder();
27+
$container->registerAttributeForAutoconfiguration(AsTaggedItem::class, static function () {});
28+
$container->register('foo', \stdClass::class)
29+
->setAutoconfigured(true)
30+
;
31+
32+
(new AttributeAutoconfigurationPass())->process($container);
33+
34+
$this->assertSame([], $container->getDefinition('foo')->getInstanceofConditionals());
35+
}
36+
}

0 commit comments

Comments
 (0)
0