Skip to content

Commit

Permalink
[Yaml] Nested merge keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Rochette authored and mathroc committed Aug 6, 2015
1 parent 6f8a37c commit 500c57e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Symfony/Component/Yaml/Parser.php
Expand Up @@ -113,6 +113,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
$data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport);
}
}
if ($isRef) {
$this->refs[$isRef] = end($data);
}
} 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('"', "'")))) {
if ($context && 'sequence' == $context) {
throw new ParseException('You cannot define a mapping item when in a sequence');
Expand Down Expand Up @@ -191,6 +194,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
$data[$key] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport);
}
}
if ($isRef) {
$this->refs[$isRef] = $data[$key];
}
} else {
// multiple documents are not supported
if ('---' === $this->currentLine) {
Expand Down Expand Up @@ -248,10 +254,6 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =

throw new ParseException($error, $this->getRealCurrentLineNb() + 1, $this->currentLine);
}

if ($isRef) {
$this->refs[$isRef] = end($data);
}
}

if (isset($mbEncoding)) {
Expand Down
13 changes: 12 additions & 1 deletion src/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.yml
Expand Up @@ -23,5 +23,16 @@ yaml: |
isit: tested
head:
<<: [ *foo , *dong , *foo2 ]
taz: &taz
a: Steve
w:
p: 1234
nested:
<<: *taz
d: Doug
w: &nestedref
p: 12345
z:
<<: *nestedref
php: |
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'))
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 comments on commit 500c57e

Please sign in to comment.