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
minor #21561 [DI] Refacto / cleanup / minor fixes (nicolas-grekas)
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Refacto / cleanup / minor fixes
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
An almost neutral refacto touching only new things in master - unlocking some next steps.
- renames "autowire method" to "autowire call"
- renames `GetterProxyInterface` to `InheritanceProxyInterface`
- moves some helpers in a new internal `InheritanceProxyHelper`
- some other minor things
Commits
-------
ad5b5b5 [DI] Refacto / cleanup / minor fixes
if ($constructor = $reflectionClass->getConstructor()) {
@@ -89,7 +99,7 @@ protected function processValue($value, $isRoot = false)
89
99
thrownewRuntimeException(sprintf('Cannot autowire service "%s": class %s has no constructor but arguments are defined.', $this->currentId, $reflectionClass->name, $method));
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
217
228
continue;
218
229
}
230
+
if (method_exists($parameter, 'isVariadic') && $parameter->isVariadic()) {
231
+
continue;
232
+
}
219
233
220
234
if (method_exists($parameter, 'getType')) {
221
235
if ($typeName = $parameter->getType()) {
@@ -228,7 +242,7 @@ private function autowireMethodCall(\ReflectionMethod $reflectionMethod, array $
228
242
if (!$typeName) {
229
243
// no default value? Then fail
230
244
if (!$parameter->isOptional()) {
231
-
if ($mustAutowire) {
245
+
if (self::MODE_REQUIRED === $mode) {
232
246
thrownewRuntimeException(sprintf('Cannot autowire service "%s": argument $%s of method %s::%s() must have a type-hint or be given a value explicitly.', $this->currentId, $parameter->name, $reflectionMethod->class, $reflectionMethod->name));
233
247
}
234
248
@@ -268,7 +282,7 @@ private function autowireMethodCall(\ReflectionMethod $reflectionMethod, array $
268
282
$value = $parameter->getDefaultValue();
269
283
} else {
270
284
// The exception code is set to 1 if the exception must be thrown even if it's an optional setter
271
-
if (1 === $e->getCode() || $mustAutowire) {
285
+
if (1 === $e->getCode() || self::MODE_REQUIRED === $mode) {
272
286
throw$e;
273
287
}
274
288
@@ -279,7 +293,7 @@ private function autowireMethodCall(\ReflectionMethod $reflectionMethod, array $
279
293
// Typehint against a non-existing class
280
294
281
295
if (!$parameter->isDefaultValueAvailable()) {
282
-
if ($mustAutowire) {
296
+
if (self::MODE_REQUIRED === $mode) {
283
297
thrownewRuntimeException(sprintf('Cannot autowire argument $%s of method %s::%s() for service "%s": Class %s does not exist.', $parameter->name, $reflectionMethod->class, $reflectionMethod->name, $this->currentId, $typeName));
284
298
}
285
299
@@ -292,7 +306,7 @@ private function autowireMethodCall(\ReflectionMethod $reflectionMethod, array $
292
306
$arguments[$index] = $value;
293
307
}
294
308
295
-
if (!$mustAutowire && !$didAutowire) {
309
+
if (self::MODE_REQUIRED !== $mode && !$didAutowire) {
296
310
returnarray();
297
311
}
298
312
@@ -313,8 +327,8 @@ private function autowireMethodCall(\ReflectionMethod $reflectionMethod, array $
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" does not exist.', $id, $class->name, $name));
1335
-
}
1336
-
$r = $class->getMethod($name);
1337
-
if ($r->isPrivate()) {
1338
-
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" must be public or protected.', $id, $class->name, $r->name));
1339
-
}
1340
-
if ($r->isStatic()) {
1341
-
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot be static.', $id, $class->name, $r->name));
1342
-
}
1343
-
if ($r->isFinal()) {
1344
-
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot be marked as final.', $id, $class->name, $r->name));
1345
-
}
1346
-
if ($r->returnsReference()) {
1347
-
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot return by reference.', $id, $class->name, $r->name));
1348
-
}
1349
-
if (0 < $r->getNumberOfParameters()) {
1350
-
thrownewRuntimeException(sprintf('Unable to configure getter injection for service "%s": method "%s::%s" cannot have any arguments.', $id, $class->name, $r->name));
1351
-
}
1352
-
if ($type = method_exists($r, 'getReturnType') ? $r->getReturnType() : null) {
0 commit comments