@@ -44,12 +44,13 @@ public function __construct($offset = 0)
44
44
* @param string $value A YAML string
45
45
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
46
46
* @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()
47
48
*
48
49
* @return mixed A PHP value
49
50
*
50
51
* @throws ParseException If the YAML is not valid
51
52
*/
52
- public function parse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false )
53
+ public function parse ($ value , $ exceptionOnInvalidType = false , $ objectSupport = false , $ objectForMap = false )
53
54
{
54
55
$ this ->currentLineNb = -1 ;
55
56
$ this ->currentLine = '' ;
@@ -93,7 +94,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
93
94
$ c = $ this ->getRealCurrentLineNb () + 1 ;
94
95
$ parser = new Parser ($ c );
95
96
$ parser ->refs =& $ this ->refs ;
96
- $ data [] = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport );
97
+ $ data [] = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
97
98
} else {
98
99
if (isset ($ values ['leadspaces ' ])
99
100
&& ' ' == $ values ['leadspaces ' ]
@@ -109,9 +110,9 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
109
110
$ block .= "\n" .$ this ->getNextEmbedBlock ($ this ->getCurrentLineIndentation () + 2 );
110
111
}
111
112
112
- $ data [] = $ parser ->parse ($ block , $ exceptionOnInvalidType , $ objectSupport );
113
+ $ data [] = $ parser ->parse ($ block , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
113
114
} else {
114
- $ data [] = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport );
115
+ $ data [] = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
115
116
}
116
117
}
117
118
} 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 =
121
122
$ context = 'mapping ' ;
122
123
123
124
// force correct settings
124
- Inline::parse (null , $ exceptionOnInvalidType , $ objectSupport );
125
+ Inline::parse (null , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
125
126
try {
126
127
$ key = Inline::parseScalar ($ values ['key ' ]);
127
128
} catch (ParseException $ e ) {
@@ -146,7 +147,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
146
147
$ c = $ this ->getRealCurrentLineNb () + 1 ;
147
148
$ parser = new Parser ($ c );
148
149
$ parser ->refs =& $ this ->refs ;
149
- $ parsed = $ parser ->parse ($ value , $ exceptionOnInvalidType , $ objectSupport );
150
+ $ parsed = $ parser ->parse ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
150
151
151
152
$ merged = array ();
152
153
if (!is_array ($ parsed )) {
@@ -188,7 +189,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
188
189
$ c = $ this ->getRealCurrentLineNb () + 1 ;
189
190
$ parser = new Parser ($ c );
190
191
$ parser ->refs =& $ this ->refs ;
191
- $ value = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport );
192
+ $ value = $ parser ->parse ($ this ->getNextEmbedBlock (), $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
192
193
// Spec: Keys MUST be unique; first one wins.
193
194
// Parser cannot abort this mapping earlier, since lines
194
195
// are processed sequentially.
@@ -200,7 +201,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
200
201
if ($ isInPlace ) {
201
202
$ data = $ this ->refs [$ isInPlace ];
202
203
} else {
203
- $ value = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport); ;
204
+ $ value = $ this ->parseValue ($ values ['value ' ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap ) ;
204
205
// Spec: Keys MUST be unique; first one wins.
205
206
// Parser cannot abort this mapping earlier, since lines
206
207
// are processed sequentially.
@@ -214,7 +215,7 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport =
214
215
$ lineCount = count ($ this ->lines );
215
216
if (1 === $ lineCount || (2 === $ lineCount && empty ($ this ->lines [1 ]))) {
216
217
try {
217
- $ value = Inline::parse ($ this ->lines [0 ], $ exceptionOnInvalidType , $ objectSupport );
218
+ $ value = Inline::parse ($ this ->lines [0 ], $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
218
219
} catch (ParseException $ e ) {
219
220
$ e ->setParsedLine ($ this ->getRealCurrentLineNb () + 1 );
220
221
$ e ->setSnippet ($ this ->currentLine );
@@ -390,15 +391,16 @@ private function moveToPreviousLine()
390
391
/**
391
392
* Parses a YAML value.
392
393
*
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()
396
398
*
397
- * @return mixed A PHP value
399
+ * @return mixed A PHP value
398
400
*
399
401
* @throws ParseException When reference does not exist
400
402
*/
401
- private function parseValue ($ value , $ exceptionOnInvalidType , $ objectSupport )
403
+ private function parseValue ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap )
402
404
{
403
405
if (0 === strpos ($ value , '* ' )) {
404
406
if (false !== $ pos = strpos ($ value , '# ' )) {
@@ -421,7 +423,7 @@ private function parseValue($value, $exceptionOnInvalidType, $objectSupport)
<
1241
/td>421
423
}
422
424
423
425
try {
424
- return Inline::parse ($ value , $ exceptionOnInvalidType , $ objectSupport );
426
+ return Inline::parse ($ value , $ exceptionOnInvalidType , $ objectSupport, $ objectForMap );
425
427
} catch (ParseException $ e ) {
426
428
$ e ->setParsedLine ($ this ->getRealCurrentLineNb () + 1 );
427
429
$ e ->setSnippet ($ this ->currentLine );
0 commit comments