@@ -30,6 +30,7 @@ class AutowirePass extends AbstractRecursivePass
30
30
private $ types ;
31
31
private $ ambiguousServiceTypes = array ();
32
32
private $ autowired = array ();
33
+ private $ lastFailure ;
33
34
34
35
/**
35
36
* {@inheritdoc}
@@ -77,21 +78,19 @@ protected function processValue($value, $isRoot = false)
77
78
{
78
79
if ($ value instanceof TypedReference) {
79
80
if ($ ref = $ this ->getAutowiredReference ($ value )) {
80
- $ value = $ ref ;
81
- } else {
82
- $ this ->container ->log ($ this , $ this ->createTypeNotFoundMessage ($ value ->getType (), 'typed reference ' ));
81
+ return $ ref ;
83
82
}
83
+ $ this ->container ->log ($ this , $ this ->createTypeNotFoundMessage ($ value ->getType (), 'it ' ));
84
84
}
85
- if (!$ value instanceof Definition) {
86
- return parent ::processValue ($ value , $ isRoot );
87
- }
88
- if (!$ value ->isAutowired () || $ value ->isAbstract () || !$ value ->getClass ()) {
89
- return parent ::processValue ($ value , $ isRoot );
85
+ $ value = parent ::processValue ($ value , $ isRoot );
86
+
87
+ if (!$ value instanceof Definition || !$ value ->isAutowired () || $ value ->isAbstract () || !$ value ->getClass ()) {
88
+ return $ value ;
90
89
}
91
90
if (!$ reflectionClass = $ this ->container ->getReflectionClass ($ value ->getClass ())) {
92
91
$ this ->container ->log ($ this , sprintf ('Skipping service "%s": Class or interface "%s" does not exist. ' , $ this ->currentId , $ value ->getClass ()));
93
92
94
- return parent :: processValue ( $ value, $ isRoot ) ;
93
+ return $ value ;
95
94
}
96
95
97
96
$ autowiredMethods = $ this ->getMethodsToAutowire ($ reflectionClass );
@@ -115,7 +114,7 @@ protected function processValue($value, $isRoot = false)
115
114
$ value ->setMethodCalls ($ methodCalls );
116
115
}
117
116
118
- return parent :: processValue ( $ value, $ isRoot ) ;
117
+ return $ value ;
119
118
}
120
119
121
120
/**
@@ -246,9 +245,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
246
245
247
246
if ($ parameter ->isDefaultValueAvailable ()) {
248
247
$ value = $ parameter ->getDefaultValue ();
249
- } elseif ($ parameter ->allowsNull ()) {
250
- $ value = null ;
251
- } else {
248
+ } elseif (!$ parameter ->allowsNull ()) {
252
249
throw new RuntimeException ($ failureMessage );
253
250
}
254
251
$ this ->container ->log ($ this , $ failureMessage );
@@ -279,6 +276,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
279
276
*/
280
277
private function getAutowiredReference (TypedReference $ reference )
281
278
{
279
+ $ this ->lastFailure = null ;
282
280
$ type = $ reference ->getType ();
283
281
284
282
if ($ type !== (string ) $ reference || ($ this ->container ->has ($ type ) && !$ this ->container ->findDefinition ($ type )->isAbstract ())) {
@@ -406,6 +404,7 @@ private function createAutowiredDefinition($type)
406
404
$ this ->container ->setDefinition ($ argumentId , $ argumentDefinition );
407
405
} catch (RuntimeException $ e ) {
408
406
$ this ->autowired [$ type ] = false ;
407
+ $ this ->lastFailure = ' - ' .$ e ->getMessage ();
409
408
$ this ->container ->log ($ this , $ e ->getMessage ());
410
409
411
410
return ;
@@ -427,7 +426,14 @@ private function createTypeNotFoundMessage($type, $label)
427
426
$ message = sprintf ('references %s "%s" but %s.%s ' , $ r ->isInterface () ? 'interface ' : 'class ' , $ type , $ message , $ this ->createTypeAlternatives ($ type ));
428
427
}
429
428
430
- return sprintf ('Cannot autowire service "%s": %s %s ' , $ this ->currentId , $ label , $ message );
429
+ $ message = sprintf ('Cannot autowire service "%s": %s %s ' , $ this ->currentId , $ label , $ message );
430
+
431
+ if (null !== $ this ->lastFailure ) {
432
+ $ message = $ this ->lastFailure ."\n - " .$ message ;
433
+ $ this ->lastFailure = null ;
434
+ }
435
+
436
+ return $ message ;
431
437
}
432
438
433
439
private function createTypeAlternatives ($ type )
0 commit comments