@@ -44,12 +44,13 @@ public function __construct($offset = 0)
4444 * @param string $value A YAML string
4545 * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
4646 * @param bool $objectSupport true if object support is enabled, false otherwise
47+ * @param bool $objectForMap true if maps should return a stdClass instead of array()
4748 *
4849 * @return mixed A PHP value
4950 *
5051 * @throws ParseException If the YAML is not valid
5152 */
52- public function parse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false )
53+ public function parse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false , $ objectForMap = false )
5354 {
5455 $ this ->currentLineNb = -1 ;
5556 $ this ->currentLine = '' ;
@@ -93,7 +94,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
9394 $ c = $ this ->getRealCurrentLineNb () + 1 ;
9495 $ parser = new Parser ($ c );
9596 $ parser ->refs =& $ this ->refs ;
96- $ data [] = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport );
97+ $ data [] = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
9798 } else {
9899 if (isset ($ values ['leadspaces ' ])
99100 && ' ' == $ values ['leadspaces ' ]
@@ -109,9 +110,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
109110 $ block .= "\n" .$ this ->getNextEmbedBlock ($ this ->getCurrentLineIndentation () + 2 );
110111 }
111112
112- $ data [] = $ parser ->parse ($ block , $ exceptionOnInvalidType , $ objectSupport );
113+ $ data [] = $ parser ->parse ($ block , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
113114 } else {
114- $ data [] = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport );
115+ $ data [] = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
115116 }
116117 }
117118 } elseif (preg_match ('#^(?P<key> ' .Inline::REGEX_QUOTED_STRING .'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u ' , $ this ->currentLine , $ values ) && false === strpos ($ values ['key ' ],' # ' )) {
@@ -121,7 +122,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
121122 $ context = 'mapping ' ;
122123
123124 // force correct settings
124- Inline::parse (null , $ exceptionOnInvalidType , $ objectSupport );
125+ Inline::parse (null , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
125126 try {
126127 $ key = Inline::parseScalar ($ values ['key ' ]);
127128 } catch (ParseException $ e ) {
@@ -146,7 +147,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
146147 $ c = $ this ->getRealCurrentLineNb () + 1 ;
147148 $ parser = new Parser ($ c );
148149 $ parser ->refs =& $ this ->refs ;
149- $ parsed = $ parser ->parse ($ value , $ exceptionOnInvalidType , $ objectSupport );
150+ $ parsed = $ parser ->parse ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
150151
151152 $ merged = array ();
152153 if (!is_array ($ parsed )) {
@@ -188,7 +189,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
188189 $ c = $ this ->getRealCurrentLineNb () + 1 ;
189190 $ parser = new Parser ($ c );
190191 $ parser ->refs =& $ this ->refs ;
191- $ value = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport );
192+ $ value = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
192193 // Spec: Keys MUST be unique; first one wins.
193194 // Parser cannot abort this mapping earlier, since lines
194195 // are processed sequentially.
@@ -200,7 +201,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
200201 if ($ isInPlace ) {
201202 $ data = $ this ->refs [$ isInPlace ];
202203 } else {
203- $ value = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport); ;
204+ $ value = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap ) ;
204205 // Spec: Keys MUST be unique; first one wins.
205206 // Parser cannot abort this mapping earlier, since lines
206207 // are processed sequentially.
@@ -214,7 +215,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
214215 $ lineCount = count ($ this ->lines );
215216 if (1 === $ lineCount || (2 === $ lineCount && empty ($ this ->lines [1 ]))) {
216217 try {
217- $ value = Inline::parse ($ this ->lines [0 ], $ exceptionOnInvalidType , $ objectSupport );
218+ $ value = Inline::parse ($ this ->lines [0 ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
218219 } catch (ParseException $ e ) {
219220 $ e ->setParsedLine ($ this ->getRealCurrentLineNb () + 1 );
220221 $ e ->setSnippet ($ this ->currentLine );
@@ -390,15 +391,16 @@ private function moveToPreviousLine()
390391 /**
391392 * Parses a YAML value.
392393 *
393- * @param string $value A YAML value
394- * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
395- * @param bool $objectSupport True if object support is enabled, false otherwise
394+ * @param string $value A YAML value
395+ * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
396+ * @param bool $objectSupport True if object support is enabled, false otherwise
397+ * @param bool $objectForMap true if maps should return a stdClass instead of array()
396398 *
397- * @return mixed A PHP value
399+ * @return mixed A PHP value
398400 *
399401 * @throws ParseException When reference does not exist
400402 */
401- private function parseValue ($ value , $ exceptionOnInvalidType , $ objectSupport )
403+ private function parseValue ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap )
402404 {
403405 if (0 === strpos ($ value , '* ' )) {
404406 if (false !== $ pos = strpos ($ value , '# ' )) {
@@ -421,7 +423,7 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport)
421423 }
422424
423425 try {
424- return Inline::parse ($ value , $ exceptionOnInvalidType , $ objectSupport );
426+ return Inline::parse ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
425427 } catch (ParseException $ e ) {
426428 $ e ->setParsedLine ($ this ->getRealCurrentLineNb () + 1 );
427429 $ e ->setSnippet ($ this ->currentLine );
0 commit comments