Skip to content

Commit 360c9d0

Browse files
Merge branch '6.0' into 6.1
* 6.0: [HttpFoundation] Fix bad return type in IpUtils::checkIp4() [DependencyInjection] Fix order of arguments when mixing positional and named ones [HttpClient] Fix collecting data non-late for the profiler [Security/Http] Fix compat of persistent remember-me with legacy tokens Bump Symfony version to 6.0.20 Update VERSION for 6.0.19 Update CHANGELOG for 6.0.19 Bump Symfony version to 5.4.20 Update VERSION for 5.4.19 Update CONTRIBUTORS for 5.4.19 Update CHANGELOG for 5.4.19 [Security/Http] Remove CSRF tokens from storage on successful login [HttpKernel] Remove private headers before storing responses with HttpCache
2 parents 6ff7b7d + 359806e commit 360c9d0

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

Compiler/AutowirePass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
241241
foreach ($parameters as $index => $parameter) {
242242
$this->defaultArgument->names[$index] = $parameter->name;
243243

244+
if (\array_key_exists($parameter->name, $arguments)) {
245+
$arguments[$index] = $arguments[$parameter->name];
246+
unset($arguments[$parameter->name]);
247+
}
244248
if (\array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
245249
continue;
246250
}
@@ -362,7 +366,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
362366

363367
// it's possible index 1 was set, then index 0, then 2, etc
364368
// make sure that we re-order so they're injected as expected
365-
ksort($arguments);
369+
ksort($arguments, \SORT_NATURAL);
366370

367371
return $arguments;
368372
}

Compiler/ResolveBindingsPass.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,17 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
177177
}
178178
}
179179

180+
$names = [];
181+
180182
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
183+
$names[$key] = $parameter->name;
184+
181185
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
182186
continue;
183187
}
188+
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
189+
continue;
190+
}
184191

185192
$typeHint = ProxyHelper::getTypeHint($reflectionMethod, $parameter);
186193
$name = Target::parseName($parameter);
@@ -210,8 +217,15 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
210217
}
211218
}
212219

220+
foreach ($names as $key => $name) {
221+
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
222+
$arguments[$key] = $arguments[$name];
223+
unset($arguments[$name]);
224+
}
225+
}
226+
213227
if ($arguments !== $call[1]) {
214-
ksort($arguments);
228+
ksort($arguments, \SORT_NATURAL);
215229
$calls[$i][1] = $arguments;
216230
}
217231
}

Tests/Compiler/AutowirePassTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,21 @@ public function testDecorationWithServiceAndAliasedInterface()
11621162
static::assertInstanceOf(DecoratedDecorator::class, $container->get(DecoratorImpl::class));
11631163
}
11641164

1165+
public function testAutowireWithNamedArgs()
1166+
{
1167+
$container = new ContainerBuilder();
1168+
1169+
$container->register('foo', MultipleArgumentsOptionalScalar::class)
1170+
->setArguments(['foo' => 'abc'])
1171+
->setAutowired(true)
1172+
->setPublic(true);
1173+
$container->register(A::class, A::class);
1174+
1175+
(new AutowirePass())->process($container);
1176+
1177+
$this->assertEquals([new TypedReference(A::class, A::class), 'abc'], $container->getDefinition('foo')->getArguments());
1178+
}
1179+
11651180
public function testAutowireAttribute()
11661181
{
11671182
$container = new ContainerBuilder();

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,24 @@ public function testBindWithTarget()
243243

244244
$this->assertSame('bar', (string) $container->getDefinition('with_target')->getArgument(0));
245245
}
246+
247+
public function testBindWithNamedArgs()
248+
{
249+
$container = new ContainerBuilder();
250+
251+
$bindings = [
252+
'$apiKey' => new BoundArgument('K'),
253+
];
254+
255+
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
256+
$definition->setArguments(['c' => 'C', 'hostName' => 'H']);
257+
$definition->setBindings($bindings);
258+
259+
$container->register('foo', CaseSensitiveClass::class);
260+
261+
$pass = new ResolveBindingsPass();
262+
$pass->process($container);
263+
264+
$this->assertEquals(['C', 'K', 'H'], $definition->getArguments());
265+
}
246266
}

0 commit comments

Comments
 (0)