Skip to content

[DependencyInjection] fix parsing classes for attributes #41673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function process(ContainerBuilder $container)
}

foreach ($container->getDefinitions() as $id => $definition) {
if ($this->accept($definition) && null !== $class = $container->getReflectionClass($definition->getClass())) {
if ($this->accept($definition) && $class = $container->getReflectionClass($definition->getClass(), false)) {
$this->processClass($container, $class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
$serializedPrototype = serialize($prototype);

foreach ($classes as $class => $errorMessage) {
if ($autoconfigureAttributes && $this->env) {
if (null === $errorMessage && $autoconfigureAttributes && $this->env) {
$r = $this->container->getReflectionClass($class);
$attribute = null;
foreach ($r->getAttributes(When::class) as $attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfigureAttributed;
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfiguredInterface;
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;

/**
* @requires PHP 8
Expand Down Expand Up @@ -78,4 +79,16 @@ public function testAutoconfiguredTag()
;
$this->assertEquals([AutoconfiguredInterface::class => $expected], $container->getAutoconfiguredInstanceof());
}

public function testMissingParent()
{
$container = new ContainerBuilder();

$definition = $container->register(ParentNotExists::class, ParentNotExists::class)
->setAutoconfigured(true);

(new RegisterAutoconfigureAttributesPass())->process($container);

$this->addToAssertionCount(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ public function testMissingParentClass()
{
$container = new ContainerBuilder();
$container->setParameter('bad_classes_dir', 'BadClasses');
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'), 'test');

$loader->registerClasses(
(new Definition())->setPublic(false),
(new Definition())->setAutoconfigured(true),
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
'Prototype/%bad_classes_dir%/*'
);
Expand Down