Skip to content

Commit 2a6dd14

Browse files
Merge branch '6.1' into 6.2
* 6.1: [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.1.12 Update VERSION for 6.1.11 Update CHANGELOG for 6.1.11 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 6abd565 + 360c9d0 commit 2a6dd14

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
@@ -272,6 +272,10 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
272272
foreach ($parameters as $index => $parameter) {
273273
$this->defaultArgument->names[$index] = $parameter->name;
274274

275+
if (\array_key_exists($parameter->name, $arguments)) {
276+
$arguments[$index] = $arguments[$parameter->name];
277+
unset($arguments[$parameter->name]);
278+
}
275279
if (\array_key_exists($index, $arguments) && '' !== $arguments[$index]) {
276280
continue;
277281
}
@@ -367,7 +371,7 @@ private function autowireMethod(\ReflectionFunctionAbstract $reflectionMethod, a
367371

368372
// it's possible index 1 was set, then index 0, then 2, etc
369373
// make sure that we re-order so they're injected as expected
370-
ksort($arguments);
374+
ksort($arguments, \SORT_NATURAL);
371375

372376
return $arguments;
373377
}

Compiler/ResolveBindingsPass.php

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

174+
$names = [];
175+
174176
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
177+
$names[$key] = $parameter->name;
178+
175179
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
176180
continue;
177181
}
182+
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
183+
continue;
184+
}
178185

179186
$typeHint = ltrim(ProxyHelper::exportType($parameter) ?? '', '?');
180187

@@ -205,8 +212,15 @@ protected function processValue(mixed $value, bool $isRoot = false): mixed
205212
}
206213
}
207214

215+
foreach ($names as $key => $name) {
216+
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
217+
$arguments[$key] = $arguments[$name];
218+
unset($arguments[$name]);
219+
}
220+
}
221+
208222
if ($arguments !== $call[1]) {
209-
ksort($arguments);
223+
ksort($arguments, \SORT_NATURAL);
210224
$calls[$i][1] = $arguments;
211225
}
212226
}

Tests/Compiler/AutowirePassTest.php

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

1162+
public function testAutowireWithNamedArgs()
1163+
{
1164+
$container = new ContainerBuilder();
1165+
1166+
$container->register('foo', MultipleArgumentsOptionalScalar::class)
1167+
->setArguments(['foo' => 'abc'])
1168+
->setAutowired(true)
1169+
->setPublic(true);
1170+
$container->register(A::class, A::class);
1171+
1172+
(new AutowirePass())->process($container);
1173+
1174+
$this->assertEquals([new TypedReference(A::class, A::class), 'abc'], $container->getDefinition('foo')->getArguments());
1175+
}
1176+
11621177
public function testAutowireAttribute()
11631178
{
11641179
$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)