@@ -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 ())) {
@@ -396,7 +394,8 @@ private function createAutowiredDefinition($type)
396
394
}
397
395
398
396
$ currentId = $ this ->currentId ;
399
- $ this ->currentId = $ this ->autowired [$ type ] = $ argumentId = sprintf ('autowired.%s ' , $ type );
397
+ $ this ->currentId = $ type ;
398
+ $ this ->autowired [$ type ] = $ argumentId = sprintf ('autowired.%s ' , $ type );
400
399
$ argumentDefinition = new Definition ($ type );
401
400
$ argumentDefinition ->setPublic (false );
402
401
$ argumentDefinition ->setAutowired (true );
@@ -406,7 +405,8 @@ private function createAutowiredDefinition($type)
406
405
$ this ->container ->setDefinition ($ argumentId , $ argumentDefinition );
407
406
} catch (RuntimeException $ e ) {
408
407
$ this ->autowired [$ type ] = false ;
409
- $ this ->container ->log ($ this , $ e ->getMessage ());
408
+ $ this ->lastFailure = $ e ->getMessage ();
409
+ $ this ->container ->log ($ this , $ this ->lastFailure );
410
410
411
411
return ;
412
412
} finally {
@@ -427,7 +427,14 @@ private function createTypeNotFoundMessage($type, $label)
427
427
$ message = sprintf ('references %s "%s" but %s.%s ' , $ r ->isInterface () ? 'interface ' : 'class ' , $ type , $ message , $ this ->createTypeAlternatives ($ type ));
428
428
}
429
429
67E6
code>
430
- return sprintf ('Cannot autowire service "%s": %s %s ' , $ this ->currentId , $ label , $ message );
430
+ $ message = sprintf ('Cannot autowire service "%s": %s %s ' , $ this ->currentId , $ label , $ message );
431
+
432
+ if (null !== $ this ->lastFailure ) {
433
+ $ message = $ this ->lastFailure ."\n" .$ message ;
434
+ $ this ->lastFailure = null ;
435
+ }
436
+
437
+ return $ message ;
431
438
}
432
439
433
440
private function createTypeAlternatives ($ type )
0 commit comments