[DI] Dont cache classes with missing parents
This commit is contained in:
parent
9151698d85
commit
1606430cfd
@ -155,7 +155,7 @@ class ClassExistenceResource implements SelfCheckingResourceInterface, \Serializ
|
|||||||
throw $previous;
|
throw $previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
$e = new \ReflectionException("Class $class not found", 0, $previous);
|
$e = new \ReflectionException(sprintf('Class "%s" not found while loading "%s".', $class, self::$autoloadedClass), 0, $previous);
|
||||||
|
|
||||||
if (null !== $previous) {
|
if (null !== $previous) {
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -84,7 +84,7 @@ EOF
|
|||||||
public function testBadParentWithNoTimestamp()
|
public function testBadParentWithNoTimestamp()
|
||||||
{
|
{
|
||||||
$this->expectException('ReflectionException');
|
$this->expectException('ReflectionException');
|
||||||
$this->expectExceptionMessage('Class Symfony\Component\Config\Tests\Fixtures\MissingParent not found');
|
$this->expectExceptionMessage('Class "Symfony\Component\Config\Tests\Fixtures\MissingParent" not found while loading "Symfony\Component\Config\Tests\Fixtures\BadParent".');
|
||||||
|
|
||||||
$res = new ClassExistenceResource(BadParent::class, false);
|
$res = new ClassExistenceResource(BadParent::class, false);
|
||||||
$res->isFresh(0);
|
$res->isFresh(0);
|
||||||
|
@ -361,7 +361,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = null;
|
$resource = $classReflector = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isset($this->classReflectors[$class])) {
|
if (isset($this->classReflectors[$class])) {
|
||||||
@ -376,7 +376,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
if ($throw) {
|
if ($throw) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
$classReflector = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->trackResources) {
|
if ($this->trackResources) {
|
||||||
|
@ -149,12 +149,7 @@ abstract class FileLoader extends BaseFileLoader
|
|||||||
try {
|
try {
|
||||||
$r = $this->container->getReflectionClass($class);
|
$r = $this->container->getReflectionClass($class);
|
||||||
} catch (\ReflectionException $e) {
|
} catch (\ReflectionException $e) {
|
||||||
$classes[$class] = sprintf(
|
$classes[$class] = $e->getMessage();
|
||||||
'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".',
|
|
||||||
$namespace,
|
|
||||||
$class,
|
|
||||||
$e->getMessage()
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// check to make sure the expected class exists
|
// check to make sure the expected class exists
|
||||||
|
@ -380,7 +380,7 @@ class AutowirePassTest extends TestCase
|
|||||||
public function testParentClassNotFoundThrowsException()
|
public function testParentClassNotFoundThrowsException()
|
||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
|
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
|
||||||
$this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).');
|
$this->expectExceptionMessageRegExp('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}');
|
||||||
|
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ class FileLoaderTest extends TestCase
|
|||||||
|
|
||||||
$this->assertTrue($container->has(MissingParent::class));
|
$this->assertTrue($container->has(MissingParent::class));
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertRegExp(
|
||||||
['While discovering services from namespace "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\", an error was thrown when processing the class "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent": "Class Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingClass not found".'],
|
'{Class "?Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Fixtures\\\\Prototype\\\\BadClasses\\\\MissingClass"? not found}',
|
||||||
$container->getDefinition(MissingParent::class)->getErrors()
|
$container->getDefinition(MissingParent::class)->getErrors()[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user