Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1924f9

Browse files
[DI] Dont cache classes with missing parents
1 parent 9151698 commit e1924f9

File tree

6 files changed

+8
-14
lines changed

6 files changed

+8
-14
lines changed

src/Symfony/Component/Config/Resource/ClassExistenceResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function throwOnRequiredClass($class, \Exception $previous = null)
155155
throw $previous;
156156
}
157157

158-
$e = new \ReflectionException("Class $class not found", 0, $previous);
158+
$e = new \ReflectionException(sprintf('Class "%s" not found while loading "%s".', $class, self::$autoloadedClass), 0, $previous);
159159

160160
if (null !== $previous) {
161161
throw $e;

src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testBadParentWithTimestamp()
8484
public function testBadParentWithNoTimestamp()
8585
{
8686
$this->expectException('ReflectionException');
87-
$this->expectExceptionMessage('Class Symfony\Component\Config\Tests\Fixtures\MissingParent not found');
87+
$this->expectExceptionMessage('Class "Symfony\Component\Config\Tests\Fixtures\MissingParent" not found while loading "Symfony\Component\Config\Tests\Fixtures\BadParent".');
8888

8989
$res = new ClassExistenceResource(BadParent::class, false);
9090
$res->isFresh(0);

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ public function getReflectionClass($class, $throw = true)
361361
return null;
362362
}
363363

364-
$resource = null;
364+
$resource = $classReflector = null;
365365

366366
try {
367367
if (isset($this->classReflectors[$class])) {
@@ -376,7 +376,6 @@ public function getReflectionClass($class, $throw = true)
376376
if ($throw) {
377377
throw $e;
378378
}
379-
$classReflector = false;
380379
}
381380

382381
if ($this->trackResources) {

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,7 @@ private function findClasses($namespace, $pattern, $excludePattern)
149149
try {
150150
$r = $this->container->getReflectionClass($class);
151151
} catch (\ReflectionException $e) {
152-
$classes[$class] = sprintf(
153-
'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".',
154-
$namespace,
155-
$class,
156-
$e->getMessage()
157-
);
152+
$classes[$class] = sprintf('While discovering services from namespace "%s", an error was thrown when processing the class "%s": %s.', $namespace, $class, $e->getMessage());
158153
continue;
159154
}
160155
// check to make sure the expected class exists

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public function testClassNotFoundThrowsException()
380380
public function testParentClassNotFoundThrowsException()
381381
{
382382
$this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException');
383-
$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).');
383+
$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}');
384384

385385
$container = new ContainerBuilder();
386386

src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ public function testMissingParentClass()
178178

179179
$this->assertTrue($container->has(MissingParent::class));
180180

181-
$this->assertSame(
182-
['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".'],
183-
$container->getDefinition(MissingParent::class)->getErrors()
181+
$this->assertRegExp(
182+
'{^While discovering services from namespace "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Fixtures\\\\Prototype\\\\BadClasses\\\\)", an error was thrown when processing the class "\1MissingParent": "?Class "?\1MissingClass"? not found}',
183+
$container->getDefinition(MissingParent::class)->getErrors()[0]
184184
);
185185
}
186186

0 commit comments

Comments
 (0)