Skip to content

Commit 4f0835c

Browse files
committed
[Yaml] added support for parsing PHP constants
1 parent db208e3 commit 4f0835c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Symfony/Component/Yaml/Inline.php

+2
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ private static function evaluateScalar($scalar, $flags, $references = array())
562562
}
563563

564564
return;
565+
case 0 === strpos($scalar, '!php/const:'):
566+
return @constant(substr($scalar, 11));
565567
case 0 === strpos($scalar, '!!float '):
566568
return (float) substr($scalar, 8);
567569
case ctype_digit($scalar):

src/Symfony/Component/Yaml/Tests/InlineTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ public function getTestsForParse()
349349

350350
array('[foo, bar: { foo: bar }]', array('foo', '1' => array('bar' => array('foo' => 'bar')))),
351351
array('[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']', array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%'), true, '@service_container')),
352+
353+
// constants
354+
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
355+
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
356+
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
357+
array('!php/const:WRONG_CONSTANT', null),
352358
);
353359
}
354360

0 commit comments

Comments
 (0)