@@ -114,9 +114,10 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
114
114
return new $ requestedName ();
115
115
}
116
116
117
- $ parameters = array_map (function (ReflectionParameter $ parameter ) use ($ container , $ requestedName ) {
118
- return $ this ->resolveParameter ($ parameter , $ container , $ requestedName );
119
- }, $ reflectionParameters );
117
+ $ parameters = array_map (
118
+ $ this ->resolveParameter ($ container , $ requestedName ),
119
+ $ reflectionParameters
120
+ );
120
121
121
122
return new $ requestedName (...$ parameters );
122
123
}
@@ -136,42 +137,49 @@ public function canCreate(ContainerInterface $container, $requestedName)
136
137
/**
137
138
* Resolve a parameter to a value.
138
139
*
139
- * @param ReflectionClass $parameter
140
+ * Returns a callback for resolving a parameter to a value.
141
+ *
140
142
* @param ContainerInterface $container
141
143
* @param string $requestedName
142
- * @return mixed
143
- * @throws ServiceNotFoundException If type-hinted parameter cannot be
144
- * resolved to a service in the container.
144
+ * @return callable
145
145
*/
146
- private function resolveParameter (ReflectionParameter $ parameter , ContainerInterface $ container , $ requestedName )
146
+ private function resolveParameter (ContainerInterface $ container , $ requestedName )
147
147
{
148
- if ($ parameter ->isArray ()
149
- && $ parameter ->getName () === 'config '
150
- && $ container ->has ('config ' )
151
- ) {
152
- return $ container ->get ('config ' );
153
- }
154
-
155
- if ($ parameter ->isArray ()) {
156
- return [];
157
- }
158
-
159
- if (! $ parameter ->getClass ()) {
160
- return ;
161
- }
162
-
163
- $ type = $ parameter ->getClass ()->getName ();
164
- $ type = isset ($ this ->aliases [$ type ]) ? $ this ->aliases [$ type ] : $ type ;
165
-
166
- if (! $ container ->has ($ type )) {
167
- throw new ServiceNotFoundException (sprintf (
168
- 'Unable to create controller "%s"; unable to resolve parameter "%s" using type hint "%s" ' ,
169
- $ requestedName ,
170
- $ parameter ->getName (),
171
- $ type
172
- ));
173
- }
174
-
175
- return $ container ->get ($ type );
148
+ /**
149
+ * @param ReflectionClass $parameter
150
+ * @return mixed
151
+ * @throws ServiceNotFoundException If type-hinted parameter cannot be
152
+ * resolved to a service in the container.
153
+ */
154
+ return function (ReflectionParameter $ parameter ) use ($ container , $ requestedName ) {
155
+ if ($ parameter ->isArray ()
156
+ && $ parameter ->getName () === 'config '
157
+ && $ container ->has ('config ' )
158
+ ) {
159
+ return $ container ->get ('config ' );
160
+ }
161
+
162
+ if ($ parameter ->isArray ()) {
163
+ return [];
164
+ }
165
+
166
+ if (! $ parameter ->getClass ()) {
167
+ return ;
168
+ }
169
+
170
+ $ type = $ parameter ->getClass ()->getName ();
171
+ $ type = isset ($ this ->aliases [$ type ]) ? $ this ->aliases [$ type ] : $ type ;
172
+
173
+ if (! $ container ->has ($ type )) {
174
+ throw new ServiceNotFoundException (sprintf (
175
+ 'Unable to create controller "%s"; unable to resolve parameter "%s" using type hint "%s" ' ,
176
+ $ requestedName ,
177
+ $ parameter ->getName (),
178
+ $ type
179
+ ));
180
+ }
181
+
182
+ return $ container ->get ($ type );
183
+ };
176
184
}
177
185
}
0 commit comments