You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
107
176
continue;
108
177
}
@@ -111,7 +180,11 @@ private function completeDefinition($id, Definition $definition)
111
180
if (!$typeHint = $parameter->getClass()) {
112
181
// no default value? Then fail
113
182
if (!$parameter->isOptional()) {
114
-
thrownewRuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id));
183
+
if ($isConstructor) {
184
+
thrownewRuntimeException(sprintf('Unable to autowire argument index %d ($%s) for the service "%s". If this is an object, give it a type-hint. Otherwise, specify this argument\'s value explicitly.', $index, $parameter->name, $id));
185
+
}
186
+
187
+
return;
115
188
}
116
189
117
190
// specifically pass the default value
@@ -126,24 +199,35 @@ private function completeDefinition($id, Definition $definition)
// The exception code is set to 1 if the exception must be thrown even if it's a setter
214
+
if (1 === $e->getCode() || $isConstructor) {
215
+
throw$e;
216
+
}
217
+
218
+
return;
139
219
}
140
220
}
141
221
}
142
222
} catch (\ReflectionException$e) {
143
223
// Typehint against a non-existing class
144
224
145
225
if (!$parameter->isDefaultValueAvailable()) {
146
-
thrownewRuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $e->getMessage()), 0, $e);
226
+
if ($isConstructor) {
227
+
thrownewRuntimeException(sprintf('Cannot autowire argument %s for %s because the type-hinted class does not exist (%s).', $index + 1, $definition->getClass(), $e->getMessage()), 0, $e);
228
+
}
229
+
230
+
return;
147
231
}
148
232
149
233
$value = $parameter->getDefaultValue();
@@ -155,7 +239,12 @@ private function completeDefinition($id, Definition $definition)
155
239
// it's possible index 1 was set, then index 0, then 2, etc
156
240
// make sure that we re-order so they're injected as expected
thrownewRuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).', $typeHint->name, $id, $classOrInterface, $matchingServices));
345
+
thrownewRuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).', $typeHint->name, $id, $classOrInterface, $matchingServices), 1);
257
346
}
258
347
259
348
if (!$typeHint->isInstantiable()) {
@@ -269,7 +358,7 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint, $id)
$message = sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface);
@@ -320,20 +409,6 @@ private function addServiceToAmbiguousType($id, $type)
thrownewInvalidArgumentException(sprintf('The "autowire" attribute cannot be used together with "<autowire>" tags for service "%s" in %s.', (string) $service->getAttribute('id'), $file));
250
+
}
251
+
252
+
$definition->setAutowiredMethods($autowireTags);
253
+
}
254
+
242
255
if ($value = $service->getAttribute('decorates')) {
0 commit comments