Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit70105d1

Browse files
committed
[DependencyInjection] Fix named args support in ChildDefinition
1 parentadc39a2 commit70105d1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

‎src/Symfony/Component/DependencyInjection/ChildDefinition.php‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function setParent($parent)
6262
* If replaceArgument() has been used to replace an argument, this method
6363
* will return the replacement value.
6464
*
65-
* @param int $index
65+
* @param int|string $index
6666
*
6767
* @return mixed The argument value
6868
*
@@ -74,6 +74,10 @@ public function getArgument($index)
7474
return$this->arguments['index_'.$index];
7575
}
7676

77+
if (0 ===strpos($index,'$') &&array_key_exists($index,$this->arguments)) {
78+
return$this->arguments[$index];
79+
}
80+
7781
$lastIndex =count(array_filter(array_keys($this->arguments),'is_int')) -1;
7882

7983
if ($index <0 ||$index >$lastIndex) {
@@ -91,8 +95,8 @@ public function getArgument($index)
9195
* certain conventions when you want to overwrite the arguments of the
9296
* parent definition, otherwise your arguments will only be appended.
9397
*
94-
* @param int $index
95-
* @param mixed $value
98+
* @param int|string $index
99+
* @param mixed$value
96100
*
97101
* @return self the current instance
98102
*

‎src/Symfony/Component/DependencyInjection/Tests/ChildDefinitionTest.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public function testReplaceArgument()
113113
$this->assertSame('baz',$def->getArgument(1));
114114

115115
$this->assertSame(array(0 =>'foo',1 =>'bar','index_1' =>'baz'),$def->getArguments());
116+
117+
$this->assertSame($def,$def->replaceArgument('$bar','val'));
118+
$this->assertSame('val',$def->getArgument('$bar'));
119+
$this->assertSame(array(0 =>'foo',1 =>'bar','index_1' =>'baz','$bar' =>'val'),$def->getArguments());
116120
}
117121

118122
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp