Skip to content
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

[DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist #25160

Closed
wants to merge 5 commits into from

Conversation

@dunglas
Copy link
Member

commented Nov 26, 2017

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR n/a

Currently, if you just run the following commands:

composer create-project -s beta symfony/skeleton:^3.4 test
composer req orm

You get the following error:

In UniqueEntityValidator.php line 27:
                                                                   
  [ReflectionException]                                            
  Class Symfony\Component\Validator\ConstraintValidator not found  

UniqueEntityValidator is in the bridge, but it's parent class is in the validator (that is not installed by default). The hot path optimization feature (enabled by default) uses reflection, and the reflection API throws an exception in this specific case.

This PR fixes the error.

@@ -378,7 +378,11 @@ private function collectLineage($class, array &$lineage)
if (isset($lineage[$class])) {
return;
}
if (!$r = $this->container->getReflectionClass($class)) {
try {
if (!$r = $this->container->getReflectionClass($class)) {

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Nov 26, 2017

Member

or pass "false" as second argument?

This comment has been minimized.

Copy link
@dunglas

dunglas Nov 26, 2017

Author Member

Better :), done

@dunglas dunglas force-pushed the dunglas:reflexception branch from 2ff4ae9 to 9d1fdf1 Nov 26, 2017

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
/**
* @author Kévin Dunglas <dunglas@gmail.com>

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Nov 26, 2017

Member

not sure we need the license + docblock on fixtures ;)

@nicolas-grekas nicolas-grekas changed the title [DI] Prevent a ReflectionException during cache:clear when the parent… [DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist Nov 26, 2017

$container = new ContainerBuilder();
$container->register(HotPath\C1::class)->addTag('container.hot_path')->setPublic(true);
$container->register(HotPath\C2::class)->addArgument(new Reference(HotPath\C3::class))->setPublic(true);
$container->register(HotPath\C3::class);
$container->register(ParentNotExists::class);

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Nov 26, 2017

Member

the service should be public, so that the test is still valid on 4.0

@@ -98,6 +101,16 @@ protected function getC2Service()
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(${($_ = isset($this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3']) ? $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] : $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3()) && false ?: '_'});
}
/**
* Gets the private 'Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists' shared service.

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Nov 27, 2017

Member

missing fixture update

@nicolas-grekas

This comment has been minimized.

Copy link
Member

commented Nov 27, 2017

Thank you @dunglas.

nicolas-grekas added a commit that referenced this pull request Nov 27, 2017
bug #25160 [DI] Prevent a ReflectionException during cache:clear when…
… the parent class doesn't exist (dunglas)

This PR was squashed before being merged into the 3.4 branch (closes #25160).

Discussion
----------

[DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  |  no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Currently, if you just run the following commands:

```
composer create-project -s beta symfony/skeleton:^3.4 test
composer req orm
```

You get the following error:

```
In UniqueEntityValidator.php line 27:

  [ReflectionException]
  Class Symfony\Component\Validator\ConstraintValidator not found
```

`UniqueEntityValidator` is in the bridge, but it's parent class is in the validator (that is not installed by default). The hot path optimization feature (enabled by default) uses reflection, and the reflection API throws an exception in this specific case.

This PR fixes the error.

Commits
-------

6e622c6 [DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist
This was referenced Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.