8000 bug #41673 [DependencyInjection] fix parsing classes for attributes (… · symfony/symfony@d583b4f · GitHub
[go: up one dir, main page]

Skip to content

Commit d583b4f

Browse files
bug #41673 [DependencyInjection] fix parsing classes for attributes (nicolas-grekas)
This PR was merged into the 5.3 branch. Discussion ---------- [DependencyInjection] fix parsing classes for attributes | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #41548 | License | MIT | Doc PR | - Commits ------- 6ccc344 [DependencyInjection] fix parsing classes for attributes
2 parents 63ab962 + 6ccc344 commit d583b4f

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function process(ContainerBuilder $container)
3636
}
3737

3838
foreach ($container->getDefinitions() as $id => $definition) {
39-
if ($this->accept($definition) && null !== $class = $container->getReflectionClass($definition->getClass())) {
39+
if ($this->accept($definition) && $class = $container->getReflectionClass($definition->getClass(), false)) {
4040
$this->processClass($container, $class);
4141
}
4242
}

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
105105
$serializedPrototype = serialize($prototype);
106106

107107
foreach ($classes as $class => $errorMessage) {
108-
if ($autoconfigureAttributes && $this->env) {
108+
if (null === $errorMessage && $autoconfigureAttributes && $this->env) {
109109
$r = $this->container->getReflectionClass($class);
110110
$attribute = null;
111111
foreach ($r->getAttributes(When::class) as $attribute) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfigureAttributed;
2121
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfiguredInterface;
22+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
2223

2324
/**
2425
* @requires PHP 8
@@ -78,4 +79,16 @@ public function testAutoconfiguredTag()
7879
;
7980
$this->assertEquals([AutoconfiguredInterface::class => $expected], $container->getAutoconfiguredInstanceof());
8081
}
82+
83+
public function testMissingParent()
84+
{
85+
$container = new ContainerBuilder();
86+
87+
$definition = $container->register(ParentNotExists::class, ParentNotExists::class)
88+
->setAutoconfigured(true);
89+
90+
(new RegisterAutoconfigureAttributesPass())->process($container);
91+
92+
$this->addToAssertionCount(1);
93+
}
8194
}

src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ public function testMissingParentClass()
202202
{
203203
$container = new ContainerBuilder();
204204
$container->setParameter('bad_classes_dir', 'BadClasses');
205-
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
205+
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'), 'test');
206206

207207
$loader->registerClasses(
208-
(new Definition())->setPublic(false),
208+
(new Definition())->setAutoconfigured(true),
209209
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
210210
'Prototype/%bad_classes_dir%/*'
211211
);

0 commit comments

Comments
 (0)
0