@@ -58,7 +58,7 @@ public static function initialize(int $flags, int $parsedLineNumber = null, stri
58
58
*
59
59
* @throws ParseException
60
60
*/
61
- public static function parse (string $ value = null , int $ flags = 0 , array $ references = [])
61
+ public static function parse (string $ value = null , int $ flags = 0 , array & $ references = [])
62
62
{
63
63
self ::initialize ($ flags );
64
64
@@ -267,7 +267,7 @@ private static function dumpNull(int $flags): string
267
267
*
268
268
* @throws ParseException When malformed inline YAML string is parsed
269
269
*/
270
- public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array $ references = [])
270
+ public static function parseScalar (string $ scalar , int $ flags = 0 , array $ delimiters = null , int &$ i = 0 , bool $ evaluate = true , array & $ references = [])
271
271
{
272
272
if (\in_array ($ scalar [$ i ], ['" ' , "' " ])) {
273
273
// quoted scalar
@@ -343,7 +343,7 @@ private static function parseQuotedScalar(string $scalar, int &$i): string
343
343
*
344
344
* @throws ParseException When malformed inline YAML string is parsed
345
345
*/
346
- private static function parseSequence (string $ sequence , int $ flags , int &$ i = 0 , array $ references = []): array
346
+ private static function parseSequence (string $ sequence , int $ flags , int &$ i = 0 , array & $ references = []): array
347
347
{
348
348
$ output = [];
349
349
$ len = \strlen ($ sequence );
@@ -385,6 +385,11 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
385
385
}
386
386
}
387
387
388
+ if (\is_string ($ value ) && '' !== $ value && '& ' === $ value [0 ] && Parser::preg_match (Parser::REFERENCE_PATTERN , $ value , $ matches )) {
389
+ $ references [$ matches ['ref ' ]] = $ matches ['value ' ];
390
+ $ value = $ matches ['value ' ];
391
+ }
392
+
388
393
--$ i ;
389
394
}
390
395
@@ -407,7 +412,7 @@ private static function parseSequence(string $sequence, int $flags, int &$i = 0,
407
412
*
408
413
* @throws ParseException When malformed inline YAML string is parsed
409
414
*/
410
- private static function parseMapping (string $ mapping , int $ flags , int &$ i = 0 , array $ references = [])
415
+ private static function parseMapping (string $ mapping , int $ flags , int &$ i = 0 , array & $ references = [])
411
416
{
412
417
$ output = [];
413
418
$ len = \strlen ($ mapping );
@@ -433,14 +438,14 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
433
438
// key
434
439
$ offsetBeforeKeyParsing = $ i ;
435
440
$ isKeyQuoted = \in_array ($ mapping [$ i ], ['" ' , "' " ], true );
436
- $ key = self ::parseScalar ($ mapping , $ flags , [': ' , ' ' ], $ i , false , [] );
441
+ $ key = self ::parseScalar ($ mapping , $ flags , [': ' , ' ' ], $ i , false );
437
442
438
443
if ($ offsetBeforeKeyParsing === $ i ) {
439
444
throw new ParseException ('Missing mapping key. ' , self ::$ parsedLineNumber + 1 , $ mapping );
440
445
}
441
446
442
447
if ('!php/const ' === $ key ) {
443
- $ key .= ' ' .self ::parseScalar ($ mapping , $ flags , [': ' ], $ i , false , [] );
448
+ $ key .= ' ' .self ::parseScalar ($ mapping , $ flags , [': ' ], $ i , false );
444
449
$ key = sel
6D4E
f ::evaluateScalar ($ key , $ flags );
445
450
}
446
451
@@ -522,6 +527,11 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
522
527
if ('<< ' === $ key ) {
523
528
$ output += $ value ;
524
529
} elseif ($ allowOverwrite || !isset ($ output [$ key ])) {
530
+ if (\is_string ($ value ) && '' !== $ value && '& ' === $ value [0 ] && Parser::preg_match (Parser::REFERENCE_PATTERN , $ value , $ matches )) {
531
+ $ references [$ matches ['ref ' ]] = $ matches ['value ' ];
532
+ $ value = $ matches ['value ' ];
533
+ }
534
+
525
535
if (null !== $ tag ) {
526
536
$ output [$ key ] = new TaggedValue ($ tag , $ value );
527
537
} else {
@@ -548,7 +558,7 @@ private static function parseMapping(string $mapping, int $flags, int &$i = 0, a
548
558
*
549
559
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
550
560
*/
551
- private static function evaluateScalar (string $ scalar , int $ flags , array $ references = [])
561
+ private static function evaluateScalar (string $ scalar , int $ flags , array & $ references = [])
552
562
{
553
563
$ scalar = trim ($ scalar );
554
564
$ scalarLower = strtolower ($ scalar );
0 commit comments