[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.
This commit is contained in:
Christian Flothmann 2017-09-01 08:00:27 +02:00
parent 0beb598a7b
commit 1be23c2a86
2 changed files with 18 additions and 7 deletions

View File

@ -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 @@ class Inline
}
}
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);

View File

@ -222,10 +222,8 @@ class Parser
}
$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);