@@ -249,27 +249,35 @@ private function doParse($value, $flags)
249
249
if ('<< ' === $ key ) {
250
250
$ mergeNode = true ;
251
251
$ allowOverwrite = true ;
252
- if (isset ($ values ['value ' ]) && 0 === strpos ( $ values ['value ' ], ' * ' ) ) {
252
+ if (isset ($ values ['value ' ]) && isset ( $ values [ ' value ' ][ 0 ]) && ' * ' === $ values ['value ' ][ 0 ] ) {
253
253
$ refName = substr (rtrim ($ values ['value ' ]), 1 );
254
254
if (!array_key_exists ($ refName , $ this ->refs )) {
255
255
throw new ParseException (sprintf ('Reference "%s" does not exist. ' , $ refName ), $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine );
256
256
}
257
257
258
258
$ refValue = $ this ->refs [$ refName ];
259
259
260
+ if ((bool ) (Yaml::PARSE_OBJECT_FOR_MAP & $ flags ) && $ refValue instanceof \stdClass) {
261
+ $ refValue = (array ) $ refValue ;
262
+ }
263
+
260
264
if (!is_array ($ refValue )) {
261
265
throw new ParseException ('YAML merge keys used with a scalar value instead of an array. ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine );
262
266
}
263
267
264
268
$ data += $ refValue ; // array union
265
269
} else {
266
- if (isset ($ values ['value ' ]) && $ values [ ' value ' ] !== '' ) {
270
+ if (isset ($ values ['value ' ]) && '' !== $ values [ ' value ' ] ) {
267
271
$ value = $ values ['value ' ];
268
272
} else {
269
273
$ value = $ this ->getNextEmbedBlock ();
270
274
}
271
275
$ parsed = $ this ->parseBlock ($ this ->getRealCurrentLineNb () + 1 , $ value , $ flags );
272
276
277
+ if ((bool ) (Yaml::PARSE_OBJECT_FOR_MAP & $ flags ) && $ parsed instanceof \stdClass) {
278
+ $ parsed = (array ) $ parsed ;
279
+ }
280
+
273
281
if (!is_array ($ parsed )) {
274
282
throw new ParseException ('YAML merge keys used with a scalar value instead of an array. ' , $ this ->getRealCurrentLineNb () + 1 , $ this ->currentLine );
275
283
}
@@ -279,6 +287,10 @@ private function doParse($value, $flags)
279
287
// and each of these nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier
280
288
// in the sequence override keys specified in later mapping nodes.
281
289
foreach ($ parsed as $ parsedItem ) {
290
+ if ((bool ) (Yaml::PARSE_OBJECT_FOR_MAP & $ flags ) && $ parsedItem instanceof \stdClass) {
291
+ $ parsedItem = (array ) $ parsedItem ;
292
+ }
293
+
282
294
if (!is_array ($ parsedItem )) {
283
295
throw new ParseException ('Merge items must be arrays. ' , $ this ->getRealCurrentLineNb () + 1 , $ parsedItem );
284
296
}
@@ -544,7 +556,7 @@ private function getNextEmbedBlock($indentation = null, $inSequence = false)
544
556
$ indent = $ this ->getCurrentLineIndentation ();
545
557
546
558
// terminate all block scalars that are more indented than the current line
547
- if (!empty ($ blockScalarIndentations ) && $ indent < $ previousLineIndentation && trim ($ this ->currentLine ) !== '' ) {
559
+ if (!empty ($ blockScalarIndentations ) && $ indent < $ previousLineIndentation && '' !== trim ($ this ->currentLine )) {
548
560
foreach ($ blockScalarIndentations as $ key => $ blockScalarIndentation ) {
549
561
if ($ blockScalarIndentation >= $ indent ) {
550
562
unset($ blockScalarIndentations [$ key ]);
@@ -680,7 +692,7 @@ private function parseValue($value, $flags, $context)
680
692
681
693
while ($ this ->moveToNextLine ()) {
682
694
// unquoted strings end before the first unindented line
683
- if (null === $ quotation && $ this ->getCurrentLineIndentation () === 0 ) {
695
+ if (null === $ quotation && 0 === $ this ->getCurrentLineIndentation ()) {
684
696
$ this ->moveToPreviousLine ();
685
697
686
698
break ;
@@ -876,7 +888,7 @@ private function isCurrentLineComment()
876
888
//checking explicitly the first char of the trim is faster than loops or strpos
877
889
$ ltrimmedLine = ltrim ($ this ->currentLine , ' ' );
878
890
879
- return '' !== $ ltrimmedLine && $ ltrimmedLine [ 0 ] === ' # ' ;
891
+ return '' !== $ ltrimmedLine && ' # ' === $ ltrimmedLine [ 0 ] ;
880
892
}
881
893
882
894
private function isCurrentLineLastLineInDocument ()
@@ -902,15 +914,15 @@ private function cleanup($value)
902
914
903
915
// remove leading comments
904
916
$ trimmedValue = preg_replace ('#^(\#.*?\n)+#s ' , '' , $ value , -1 , $ count );
905
- if ($ count == 1 ) {
917
+ if (1 === $ count ) {
906
918
// items have been removed, update the offset
907
919
$ this ->offset += substr_count ($ value , "\n" ) - substr_count ($ trimmedValue , "\n" );
908
920
$ value = $ trimmedValue ;
909
921
}
910
922
911
923
// remove start of the document marker (---)
912
924
$ trimmedValue = preg_replace ('#^\-\-\-.*?\n#s ' , '' , $ value , -1 , $ count );
913
- if ($ count == 1 ) {
925
+ if (1 === $ count ) {
914
926
// items have been removed, update the offset
915
927
$ this ->offset += substr_count ($ value , "\n" ) - substr_count ($ trimmedValue , "\n" );
916
928
$ value = $ trimmedValue ;
0 commit comments