@@ -58,15 +58,7 @@ protected function processValue($value, bool $isRoot = false)
58
58
if (isset ($ this ->serviceLocatorContextIds [$ currentId ])) {
59
59
$ currentId = $ this ->serviceLocatorContextIds [$ currentId ];
60
60
$ locator = $ this ->container ->getDefinition ($ this ->currentId )->getFactory ()[0 ];
61
-
62
- foreach ($ locator ->getArgument (0 ) as $ k => $ v ) {
63
- if ($ v ->getValues ()[0 ] === $ value ) {
64
- if ($ k !== $ id ) {
65
- $ currentId = $ k .'" in the container provided to " ' .$ currentId ;
66
- }
67
- throw new ServiceNotFoundException ($ id , $ currentId , null , $ this ->getAlternatives ($ id ));
68
- }
69
- }
61
+ $ this ->throwServiceNotFoundException ($ value , $ currentId , $ locator ->getArgument (0 ));
70
62
}
71
63
72
64
if ('. ' === $ currentId [0 ] && $ graph ->hasNode ($ currentId )) {
@@ -80,14 +72,21 @@ protected function processValue($value, bool $isRoot = false)
80
72
$ currentId = $ sourceId ;
81
73
break ;
82
74
}
75
+
76
+ if (isset ($ this ->serviceLocatorContextIds [$ sourceId ])) {
77
+ $ currentId = $ this ->serviceLocatorContextIds [$ sourceId ];
78
+ $ locator = $ this ->container ->getDefinition ($ this ->currentId );
79
+ $ this ->throwServiceNotFoundException ($ value , $ currentId , $ locator ->getArgument (0 ));
80
+ }
83
81
}
84
82
}
85
83
86
- throw new ServiceNotFoundException ( $ id , $ currentId , null , $ this -> getAlternatives ( $ id ) );
84
+ $ this -> throwServiceNotFoundException ( $ value , $ currentId , $ value );
87
85
}
88
86
89
- private function getAlternatives ( string $ id ): array
87
+ private function throwServiceNotFoundException ( Reference $ ref , string $ sourceId , mixed $ value ): void
90
88
{
89
+ $ id = (string ) $ ref ;
91
90
$ alternatives = [];
92
91
foreach ($ this ->container ->getServiceIds () as $ knownId ) {
93
92
if ('' === $ knownId || '. ' === $ knownId [0 ]) {
@@ -100,6 +99,28 @@ private function getAlternatives(string $id): array
100
99
}
101
100
}
102
101
103
- return $ alternatives ;
102
+ $ pass = new class ($ ref , $ sourceId , $ alternatives ) extends AbstractRecursivePass {
103
+ public $ ref ;
104
+ public $ sourceId ;
105
+ public $ alternatives ;
106
+
107
+ public function processValue (mixed $ value , bool $ isRoot = false ): mixed
108
+ {
109
+ if ($ this ->ref !== $ value ) {
110
+ return parent ::processValue ($ value , $ isRoot );
111
+ }
112
+ $ sourceId = $ this ->sourceId ;
113
+ if (null !== $ this ->currentId && $ this ->currentId !== (string ) $ value ) {
114
+ $ sourceId = $ this ->currentId .'" in the container provided to " ' .$ sourceId ;
115
+ }
116
+
117
+ throw new ServiceNotFoundException ((string ) $ value , $ sourceId , null , $ this ->alternatives );
118
+ }
119
+ };
120
+ $ pass ->ref = $ ref ;
121
+ $ pass ->sourceId = $ sourceId ;
122
+ $ pass ->alternatives = $ alternatives ;
123
+
124
+ $ pass ->processValue ($ value , true );
104
125
}
105
126
}
0 commit comments