@@ -64,7 +64,27 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
64
64
throw new InvalidArgumentException (\sprintf ('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set. ' , $ this ->currentId ));
65
65
}
66
66
67
- $ value ->setArgument (0 , self ::map ($ services ));
67
+ $ i = 0 ;
68
+
69
+ foreach ($ services as $ k => $ v ) {
70
+ if ($ v instanceof ServiceClosureArgument) {
71
+ continue ;
72
+ }
73
+
74
+ if ($ i === $ k ) {
75
+ if ($ v instanceof Reference) {
76
+ unset($ services [$ k ]);
77
+ $ k = (string ) $ v ;
78
+ }
79
+ ++$ i ;
80
+ } elseif (\is_int ($ k )) {
81
+ $ i = null ;
82
+ }
83
+
84
+ $ services [$ k ] = new ServiceClosureArgument ($ v );
85
+ }
86
+
87
+ $ value ->setArgument (0 , $ services );
68
88
69
89
$ id = '.service_locator. ' .ContainerBuilder::hash ($ value );
70
90
@@ -83,8 +103,12 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
83
103
84
104
public static function register (ContainerBuilder $ container , array $ map , ?string $ callerId = null ): Reference
85
105
{
106
+ foreach ($ map as $ k => $ v ) {
107
+ $ map [$ k ] = new ServiceClosureArgument ($ v );
108
+ }
109
+
86
110
$ locator = (new Definition (ServiceLocator::class))
87
- ->addArgument (self :: map ( $ map) )
111
+ ->addArgument ($ map )
88
112
->addTag ('container.service_locator ' );
89
113
90
114
if (null !== $ callerId && $ container ->hasDefinition ($ callerId )) {
@@ -109,29 +133,4 @@ public static function register(ContainerBuilder $container, array $map, ?string
109
133
110
134
return new Reference ($ id );
111
135
}
112
-
113
- public static function map (array $ services ): array
114
- {
115
- $ i = 0 ;
116
-
117
- foreach ($ services as $ k => $ v ) {
118
- if ($ v instanceof ServiceClosureArgument) {
119
- continue ;
120
- }
121
-
122
- if ($ i === $ k ) {
123
- if ($ v instanceof Reference) {
124
- unset($ services [$ k ]);
125
- $ k = (string ) $ v ;
126
- }
127
- ++$ i ;
128
- } elseif (\is_int ($ k )) {
129
- $ i = null ;
130
- }
131
-
132
- $ services [$ k ] = new ServiceClosureArgument ($ v );
133
- }
134
-
135
- return $ services ;
136
- }
137
136
}
0 commit comments