Skip to content

Commit 500c57e

Browse files
Mathieu Rochettemathroc
authored andcommitted
[Yaml] Nested merge keys
1 parent 6f8a37c commit 500c57e

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Symfony/Component/Yaml/Parser.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
113113
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport);
114114
}
115115
}
116+
if ($isRef) {
117+
$this->refs[$isRef] = end($data);
118+
}
116119
} elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && (false === strpos($values['key'], ' #') || in_array($values['key'][0], array('"', "'")))) {
117120
if ($context && 'sequence' == $context) {
118121
throw new ParseException('You cannot define a mapping item when in a sequence');
@@ -191,6 +194,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
191194
$data[$key] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport);
192195
}
193196
}
197+
if ($isRef) {
198+
$this->refs[$isRef] = $data[$key];
199+
}
194200
} else {
195201
// multiple documents are not supported
196202
if ('---' === $this->currentLine) {
@@ -248,10 +254,6 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
248254

249255
throw new ParseException($error, $this->getRealCurrentLineNb() + 1, $this->currentLine);
250256
}
251-
252-
if ($isRef) {
253-
$this->refs[$isRef] = end($data);
254-
}
255257
}
256258

257259
if (isset($mbEncoding)) {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,16 @@ yaml: |
2323
isit: tested
2424
head:
2525
<<: [ *foo , *dong , *foo2 ]
26+
taz: &taz
27+
a: Steve
28+
w:
29+
p: 1234
30+
nested:
31+
<<: *taz
32+
d: Doug
33+
w: &nestedref
34+
p: 12345
35+
z:
36+
<<: *nestedref
2637
php: |
27-
array('foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'), 'bar' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'x' => 'Oren'), 'foo2' => array('a' => 'Ballmer'), 'ding' => array('fi', 'fei', 'fo', 'fam'), 'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'), 'head' => array('a' => 'Ballmer', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'))
38+
array('foo' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian'), 'bar' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'x' => 'Oren'), 'foo2' => array('a' => 'Ballmer'), 'ding' => array('fi', 'fei', 'fo', 'fam'), 'check' => array('a' => 'Steve', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam', 'isit' => 'tested'), 'head' => array('a' => 'Ballmer', 'b' => 'Clark', 'c' => 'Brian', 'fi', 'fei', 'fo', 'fam'), 'taz' => array('a' => 'Steve', 'w' => array('p' => 1234)), 'nested' => array('a' => 'Steve', 'w' => array('p' => 12345), 'd' => 'Doug', 'z' => array('p' => 12345)),)

0 commit comments

Comments
 (0)