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

Commit366c994

Browse files
committed
substitute aliases in inline mappings
1 parent675a3fe commit366c994

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

‎src/Symfony/Component/Yaml/Inline.php‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
365365
$output =array();
366366
$len =strlen($mapping);
367367
++$i;
368+
$allowOverwrite =false;
368369

369370
// {foo: bar, bar:foo, ...}
370371
while ($i <$len) {
@@ -384,6 +385,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
384385
// key
385386
$key =self::parseScalar($mapping,array(':',''),array('"',"'"),$i,false);
386387

388+
if ('<<' ===$key) {
389+
$allowOverwrite =true;
390+
}
391+
387392
// value
388393
$done =false;
389394

@@ -395,7 +400,12 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
395400
// Spec: Keys MUST be unique; first one wins.
396401
// Parser cannot abort this mapping earlier, since lines
397402
// are processed sequentially.
398-
if (!isset($output[$key])) {
403+
// But overwriting is allowed when a merge node is used in current block.
404+
if ('<<' ===$key) {
405+
foreach ($valueas$parsedValue) {
406+
$output +=$parsedValue;
407+
}
408+
}elseif ($allowOverwrite || !isset($output[$key])) {
399409
$output[$key] =$value;
400410
}
401411
$done =true;
@@ -406,7 +416,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
406416
// Spec: Keys MUST be unique; first one wins.
407417
// Parser cannot abort this mapping earlier, since lines
408418
// are processed sequentially.
409-
if (!isset($output[$key])) {
419+
// But overwriting is allowed when a merge node is used in current block.
420+
if ('<<' ===$key) {
421+
$output +=$value;
422+
}elseif ($allowOverwrite || !isset($output[$key])) {
410423
$output[$key] =$value;
411424
}
412425
$done =true;
@@ -419,7 +432,10 @@ private static function parseMapping($mapping, &$i = 0, $references = array())
419432
// Spec: Keys MUST be unique; first one wins.
420433
// Parser cannot abort this mapping earlier, since lines
421434
// are processed sequentially.
422-
if (!isset($output[$key])) {
435+
// But overwriting is allowed when a merge node is used in current block.
436+
if ('<<' ===$key) {
437+
$output +=$value;
438+
}elseif ($allowOverwrite || !isset($output[$key])) {
423439
$output[$key] =$value;
424440
}
425441
$done =true;

‎src/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ php: |
5353
array(
5454
'foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull'),
5555
'bar' => array('a' => 'before', 'd' => 'other', 'e' => null, 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
56-
'bar_inline' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'x' => 'Oren'),
56+
'bar_inline' => array('a' => 'before', 'd' => 'other', 'b' => 'new', 'c' => array('foo' => 'bar', 'bar' => 'foo'), 'e' => 'notnull', 'x' => 'Oren'),
5757
'duplicate' => array('foo' => 'bar'),
5858
'foo2' => array('a' => 'Ballmer'),
5959
'ding' => array('fi', 'fei', 'fo', 'fam'),
6060
'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'),
6161
'head' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
6262
'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)),
6363
'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345)),
64-
'head_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'),
65-
'recursive_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => array('a' => 'Ballmer'), 'fi', 'fei', 'fo', 'fam')
64+
'head_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
65+
'recursive_inline' => array('a' => 'Steve', 'b' => 'Clark', 'c' => array('a' => 'Ballmer'), 'e' => 'notnull', 'fi', 'fei', 'fo', 'fam'),
6666
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp