Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 48832e6

Browse filesBrowse files
weaverryanfabpot
authored andcommitted
Tweaking class not found autowiring error
1 parent 50644d0 commit 48832e6
Copy full SHA for 48832e6

File tree

3 files changed

+16
-5
lines changed
Filter options

3 files changed

+16
-5
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\Config\Resource\ClassExistenceResource;
1415
use Symfony\Component\DependencyInjection\Config\AutowireServiceResource;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Definition;
@@ -485,7 +486,17 @@ private function createAutowiredDefinition($type)
485486
private function createTypeNotFoundMessage(TypedReference $reference, $label)
486487
{
487488
if (!$r = $this->container->getReflectionClass($type = $reference->getType(), false)) {
488-
$message = sprintf('has type "%s" but this class cannot be loaded.', $type);
489+
// either $type does not exist or a parent class does not exist
490+
try {
491+
$resource = new ClassExistenceResource($type, false);
492+
// isFresh() will explode ONLY if a parent class/trait does not exist
493+
$resource->isFresh(0);
494+
$parentMsg = false;
495+
} catch (\ReflectionException $e) {
496+
$parentMsg = $e->getMessage();
497+
}
498+
499+
$message = sprintf('has type "%s" but this class %s.', $type, $parentMsg ? sprintf('is missing a parent class (%s)', $parentMsg) : 'was not found');
489500
} else {
490501
$message = $this->container->has($type) ? 'this service is abstract' : 'no such service exists';
491502
$message = sprintf('references %s "%s" but %s.%s', $r->isInterface() ? 'interface' : 'class', $type, $message, $this->createTypeAlternatives($reference));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public function testDontTriggerAutowiring()
359359

360360
/**
361361
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
362-
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.
362+
* @expectedExceptionMessage Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.
363363
*/
364364
public function testClassNotFoundThrowsException()
365365
{
@@ -374,7 +374,7 @@ public function testClassNotFoundThrowsException()
374374

375375
/**
376376
* @expectedException \Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
377-
* @expectedExceptionMessage 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 cannot be loaded.
377+
* @expectedExceptionMessage 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).
378378
*/
379379
public function testParentClassNotFoundThrowsException()
380380
{
@@ -761,7 +761,7 @@ public function testNotWireableCalls($method, $expectedMsg)
761761
public function provideNotWireableCalls()
762762
{
763763
return array(
764-
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class cannot be loaded.'),
764+
array('setNotAutowireable', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setNotAutowireable()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\NotARealClass" but this class was not found.'),
765765
array('setDifferentNamespace', 'Cannot autowire service "foo": argument "$n" of method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setDifferentNamespace()" references class "stdClass" but no such service exists. It cannot be auto-registered because it is from a different root namespace.'),
766766
array(null, 'Cannot autowire service "foo": method "Symfony\Component\DependencyInjection\Tests\Compiler\NotWireable::setProtectedMethod()" must be public.'),
767767
);

‎src/Symfony/Component/DependencyInjection/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/proxy-manager-bridge": "Generate service proxies to lazy load them"
3333
},
3434
"conflict": {
35-
"symfony/config": "<3.3.1",
35+
"symfony/config": "<3.3.7",
3636
"symfony/finder": "<3.3",
3737
"symfony/yaml": "<3.3"
3838
},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.