Skip to content

Commit 6e622c6

Browse files
dunglasnicolas-grekas
authored andcommitted
[DI] Prevent a ReflectionException during cache:clear when the parent class doesn't exist
1 parent 1d7d564 commit 6e622c6

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private function collectLineage($class, array &$lineage)
378378
if (isset($lineage[$class])) {
379379
return;
380380
}
381-
if (!$r = $this->container->getReflectionClass($class)) {
381+
if (!$r = $this->container->getReflectionClass($class, false)) {
382382
return;
383383
}
384384
if ($this->container instanceof $class) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures;
4+
5+
class ParentNotExists extends \NotExists
6+
{
7+
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_inline_requires.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
88
use Symfony\Component\DependencyInjection\Reference;
99
use Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath;
10+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
1011

1112
$container = new ContainerBuilder();
1213

1314
$container->register(HotPath\C1::class)->addTag('container.hot_path')->setPublic(true);
1415
$container->register(HotPath\C2::class)->addArgument(new Reference(HotPath\C3::class))->setPublic(true);
1516
$container->register(HotPath\C3::class);
17+
$container->register(ParentNotExists::class)->setPublic(true);
1618

1719
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/container_inline_requires.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public function __construct()
3232
'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c1' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1',
3333
'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c2' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2',
3434
'symfony\\component\\dependencyinjection\\tests\\fixtures\\includes\\hotpath\\c3' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3',
35+
'symfony\\component\\dependencyinjection\\tests\\fixtures\\parentnotexists' => 'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists',
3536
);
3637
$this->methodMap = array(
38+
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\ParentNotExists' => 'getParentNotExistsService',
3739
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C1' => 'getC1Service',
3840
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C2' => 'getC2Service',
3941
'Symfony\\Component\\DependencyInjection\\Tests\\Fixtures\\includes\\HotPath\\C3' => 'getC3Service',
@@ -75,6 +77,16 @@ public function isFrozen()
7577
return true;
7678
}
7779

80+
/**
81+
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists' shared service.
82+
*
83+
* @return \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists
84+
*/
85+
protected function getParentNotExistsService()
86+
{
87+
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists();
88+
}
89+
7890
/**
7991
* Gets the public 'Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C1' shared service.
8092
*

0 commit comments

Comments
 (0)