Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca509ea

Browse filesBrowse files
committed
bug #22677 [DI] Fixed index args bug with ResolveNamedArgumentsPass (weaverryan)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Fixed index args bug with ResolveNamedArgumentsPass | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | n/a While upgrading a project, this code suddenly broke: ```yml services: ice_cream_service: class: AppBundle\Service\IceCreamService autowire: true arguments: 1: 'http://api.example.com' ``` ```php class IceCreamService { public function __construct(EntityManager $em, $apiUrl) { } } ``` Suddenly, the index `1` was not being mapped to `$apiUrl`. This was valid in 3.2, but broke when `ResolveNamedArgumentsPass` accidentally re-set the index. Simple fix :). Ping @dunglas Cheers! Commits ------- 7cc7c85 Fixing bug where indexed args were set wrong in pass in some situations
2 parents 3646d08 + 7cc7c85 commit ca509ea
Copy full SHA for ca509ea

File tree

3 files changed

+8
-4
lines changed
Filter options

3 files changed

+8
-4
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveNamedArgumentsPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function processValue($value, $isRoot = false)
4040

4141
foreach ($arguments as $key => $argument) {
4242
if (is_int($key)) {
43-
$resolvedArguments[] = $argument;
43+
$resolvedArguments[$key] = $argument;
4444
continue;
4545
}
4646
if ('' === $key || '$' !== $key[0]) {

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveNamedArgumentsPassTest.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ public function testProcess()
2727
$container = new ContainerBuilder();
2828

2929
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
30-
$definition->setArguments(array(0 => new Reference('foo'), '$apiKey' => '123'));
30+
$definition->setArguments(array(
31+
2 => 'http://api.example.com',
32+
'$apiKey' => '123',
33+
0 => new Reference('foo'),
34+
));
3135
$definition->addMethodCall('setApiKey', array('$apiKey' => '123'));
3236

3337
$pass = new ResolveNamedArgumentsPass();
3438
$pass->process($container);
3539

36-
$this->assertEquals(array(0 => new Reference('foo'), 1 => '123'), $definition->getArguments());
40+
$this->assertEquals(array(0 => new Reference('foo'), 1 => '123', 2 => 'http://api.example.com'), $definition->getArguments());
3741
$this->assertEquals(array(array('setApiKey', array('123'))), $definition->getMethodCalls());
3842
}
3943

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/NamedArgumentsDummy.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
class NamedArgumentsDummy
99
{
10-
public function __construct(CaseSensitiveClass $c, $apiKey)
10+
public function __construct(CaseSensitiveClass $c, $apiKey, $hostName)
1111
{
1212
}
1313

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.