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 cacaf9f

Browse filesBrowse files
bug #58617 [DependencyInjection] Fix replacing abstract arguments with bindings (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Fix replacing abstract arguments with bindings | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Commits ------- a77d66e [DependencyInjection] Fix replacing abstract arguments with bindings
2 parents ebd2270 + a77d66e commit cacaf9f
Copy full SHA for cacaf9f

File tree

2 files changed

+21
-5
lines changed
Filter options

2 files changed

+21
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

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

185-
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key]) {
186+
if (\array_key_exists($key, $arguments) && '' !== $arguments[$key] && !$arguments[$key] instanceof AbstractArgument) {
186187
continue;
187188
}
188-
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {
189+
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name] && !$arguments[$parameter->name] instanceof AbstractArgument) {
189190
continue;
190191
}
191192

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

220221
foreach ($names as $key => $name) {
221222
if (\array_key_exists($name, $arguments) && (0 === $key || \array_key_exists($key - 1, $arguments))) {
222-
$arguments[$key] = $arguments[$name];
223+
if (!array_key_exists($key, $arguments)) {
224+
$arguments[$key] = $arguments[$name];
225+
}
223226
unset($arguments[$name]);
224227
}
225228
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveBindingsPassTest.php
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
1516
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
1617
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
1718
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
@@ -262,11 +263,23 @@ public function testBindWithNamedArgs()
262263
$definition->setArguments(['c' => 'C', 'hostName' => 'H']);
263264
$definition->setBindings($bindings);
264265

265-
$container->register('foo', CaseSensitiveClass::class);
266-
267266
$pass = new ResolveBindingsPass();
268267
$pass->process($container);
269268

270269
$this->assertEquals(['C', 'K', 'H'], $definition->getArguments());
271270
}
271+
272+
public function testAbstractArg()
273+
{
274+
$container = new ContainerBuilder();
275+
276+
$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
277+
$definition->setArguments([new AbstractArgument(), 'apiKey' => new AbstractArgument()]);
278+
$definition->setBindings(['$c' => new BoundArgument('C'), '$apiKey' => new BoundArgument('K')]);
279+
280+
$pass = new ResolveBindingsPass();
281+
$pass->process($container);
282+
283+
$this->assertEquals(['C', 'K'], $definition->getArguments());
284+
}
272285
}

0 commit comments

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