-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist #25160
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
Conversation
@@ -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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better :), done
… class doesn't exist
2ff4ae9
to
9d1fdf1
Compare
namespace Symfony\Component\DependencyInjection\Tests\Fixtures; | ||
|
||
/** | ||
* @author Kévin Dunglas <dunglas@gmail.com> |
There was a problem hiding this comment.
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 ;)
|
||
$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); |
There was a problem hiding this comment.
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
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing fixture update
Thank you @dunglas. |
… 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
Currently, if you just run the following commands:
You get the following error:
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.