Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
Expand Down Expand Up @@ -182,10 +183,10 @@ protected function processValue($value, bool $isRoot = false)
foreach ($reflectionMethod->getParameters() as $key => $parameter) {
$names[$key] = $parameter->name;

if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key] && !$arguments[$key] instanceof AbstractArgument) {
continue;
}
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name] && !$arguments[$parameter->name] instanceof AbstractArgument) {
continue;
}

Expand Down Expand Up @@ -219,7 +220,9 @@ protected function processValue($value, bool $isRoot = false)

foreach ($names as $key => $name) {
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
$arguments[$key] = $arguments[$name];
if (!array_key_exists($key, $arguments)) {
$arguments[$key] = $arguments[$name];
}
unset($arguments[$name]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
Expand Down Expand Up @@ -262,11 +263,23 @@ public function testBindWithNamedArgs()
$definition->setArguments(['c' => 'C', 'hostName' => 'H']);
$definition->setBindings($bindings);

$container->register('foo', CaseSensitiveClass::class);

$pass = new ResolveBindingsPass();
$pass->process($container);

$this->assertEquals(['C', 'K', 'H'], $definition->getArguments());
}

public function testAbstractArg()
{
$container = new ContainerBuilder();

$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
$definition->setArguments([new AbstractArgument(), 'apiKey' => new AbstractArgument()]);
$definition->setBindings(['$c' => new BoundArgument('C'), '$apiKey' => new BoundArgument('K')]);

$pass = new ResolveBindingsPass();
$pass->process($container);

$this->assertEquals(['C', 'K'], $definition->getArguments());
}
}