@@ -25,9 +25,6 @@ class CheckExceptionOnInvalidReferenceBehaviorPass extends AbstractRecursivePass
25
25
{
26
26
private $ serviceLocatorContextIds = [];
27
27
28
- /**
29
- * {@inheritdoc}
30
- */
31
28
public function process (ContainerBuilder $ container )
32
29
{
33
30
$ this ->serviceLocatorContextIds = [];
@@ -58,15 +55,7 @@ protected function processValue($value, bool $isRoot = false)
58
55
if (isset ($ this ->serviceLocatorContextIds [$ currentId ])) {
59
56
$ currentId = $ this ->serviceLocatorContextIds [$ currentId ];
60
57
$ 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
- }
58
+ $ this ->throwServiceNotFoundException ($ value , $ currentId , $ locator ->getArgument (0 ));
70
59
}
71
60
72
61
if ('. ' === $ currentId [0 ] && $ graph ->hasNode ($ currentId )) {
@@ -80,14 +69,21 @@ protected function processValue($value, bool $isRoot = false)
80
69
$ currentId = $ sourceId ;
81
70
break ;
82
71
}
72
+
73
+ if (isset ($ this ->serviceLocatorContextIds [$ sourceId ])) {
74
+ $ currentId = $ this ->serviceLocatorContextIds [$ sourceId ];
75
+ $ locator = $ this ->container ->getDefinition ($ this ->currentId );
76
+ $ this ->throwServiceNotFoundException ($ value , $ currentId , $ locator ->getArgument (0 ));
77
+ }
83
78
}
84
79
}
85
80
86
- throw new ServiceNotFoundException ( $ id , $ currentId , null , $ this -> getAlternatives ( $ id ) );
81
+ $ this -> throwServiceNotFoundException ( $ value , $ currentId , $ value );
87
82
}
88
83
89
- private function getAlternatives ( string $ id ): array
84
+ private function throwServiceNotFoundException ( Reference $ ref , string $ sourceId , $ value ): void
90
85
{
86
+ $ id = (string ) $ ref ;
91
87
$ alternatives = [];
92
88
foreach ($ this ->container ->getServiceIds () as $ knownId ) {
93
89
if ('' === $ knownId || '. ' === $ knownId [0 ]) {
@@ -100,6 +96,31 @@ private function getAlternatives(string $id): array
100
96
}
101
97
}
102
98
103
- return $ alternatives ;
99
+ $ pass = new class () extends AbstractRecursivePass {
100
+ public $ ref ;
101
+ public $ sourceId ;
102
+ public $ alternatives ;
103
+
104
+ /**
105
+ * @return mixed
106
+ */
107
+ public function processValue ($ value , bool $ isRoot = false )
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