bug #17079 Also transform inline mappings to objects (WouterJ)
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #17079).
Discussion
----------
Also transform inline mappings to objects
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #17075
| License | MIT
| Doc PR | -
`$objectForMapping` was only applied to inlined mappings. It should be applied for multi-line mappings as well.
Commits
-------
61b863b
Also transform inline mappings to objects
This commit is contained in:
commit
5fa5c874a0
@ -240,6 +240,10 @@ class Parser
|
||||
if ($isRef) {
|
||||
$this->refs[$isRef] = $data[$key];
|
||||
}
|
||||
|
||||
if ($objectForMap && !is_object($data)) {
|
||||
$data = (object) $data;
|
||||
}
|
||||
} else {
|
||||
// multiple documents are not supported
|
||||
if ('---' === $this->currentLine) {
|
||||
|
@ -438,6 +438,28 @@ EOF;
|
||||
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
|
||||
}
|
||||
|
||||
public function testObjectForMapEnabledWithMapping()
|
||||
{
|
||||
$yaml = <<<EOF
|
||||
foo:
|
||||
fiz: [cat]
|
||||
EOF;
|
||||
$result = $this->parser->parse($yaml, false, false, true);
|
||||
|
||||
$this->assertInstanceOf('stdClass', $result);
|
||||
$this->assertInstanceOf('stdClass', $result->foo);
|
||||
$this->assertEquals(array('cat'), $result->foo->fiz);
|
||||
}
|
||||
|
||||
public function testObjectForMapEnabledWithInlineMapping()
|
||||
{
|
||||
$result = $this->parser->parse('{ "foo": "bar", "fiz": "cat" }', false, false, true);
|
||||
|
||||
$this->assertInstanceOf('stdClass', $result);
|
||||
$this->assertEquals('bar', $result->foo);
|
||||
$this->assertEquals('cat', $result->fiz);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user