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

[DependencyInjection] Fix binding parameters with default empty values #57186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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 @@ -182,10 +182,11 @@ 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]) {
continue;
if (\array_key_exists($parameter->name, $arguments)) {
$key = $parameter->name;
}
if (\array_key_exists($parameter->name, $arguments) && '' !== $arguments[$parameter->name]) {

if (\array_key_exists($key, $arguments) && !\in_array($arguments[$key], ['', null, []], true)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this makes sense: the empty string is a special case needed when loading from XML, but the others can only be defined by explicit definition.
It's also suspicious to me to change the DI component for an issue with the serializer one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas Yeah, I was way off with this solution, see #57273.

continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,32 @@ public function testEmptyBindingTypehint()
$pass->process($container);
}

/**
* @testWith [1, ""]
* [1, null]
* [1, []]
* ["apiKey", ""]
* ["apiKey", null]
* ["apiKey", []]
*/
public function testEmptyBindingWithEmptyDefaultValue($key, $value)
{
$container = new ContainerBuilder();

$bindings = [
'$apiKey' => new BoundArgument('foo'),
];

$definition = $container->register(NamedArgumentsDummy::class, NamedArgumentsDummy::class);
$definition->setArguments([$key => $value]);
$definition->setBindings($bindings);

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

$this->assertEquals([$key => 'foo'], $definition->getArguments());
}

public function testIterableBindingTypehint()
{
$autoloader = static function ($class) {
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.