@@ -459,26 +459,26 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
459459 $ name = $ target = (array_filter ($ reference ->getAttributes (), static fn ($ a ) => $ a instanceof Target)[0 ] ?? null )?->name;
460460
461461 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 )) {
463463 return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
464464 }
465465
466- if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ name )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
466+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ name )) && $ this ->canDefinitionBeAutowired ($ alias )) {
467467 return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
468468 }
469469
470470 $ parsedName = (new Target ($ name ))->getParsedName ();
471471
472- if ($ this ->container ->has ($ alias = $ type .' $ ' .$ parsedName ) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
472+ if ($ this ->container ->has ($ alias = $ type .' $ ' .$ parsedName ) && $ this ->canDefinitionBeAutowired ($ alias )) {
473473 return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
474474 }
475475
476- if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ parsedName )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
476+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type , $ parsedName )) && $ this ->canDefinitionBeAutowired ($ alias )) {
477477 return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
478478 }
479479
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 ))
482482 ) {
483483 foreach ($ this ->container ->getAliases () as $ id => $ alias ) {
484484 if ($ n === (string ) $ alias && str_starts_with ($ id , $ type .' $ ' )) {
@@ -492,17 +492,24 @@ private function getAutowiredReference(TypedReference $reference, bool $filterTy
492492 }
493493 }
494494
495- if ($ this ->container ->has ($ type ) && ! $ this ->container -> findDefinition ($ type)-> isAbstract ( )) {
495+ if ($ this ->container ->has ($ type ) && $ this ->canDefinitionBeAutowired ($ type )) {
496496 return new TypedReference ($ type , $ type , $ reference ->getInvalidBehavior ());
497497 }
498498
499- if (null !== ($ alias = $ this ->getCombinedAlias ($ type )) && ! $ this ->container -> findDefinition ($ alias)-> isAbstract ( )) {
499+ if (null !== ($ alias = $ this ->getCombinedAlias ($ type )) && $ this ->canDefinitionBeAutowired ($ alias )) {
500500 return new TypedReference ($ alias , $ type , $ reference ->getInvalidBehavior ());
501501 }
502502
503503 return null ;
504504 }
505505
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+
506513 /**
507514 * Populates the list of available types.
508515 */
0 commit comments