@@ -30,7 +30,7 @@ class AutowirePass extends AbstractRecursivePass
30
30
{
31
31
private $ definedTypes = array ();
32
32
private $ types ;
33
- private $ ambiguousServiceTypes = array () ;
33
+ private $ ambiguousServiceTypes ;
34
34
private $ autowired = array ();
35
35
private $ lastFailure ;
36
36
private $ throwOnAutowiringException ;
@@ -71,7 +71,7 @@ public function process(ContainerBuilder $container)
71
71
} finally {
72
72
$ this ->definedTypes = array ();
73
73
$ this ->types = null ;
74
- $ this ->ambiguousServiceTypes = array () ;
74
+ $ this ->ambiguousServiceTypes = null ;
75
75
$ this ->autowired = array ();
76
76
}
77
77
}
@@ -286,7 +286,7 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
286
286
}
287
287
288
288
if (null === $ this ->types ) {
289
- $ this ->populateAvailableTypes ();
289
+ $ this ->populateAvailableTypes ($ this -> strictMode );
290
290
}
291
291
292
292
if (isset ($ this ->definedTypes [$ type ])) {
@@ -322,12 +322,15 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
322
322
/**
323
323
* Populates the list of available types.
324
324
*/
325
- private function populateAvailableTypes ()
325
+ private function populateAvailableTypes ($ onlyAutowiringTypes = false )
326
326
{
327
327
$ this ->types = array ();
328
+ if (!$ onlyAutowiringTypes ) {
329
+ $ this ->ambiguousServiceTypes = array ();
330
+ }
328
331
329
332
foreach ($ this ->container ->getDefinitions () as $ id => $ definition ) {
330
- $ this ->populateAvailableType ($ id , $ definition );
333
+ $ this ->populateAvailableType ($ id , $ definition, $ onlyAutowiringTypes );
331
334
}
332
335
}
333
336
@@ -337,7 +340,7 @@ private function populateAvailableTypes()
337
340
* @param string $id
338
341
* @param Definition $definition
339
342
*/
340
- private function populateAvailableType ($ id , Definition $ definition )
343
+ private function populateAvailableType ($ id , Definition $ definition, $ onlyAutowiringTypes )
341
344
{
342
345
// Never use abstract services
343
346
if ($ definition ->isAbstract ()) {
@@ -350,6 +353,10 @@ private function populateAvailableType($id, Definition $definition)
350
353
unset($ this ->ambiguousServiceTypes [$ type ]);
351
354
}
352
355
356
+ if ($ onlyAutowiringTypes ) {
357
+ return ;
358
+ }
359
+
353
360
if (preg_match ('/^\d+_[^~]++~[._a-zA-Z\d]{7}$/ ' , $ id ) || $ definition ->isDeprecated () || !$ reflectionClass = $ this ->container ->getReflectionClass ($ definition ->getClass (), false )) {
354
361
return ;
355
362
}
@@ -479,12 +486,15 @@ private function createTypeAlternatives(TypedReference $reference)
479
486
if ($ message = $ this ->getAliasesSuggestionForType ($ type = $ reference ->getType ())) {
480
487
return ' ' .$ message ;
481
488
}
489
+ if (null === $ this ->ambiguousServiceTypes ) {
490
+ $ this ->populateAvailableTypes ();
491
+ }
482
492
483
493
if (isset ($ this ->ambiguousServiceTypes [$ type ])) {
484
494
$ message = sprintf ('one of these existing services: "%s" ' , implode ('", " ' , $ this ->ambiguousServiceTypes [$ type ]));
485
495
} elseif (isset ($ this ->types [$ type ])) {
486
496
$ message = sprintf ('the existing "%s" service ' , $ this ->types [$ type ]);
487
- } elseif ($ reference ->getRequiringClass () && !$ reference ->canBeAutoregistered ()) {
497
+ } elseif ($ reference ->getRequiringClass () && !$ reference ->canBeAutoregistered () && ! $ this -> strictMode ) {
488
498
return ' It cannot be auto-registered because it is from a different root namespace. ' ;
489
499
} else {
490
500
return ;
0 commit comments