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

@dunglas dunglas 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)) {
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or pass "false" as second argument?

Loading

Copy link
Member Author

@dunglas dunglas Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better :), done

Loading

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Loading

@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);
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Loading

@@ -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.
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing fixture update

Loading

@nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Nov 27, 2017

Thank you @dunglas.

Loading

nicolas-grekas added a commit that referenced this issue Nov 27, 2017
… 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
@fabpot fabpot mentioned this pull request Nov 30, 2017
@fabpot fabpot mentioned this pull request Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants