@@ -64,15 +64,16 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
6464 $ definition = $ container ->getDefinition ($ serviceId );
6565 $ class = $ definition ->getClass ();
6666 $ class = $ container ->getParameterBag ()->resolveValue ($ class ) ?: null ;
67+ $ reflector = null !== $ class ? $ container ->getReflectionClass ($ class ) : null ;
6768 $ checkTaggedItem = !$ definition ->hasTag ($ definition ->isAutoconfigured () ? 'container.ignore_attributes ' : $ tagName );
6869
6970 foreach ($ attributes as $ attribute ) {
7071 $ index = $ priority = null ;
7172
7273 if (isset ($ attribute ['priority ' ])) {
7374 $ priority = $ attribute ['priority ' ];
74- } elseif (null === $ defaultPriority && $ defaultPriorityMethod && $ class ) {
75- $ defaultPriority = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultPriorityMethod , $ tagName , 'priority ' , $ checkTaggedItem );
75+ } elseif (null === $ defaultPriority && $ defaultPriorityMethod && $ reflector ) {
76+ $ defaultPriority = PriorityTaggedServiceUtil::getDefault ($ serviceId , $ reflector , $ defaultPriorityMethod , $ tagName , 'priority ' , $ checkTaggedItem );
7677 }
7778 $ priority ??= $ defaultPriority ??= 0 ;
7879
@@ -84,17 +85,17 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
8485 if (null !== $ indexAttribute && isset ($ attribute [$ indexAttribute ])) {
8586 $ index = $ parameterBag ->resolveValue ($ attribute [$ indexAttribute ]);
8687 }
87- if (null === $ index && null === $ defaultIndex && $ defaultPriorityMethod && $ class ) {
88- $ defaultIndex = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultIndexMethod ?? 'getDefaultName ' , $ tagName , $ indexAttribute , $ checkTaggedItem );
88+ if (null === $ index && null === $ defaultIndex && $ defaultPriorityMethod && $ reflector ) {
89+ $ defaultIndex = PriorityTaggedServiceUtil::getDefault ($ serviceId , $ reflector , $ defaultIndexMethod ?? 'getDefaultName ' , $ tagName , $ indexAttribute , $ checkTaggedItem );
8990 }
9091 $ decorated = $ definition ->getTag ('container.decorator ' )[0 ]['id ' ] ?? null ;
9192 $ index = $ index ?? $ defaultIndex ?? $ defaultIndex = $ decorated ?? $ serviceId ;
9293
9394 $ services [] = [$ priority , ++$ i , $ index , $ serviceId , $ class ];
9495 }
9596
96- if ($ class ) {
97- $ attributes = ( new \ ReflectionClass ( $ class )) ->getAttributes (AsTaggedItem::class);
97+ if ($ reflector ) {
98+ $ attributes = $ reflector ->getAttributes (AsTaggedItem::class);
9899 $ attributeCount = \count ($ attributes );
99100
100101 foreach ($ attributes as $ attribute ) {
@@ -137,9 +138,11 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
137138 */
138139class PriorityTaggedServiceUtil
139140{
140- public static function getDefault (ContainerBuilder $ container , string $ serviceId , string $ class , string $ defaultMethod , string $ tagName , ?string $ indexAttribute , bool $ checkTaggedItem ): string |int |null
141+ public static function getDefault (string $ serviceId , \ ReflectionClass $ r , string $ defaultMethod , string $ tagName , ?string $ indexAttribute , bool $ checkTaggedItem ): string |int |null
141142 {
142- if (!($ r = $ container ->getReflectionClass ($ class )) || (!$ checkTaggedItem && !$ r ->hasMethod ($ defaultMethod ))) {
143+ $ class = $ r ->getName ();
144+
145+ if (!$ checkTaggedItem && !$ r ->hasMethod ($ defaultMethod )) {
143146 return null ;
144147 }
145148
0 commit comments