From 1be23c2a86e98e2f7f45917090c2d7f9e519358c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 1 Sep 2017 08:00:27 +0200 Subject: [PATCH] [Yaml] add inline parser context initializer Calling the parser to initialize some internal context does not look like a good idea. Additionally, this change allows to not accept null values in `Inline::parse()` in 3.4 anymore. --- src/Symfony/Component/Yaml/Inline.php | 21 +++++++++++++++++---- src/Symfony/Component/Yaml/Parser.php | 4 +--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index c78c811baa5a7..fee21eb34ecc2 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -33,6 +33,22 @@ class Inline private static $objectForMap = false; private static $constantSupport = false; + /** + * @param int $flags + * @param int|null $parsedLineNumber + */ + public static function initialize($flags, $parsedLineNumber = null) + { + self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags); + self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags); + self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags); + self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags); + + if (null !== $parsedLineNumber) { + self::$parsedLineNumber = $parsedLineNumber; + } + } + /** * Converts a YAML string to a PHP value. * @@ -78,10 +94,7 @@ public static function parse($value, $flags = 0, $references = array()) } } - self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags); - self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags); - self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags); - self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags); + self::initialize($flags); $value = trim($value); diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index b39512c869d14..042d9d186d273 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -222,10 +222,8 @@ private function doParse($value, $flags) } $context = 'mapping'; - // force correct settings - Inline::parse(null, $flags, $this->refs); + Inline::initialize($flags, $this->getRealCurrentLineNb()); try { - Inline::$parsedLineNumber = $this->getRealCurrentLineNb(); $i = 0; $evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags);