diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 55d7f7032117..ce9ced85e76d 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -240,6 +240,10 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport = if ($isRef) { $this->refs[$isRef] = $data[$key]; } + + if ($objectForMap && !is_object($data)) { + $data = (object) $data; + } } else { // multiple documents are not supported if ('---' === $this->currentLine) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index 517836abe752..8fc7db58746a 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -438,6 +438,28 @@ public function testObjectSupportDisabledButNoExceptions() $this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects'); } + public function testObjectForMapEnabledWithMapping() + { + $yaml = <<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 */