@@ -62,25 +62,26 @@ private function findAndSortTaggedServices($tagName, ContainerBuilder $container
62
62
$ class = $ container ->getParameterBag ()->resolveValue ($ class ) ?: null ;
63
63
$ checkTaggedItem = !$ definition ->hasTag (80000 <= \PHP_VERSION_ID && $ definition ->isAutoconfigured () ? 'container.ignore_attributes ' : $ tagName );
64
64
65
+ if ($ class ) {
66
+ $ defaultPriority = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultPriorityMethod , $ tagName , 'priority ' , $ checkTaggedItem );
67
+ $ defaultIndex = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultIndexMethod ?? 'getDefaultName ' , $ tagName , $ indexAttribute , $ checkTaggedItem );
68
+ }
69
+
65
70
foreach ($ attributes as $ attribute ) {
66
71
$ index = $ priority = null ;
67
72
68
73
if (isset ($ attribute ['priority ' ])) {
69
74
$ priority = $ attribute ['priority ' ];
70
- } elseif (null === $ defaultPriority && $ defaultPriorityMethod && $ class ) {
71
- $ defaultPriority = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultPriorityMethod , $ tagName , 'priority ' , $ checkTaggedItem );
72
75
}
73
76
$ priority = $ priority ?? $ defaultPriority ?? $ defaultPriority = 0 ;
74
77
75
- if (null === $ indexAttribute && ! $ defaultIndexMethod && !$ needsIndexes ) {
76
- $ services [] = [$ priority , ++$ i , null , $ serviceId , null ];
78
+ if (null === $ indexAttribute && null === $ defaultIndex && !$ needsIndexes ) {
79
+ $ services [] = [$ priority , ++$ i , null , $ serviceId , $ class ];
77
80
continue 2 ;
78
81
}
79
82
80
83
if (null !== $ indexAttribute && isset ($ attribute [$ indexAttribute ])) {
81
84
$ index = $ attribute [$ indexAttribute ];
82
- } elseif (null === $ defaultIndex && $ defaultPriorityMethod && $ class ) {
83
- $ defaultIndex = PriorityTaggedServiceUtil::getDefault ($ container , $ serviceId , $ class , $ defaultIndexMethod ?? 'getDefaultName ' , $ tagName , $ indexAttribute , $ checkTaggedItem );
84
85
}
85
86
$ index = $ index ?? $ defaultIndex ?? $ defaultIndex = $ serviceId ;
86
87
@@ -119,13 +120,13 @@ class PriorityTaggedServiceUtil
119
120
/**
120
121
* @return string|int|null
121
122
*/
122
- public static function getDefault (ContainerBuilder $ container , string $ serviceId , string $ class , string $ defaultMethod , string $ tagName , ?string $ indexAttribute , bool $ checkTaggedItem )
123
+ public static function getDefault (ContainerBuilder $ container , string $ serviceId , string $ class , ? string $ defaultMethod , string $ tagName , ?string $ indexAttribute , bool $ checkTaggedItem )
123
124
{
124
125
if (!($ r = $ container ->getReflectionClass ($ class )) || (!$ checkTaggedItem && !$ r ->hasMethod ($ defaultMethod ))) {
125
126
return null ;
126
127
}
127
128
128
- if ($ checkTaggedItem && ! $ r ->hasMethod ($ defaultMethod )) {
129
+ if ($ checkTaggedItem && (! $ defaultMethod || ! $ r ->hasMethod ($ defaultMethod) )) {
129
130
foreach ($ r ->getAttributes (AsTaggedItem::class) as $ attribute ) {
130
131
return 'priority ' === $ indexAttribute ? $ attribute ->newInstance ()->priority : $ attribute ->newInstance ()->index ;
131
132
}
0 commit comments