8000 [DependencyInjection] Fix named args support in ChildDefinition by dunglas · Pull Request #22981 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Fix named args support in ChildDefinition #22981

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[DependencyInjection] Fix named args support in ChildDefinition
  • Loading branch information
dunglas committed May 31, 2017
commit 70105d1f0690c545c7f90c38bfcfa9f05cad19f4
10 changes: 7 additions & 3 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function setParent($parent)
* If replaceArgument() has been used to replace an argument, this method
* will return the replacement value.
*
* @param int $index
* @param int|string $index
*
* @return mixed The argument value
*
Expand All @@ -74,6 +74,10 @@ public function getArgument($index)
return $this->arguments['index_'.$index];
}

if (0 === strpos($index, '$') && array_key_exists($index, $this->arguments)) {
return $this->arguments[$index];
}

$lastIndex = count(array_filter(array_keys($this->arguments), 'is_int')) - 1;

if ($index < 0 || $index > $lastIndex) {
Expand All @@ -91,8 +95,8 @@ public function getArgument($index)
* certain conventions when you want to overwrite the arguments of the
* parent definition, otherwise your arguments will only be appended.
*
* @param int $index
* @param mixed $value
* @param int|string $index
* @param mixed $value
*
* @return self the current instance
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public function testReplaceArgument()
$this->assertSame('baz', $def->getArgument(1));

$this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz'), $def->getArguments());

$this->assertSame($def, $def->replaceArgument('$bar', 'val'));
$this->assertSame('val', $def->getArgument('$bar'));
$this->assertSame(array(0 => 'foo', 1 => 'bar', 'index_1' => 'baz', '$bar' => 'val'), $def->getArguments());
}

/**
Expand Down
0