14
14
use Symfony \Component \DependencyInjection \Alias ;
15
15
use Symfony \Component \DependencyInjection \Argument \ServiceClosureArgument ;
16
16
use Symfony \Component \DependencyInjection \Argument \ServiceLocatorArgument ;
17
+ use Symfony \Component \DependencyInjection \Argument \TaggedIteratorArgument ;
17
18
use Symfony \Component \DependencyInjection \ContainerBuilder ;
18
19
use Symfony \Component \DependencyInjection \Definition ;
19
20
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
@@ -47,14 +48,19 @@ protected function processValue($value, bool $isRoot = false)
47
48
$ value ->setClass (ServiceLocator::class);
48
49
}
49
50
50
- $ arguments = $ value ->getArguments ();
51
- if (!isset ($ arguments [0 ]) || !\is_array ($ arguments [0 ])) {
51
+ $ services = $ value ->getArguments ()[0 ] ?? null ;
52
+
53
+ if ($ services instanceof TaggedIteratorArgument) {
54
+ $ services = $ this ->findAndSortTaggedServices ($ services , $ this ->container );
55
+ }
56
+
57
+ if (!\is_array ($ services )) {
52
58
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 ));
53
59
}
54
60
55
61
$ i = 0 ;
56
62
57
- foreach ($ arguments [ 0 ] as $ k => $ v ) {
63
+ foreach ($ services as $ k => $ v ) {
58
64
if ($ v instanceof ServiceClosureArgument) {
59
65
continue ;
60
66
}
@@ -63,18 +69,18 @@ protected function processValue($value, bool $isRoot = false)
63
69
}
64
70
65
71
if ($ i === $ k ) {
66
- unset($ arguments [ 0 ] [$ k ]);
72
+ unset($ services [$ k ]);
67
73
68
74
$ k = (string ) $ v ;
69
75
++$ i ;
70
76
} elseif (\is_int ($ k )) {
71
77
$ i = null ;
72
78
}
73
- $ arguments [ 0 ] [$ k ] = new ServiceClosureArgument ($ v );
79
+ $ services [$ k ] = new ServiceClosureArgument ($ v );
74
80
}
75
- ksort ($ arguments [ 0 ] );
81
+ ksort ($ services );
76
82
77
- $ value ->setArguments ( $ arguments );
83
+ $ value ->setArgument ( 0 , $ services );
78
84
79
85
$ id = '.service_locator. ' .ContainerBuilder::hash ($ value );
80
86
0 commit comments