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 89e2724

Browse filesBrowse files
[DI] Fix defaults overriding empty strings in AutowirePass
1 parent c56f547 commit 89e2724
Copy full SHA for 89e2724

File tree

Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ private function completeDefinition($id, Definition $definition)
9595
throw new RuntimeException(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));
9696
}
9797

98-
// specifically pass the default value
99-
$arguments[$index] = $parameter->getDefaultValue();
98+
if (!array_key_exists($index, $arguments)) {
99+
// specifically pass the default value
100+
$arguments[$index] = $parameter->getDefaultValue();
101+
}
100102

101103
continue;
102104
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,22 @@ public function testIgnoreServiceWithClassNotExisting()
443443

444444
$this->assertTrue($container->hasDefinition('bar'));
445445
}
446+
447+
public function testEmptyStringIsKept()
448+
{
449+
$container = new ContainerBuilder();
450+
451+
$container->register('a', __NAMESPACE__.'\A');
452+
$container->register('lille', __NAMESPACE__.'\Lille');
453+
$container->register('foo', __NAMESPACE__.'\MultipleArgumentsOptionalScalar')
454+
->setAutowired(true)
455+
->setArguments(array('', ''));
456+
457+
$pass = new AutowirePass();
458+
$pass->process($container);
459+
460+
$this->assertEquals(array(new Reference('a'), '', new Reference('lille')), $container->getDefinition('foo')->getArguments());
461+
}
446462
}
447463

448464
class Foo

0 commit comments

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