@@ -459,26 +459,26 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
459
459
$ name = $ target = (array_filter ($ reference ->getAttributes (), static fn ($ a ) => $ a instanceof Target)[0 ] ?? null )?->name;
460
460
461
461
if (null !== $ name ??= $ reference ->getName ()) {
462
- if ($ this ->container ->has ($ alias = $ type .' $ ' .$ name ) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
462
+ if ($ this ->container ->has ($ alias = $ type .' $ ' .$ name ) && $ this ->canDefinitionBeAutowired ($ alias )) {
463
463
return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
464
464
}
465
465
466
- if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ name )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
466
+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ name )) && $ this ->canDefinitionBeAutowired ($ alias )) {
467
467
return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
468
468
}
469
469
470
470
$ parsedName = (new Target ($ name ))->getParsedName ();
471
471
472
- if ($ this ->container ->has ($ alias = $ type .' $ ' .$ parsedName ) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
472
+ if ($ this ->container ->has ($ alias = $ type .' $ ' .$ parsedName ) && $ this ->canDefinitionBeAutowired ($ alias )) {
473
473
return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
474
474
}
475
475
476
- if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ parsedName )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
476
+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ parsedName )) && $ this ->canDefinitionBeAutowired ($ alias )) {
477
477
return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
478
478
}
479
479
480
- if (($ this ->container ->has ($ n = $ name ) && ! $ this ->container -> findDefinition ($ n)-> isAbstract ( ))
481
- || ($ this ->container ->has ($ n = $ parsedName ) && ! $ this ->container -> findDefinition ($ n)-> isAbstract ( ))
480
+ if (($ this ->container ->has ($ n = $ name ) && $ this ->canDefinitionBeAutowired ($ n ))
481
+ || ($ this ->container ->has ($ n = $ parsedName ) && $ this ->canDefinitionBeAutowired ($ n ))
482
482
) {
483
483
foreach ($ this ->container ->getAliases () as $ id => $ alias ) {
484
484
if ($ n === (string ) $ alias && str_starts_with ($ id , $ type .' $ ' )) {
@@ -492,17 +492,24 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
492
492
}
493
493
}
494
494
495
- if ($ this ->container ->has ($ type ) && ! $ this ->container -> findDefinition ($ type)-> isAbstract ( )) {
495
+ if ($ this ->container ->has ($ type ) && $ this ->canDefinitionBeAutowired ($ type )) {
496
496
return new TypedReference ($ type , $ type , $ reference ->getInvalidBehavior ());
497
497
}
498
498
499
- if (null !== ($ alias = $ this ->getCombinedAlias ($ type )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
499
+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type )) && $ this ->canDefinitionBeAutowired ($ alias )) {
500
500
return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
501
501
}
502
502
503
503
return null ;
504
504
}
505
505
506
+ private function canDefinitionBeAutowired (string $ id ): bool
507
+ {
508
+ $ definition = $ this ->container ->findDefinition ($ id );
509
+
510
+ return !$ definition ->isAbstract () && !$ definition ->hasTag ('container.excluded ' );
511
+ }
512
+
506
513
/**
507
514
* Populates the list of available types.
508
515
*/
0 commit comments