@@ -64,15 +64,16 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
64
64
$ definition = $ container ->getDefinition ($ serviceId );
65
65
$ class = $ definition ->getClass ();
66
66
$ class = $ container ->getParameterBag ()->resolveValue ($ class ) ?: null ;
67
+ $ reflector = null !== $ class ? $ container ->getReflectionClass ($ class ) : null ;
67
68
$ checkTaggedItem = !$ definition ->hasTag ($ definition ->isAutoconfigured () ? 'container.ignore_attributes ' : $ tagName );
68
69
69
70
foreach ($ attributes as $ attribute ) {
70
71
$ index = $ priority = null ;
71
72
72
73
if (isset ($ attribute ['priority ' ])) {
73
74
$ 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 );
76
77
}
77
78
$ priority ??= $ defaultPriority ??= 0 ;
78
79
@@ -84,17 +85,17 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
84
85
if (null !== $ indexAttribute && isset ($ attribute [$ indexAttribute ])) {
85
86
$ index = $ parameterBag ->resolveValue ($ attribute [$ indexAttribute ]);
86
87
}
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 );
89
90
}
90
91
$ decorated = $ definition ->getTag ('container.decorator ' )[0 ]['id ' ] ?? null ;
91
92
$ index = $ index ?? $ defaultIndex ?? $ defaultIndex = $ decorated ?? $ serviceId ;
92
93
93
94
$ services [] = [$ priority , ++$ i , $ index , $ serviceId , $ class ];
94
95
}
95
96
96
- if ($ class ) {
97
- $ attributes = ( new \ ReflectionClass ( $ class )) ->getAttributes (AsTaggedItem::class);
97
+ if ($ reflector ) {
98
+ $ attributes = $ reflector ->getAttributes (AsTaggedItem::class);
98
99
$ attributeCount = \count ($ attributes );
99
100
100
101
foreach ($ attributes as $ attribute ) {
@@ -137,9 +138,11 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
137
138
*/
138
139
class PriorityTaggedServiceUtil
139
140
{
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
141
142
{
142
- if (!($ r = $ container ->getReflectionClass ($ class )) || (!$ checkTaggedItem && !$ r ->hasMethod ($ defaultMethod ))) {
143
+ $ class = $ r ->getName ();
144
+
145
+ if (!$ checkTaggedItem && !$ r ->hasMethod ($ defaultMethod )) {
143
146
return null ;
144
147
}
145
148
0 commit comments