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
bug symfony#17876 [DependencyInjection] Fixing autowiring bug when some args are set (weaverryan)
This PR was merged into the 2.8 branch.
Discussion
----------
[DependencyInjection] Fixing autowiring bug when some args are set
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | symfony#17724, symfony#17878
| License | MIT
| Doc PR | todo
This fixessymfony#17724 & symfony#17878.
**symfony#17724**
I've set this against the 2.8 branch because imo it's a bug fix. The [test](https://github.com/symfony/symfony/compare/2.8...weaverryan:auto-wiring-individuals?expand=1#diff-d124c3d39cd5f7c732fb3d3be7a8cb42R298) illustrates the bug - having *some* arguments set beforehand caused auto-wired arguments to be set on the wrong index.
**symfony#17878**
I've also included this fix just to get all the weird ordering problems taken care of at once. I don't think this is a behavior change - autowiring with scalars only worked previously if the argument was optional (still works now) or if you specified that argument explicitly (still works). Otherwise, your argument ordering would have gotten messed up.
Commits
-------
260731b minor changes
865f202 [symfony#17878] Fixing a bug where scalar values caused invalid ordering
cf692a6 [symfony#17724] Fixing autowiring bug where if some args are set, new ones are put in the wrong spot
if ($argumentExists && '' !== $arguments[$index]) {
74
+
if (array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
76
75
continue;
77
76
}
78
77
79
78
try {
80
79
if (!$typeHint = $parameter->getClass()) {
80
+
// no default value? Then fail
81
+
if (!$parameter->isOptional()) {
82
+
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));
* @expectedExceptionMessage Unable to autowire argument index 1 ($foo) for the service "arg_no_type_hint". If this is an object, give it a type-hint. Otherwise, specify this argument's value explicitly.
* @expectedExceptionMessage Unable to autowire argument index 1 ($foo) for the service "not_really_optional_scalar". If this is an object, give it a type-hint. Otherwise, specify this argument's value explicitly.
0 commit comments