composer update
This commit is contained in:
parent
9ac51e0523
commit
623395064f
279 changed files with 4458 additions and 16328 deletions
290
vendor/symfony/yaml/Inline.php
vendored
290
vendor/symfony/yaml/Inline.php
vendored
|
@ -18,33 +18,69 @@ use Symfony\Component\Yaml\Exception\DumpException;
|
|||
* Inline implements a YAML parser/dumper for the YAML inline syntax.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class Inline
|
||||
{
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\']*(?:\'\'[^\']*)*)\')';
|
||||
|
||||
public static $parsedLineNumber;
|
||||
|
||||
private static $exceptionOnInvalidType = false;
|
||||
private static $objectSupport = false;
|
||||
private static $objectForMap = false;
|
||||
private static $constantSupport = false;
|
||||
|
||||
/**
|
||||
* Converts a YAML string to a PHP array.
|
||||
* Converts a YAML string to a PHP value.
|
||||
*
|
||||
* @param string $value A YAML string
|
||||
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
|
||||
* @param bool $objectSupport true if object support is enabled, false otherwise
|
||||
* @param bool $objectForMap true if maps should return a stdClass instead of array()
|
||||
* @param array $references Mapping of variable names to values
|
||||
* @param string $value A YAML string
|
||||
* @param int $flags A bit field of PARSE_* constants to customize the YAML parser behavior
|
||||
* @param array $references Mapping of variable names to values
|
||||
*
|
||||
* @return array A PHP array representing the YAML string
|
||||
* @return mixed A PHP value
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false, $references = array())
|
||||
public static function parse($value, $flags = 0, $references = array())
|
||||
{
|
||||
self::$exceptionOnInvalidType = $exceptionOnInvalidType;
|
||||
self::$objectSupport = $objectSupport;
|
||||
self::$objectForMap = $objectForMap;
|
||||
if (is_bool($flags)) {
|
||||
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
|
||||
|
||||
if ($flags) {
|
||||
$flags = Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE;
|
||||
} else {
|
||||
$flags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (func_num_args() >= 3 && !is_array($references)) {
|
||||
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
|
||||
|
||||
if ($references) {
|
||||
$flags |= Yaml::PARSE_OBJECT;
|
||||
}
|
||||
|
||||
if (func_num_args() >= 4) {
|
||||
@trigger_error('Passing a boolean flag to toggle object for map support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED);
|
||||
|
||||
if (func_get_arg(3)) {
|
||||
$flags |= Yaml::PARSE_OBJECT_FOR_MAP;
|
||||
}
|
||||
}
|
||||
|
||||
if (func_num_args() >= 5) {
|
||||
$references = func_get_arg(4);
|
||||
} else {
|
||||
$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);
|
||||
|
||||
$value = trim($value);
|
||||
|
||||
|
@ -60,15 +96,15 @@ class Inline
|
|||
$i = 0;
|
||||
switch ($value[0]) {
|
||||
case '[':
|
||||
$result = self::parseSequence($value, $i, $references);
|
||||
$result = self::parseSequence($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
case '{':
|
||||
$result = self::parseMapping($value, $i, $references);
|
||||
$result = self::parseMapping($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
default:
|
||||
$result = self::parseScalar($value, null, array('"', "'"), $i, true, $references);
|
||||
$result = self::parseScalar($value, $flags, null, array('"', "'"), $i, true, $references);
|
||||
}
|
||||
|
||||
// some comments are allowed at the end
|
||||
|
@ -86,35 +122,58 @@ class Inline
|
|||
/**
|
||||
* Dumps a given PHP variable to a YAML string.
|
||||
*
|
||||
* @param mixed $value The PHP variable to convert
|
||||
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
|
||||
* @param bool $objectSupport true if object support is enabled, false otherwise
|
||||
* @param mixed $value The PHP variable to convert
|
||||
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||
*
|
||||
* @return string The YAML string representing the PHP array
|
||||
* @return string The YAML string representing the PHP value
|
||||
*
|
||||
* @throws DumpException When trying to dump PHP resource
|
||||
*/
|
||||
public static function dump($value, $exceptionOnInvalidType = false, $objectSupport = false)
|
||||
public static function dump($value, $flags = 0)
|
||||
{
|
||||
if (is_bool($flags)) {
|
||||
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
|
||||
|
||||
if ($flags) {
|
||||
$flags = Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE;
|
||||
} else {
|
||||
$flags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (func_num_args() >= 3) {
|
||||
@trigger_error('Passing a boolean flag to toggle object support is deprecated since version 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
|
||||
|
||||
if (func_get_arg(2)) {
|
||||
$flags |= Yaml::DUMP_OBJECT;
|
||||
}
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case is_resource($value):
|
||||
if ($exceptionOnInvalidType) {
|
||||
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
||||
throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
|
||||
}
|
||||
|
||||
return 'null';
|
||||
case $value instanceof \DateTimeInterface:
|
||||
return $value->format('c');
|
||||
case is_object($value):
|
||||
if ($objectSupport) {
|
||||
if (Yaml::DUMP_OBJECT & $flags) {
|
||||
return '!php/object:'.serialize($value);
|
||||
}
|
||||
|
||||
if ($exceptionOnInvalidType) {
|
||||
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
|
||||
return self::dumpArray((array) $value, $flags);
|
||||
}
|
||||
|
||||
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
|
||||
throw new DumpException('Object support when dumping a YAML file has been disabled.');
|
||||
}
|
||||
|
||||
return 'null';
|
||||
case is_array($value):
|
||||
return self::dumpArray($value, $exceptionOnInvalidType, $objectSupport);
|
||||
return self::dumpArray($value, $flags);
|
||||
case null === $value:
|
||||
return 'null';
|
||||
case true === $value:
|
||||
|
@ -146,9 +205,12 @@ class Inline
|
|||
return $repr;
|
||||
case '' == $value:
|
||||
return "''";
|
||||
case self::isBinaryString($value):
|
||||
return '!!binary '.base64_encode($value);
|
||||
case Escaper::requiresDoubleQuoting($value):
|
||||
return Escaper::escapeWithDoubleQuotes($value);
|
||||
case Escaper::requiresSingleQuoting($value):
|
||||
case preg_match('{^[0-9]+[_0-9]*$}', $value):
|
||||
case preg_match(self::getHexRegex(), $value):
|
||||
case preg_match(self::getTimestampRegex(), $value):
|
||||
return Escaper::escapeWithSingleQuotes($value);
|
||||
|
@ -157,57 +219,75 @@ class Inline
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given array is hash or just normal indexed array.
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param array $value The PHP array to check
|
||||
*
|
||||
* @return bool true if value is hash array, false otherwise
|
||||
*/
|
||||
public static function isHash(array $value)
|
||||
{
|
||||
$expectedKey = 0;
|
||||
|
||||
foreach ($value as $key => $val) {
|
||||
if ($key !== $expectedKey++) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps a PHP array to a YAML string.
|
||||
*
|
||||
* @param array $value The PHP array to dump
|
||||
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
|
||||
* @param bool $objectSupport true if object support is enabled, false otherwise
|
||||
* @param array $value The PHP array to dump
|
||||
* @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
|
||||
*
|
||||
* @return string The YAML string representing the PHP array
|
||||
*/
|
||||
private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport)
|
||||
private static function dumpArray($value, $flags)
|
||||
{
|
||||
// array
|
||||
$keys = array_keys($value);
|
||||
$keysCount = count($keys);
|
||||
if ((1 === $keysCount && '0' == $keys[0])
|
||||
|| ($keysCount > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) === $keysCount * ($keysCount - 1) / 2)
|
||||
) {
|
||||
if ($value && !self::isHash($value)) {
|
||||
$output = array();
|
||||
foreach ($value as $val) {
|
||||
$output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport);
|
||||
$output[] = self::dump($val, $flags);
|
||||
}
|
||||
|
||||
return sprintf('[%s]', implode(', ', $output));
|
||||
}
|
||||
|
||||
// mapping
|
||||
// hash
|
||||
$output = array();
|
||||
foreach ($value as $key => $val) {
|
||||
$output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport));
|
||||
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
|
||||
}
|
||||
|
||||
return sprintf('{ %s }', implode(', ', $output));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a scalar to a YAML string.
|
||||
* Parses a YAML scalar.
|
||||
*
|
||||
* @param string $scalar
|
||||
* @param int $flags
|
||||
* @param string $delimiters
|
||||
* @param array $stringDelimiters
|
||||
* @param int &$i
|
||||
* @param bool $evaluate
|
||||
* @param array $references
|
||||
*
|
||||
* @return string A YAML string
|
||||
* @return string
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function parseScalar($scalar, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true, $references = array())
|
||||
public static function parseScalar($scalar, $flags = 0, $delimiters = null, $stringDelimiters = array('"', "'"), &$i = 0, $evaluate = true, $references = array())
|
||||
{
|
||||
if (in_array($scalar[$i], $stringDelimiters)) {
|
||||
// quoted scalar
|
||||
|
@ -233,7 +313,7 @@ class Inline
|
|||
$output = $match[1];
|
||||
$i += strlen($output);
|
||||
} else {
|
||||
throw new ParseException(sprintf('Malformed inline YAML string (%s).', $scalar));
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar));
|
||||
}
|
||||
|
||||
// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
|
||||
|
@ -241,8 +321,12 @@ class Inline
|
|||
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]));
|
||||
}
|
||||
|
||||
if ($output && '%' === $output[0]) {
|
||||
@trigger_error(sprintf('Not quoting the scalar "%s" starting with the "%%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0.', $output), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if ($evaluate) {
|
||||
$output = self::evaluateScalar($output, $references);
|
||||
$output = self::evaluateScalar($output, $flags, $references);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,19 +334,19 @@ class Inline
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses a quoted scalar to YAML.
|
||||
* Parses a YAML quoted scalar.
|
||||
*
|
||||
* @param string $scalar
|
||||
* @param int &$i
|
||||
*
|
||||
* @return string A YAML string
|
||||
* @return string
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseQuotedScalar($scalar, &$i)
|
||||
{
|
||||
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
||||
throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)));
|
||||
}
|
||||
|
||||
$output = substr($match[0], 1, strlen($match[0]) - 2);
|
||||
|
@ -280,17 +364,18 @@ class Inline
|
|||
}
|
||||
|
||||
/**
|
||||
* Parses a sequence to a YAML string.
|
||||
* Parses a YAML sequence.
|
||||
*
|
||||
* @param string $sequence
|
||||
* @param int $flags
|
||||
* @param int &$i
|
||||
* @param array $references
|
||||
*
|
||||
* @return string A YAML string
|
||||
* @return array
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseSequence($sequence, &$i = 0, $references = array())
|
||||
private static function parseSequence($sequence, $flags, &$i = 0, $references = array())
|
||||
{
|
||||
$output = array();
|
||||
$len = strlen($sequence);
|
||||
|
@ -301,11 +386,11 @@ class Inline
|
|||
switch ($sequence[$i]) {
|
||||
case '[':
|
||||
// nested sequence
|
||||
$output[] = self::parseSequence($sequence, $i, $references);
|
||||
$output[] = self::parseSequence($sequence, $flags, $i, $references);
|
||||
break;
|
||||
case '{':
|
||||
// nested mapping
|
||||
$output[] = self::parseMapping($sequence, $i, $references);
|
||||
$output[] = self::parseMapping($sequence, $flags, $i, $references);
|
||||
break;
|
||||
case ']':
|
||||
return $output;
|
||||
|
@ -314,14 +399,14 @@ class Inline
|
|||
break;
|
||||
default:
|
||||
$isQuoted = in_array($sequence[$i], array('"', "'"));
|
||||
$value = self::parseScalar($sequence, array(',', ']'), array('"', "'"), $i, true, $references);
|
||||
$value = self::parseScalar($sequence, $flags, array(',', ']'), array('"', "'"), $i, true, $references);
|
||||
|
||||
// the value can be an array if a reference has been resolved to an array var
|
||||
if (!is_array($value) && !$isQuoted && false !== strpos($value, ': ')) {
|
||||
if (is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
|
||||
// embedded mapping?
|
||||
try {
|
||||
$pos = 0;
|
||||
$value = self::parseMapping('{'.$value.'}', $pos, $references);
|
||||
$value = self::parseMapping('{'.$value.'}', $flags, $pos, $references);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
// no, it's not
|
||||
}
|
||||
|
@ -335,21 +420,22 @@ class Inline
|
|||
++$i;
|
||||
}
|
||||
|
||||
throw new ParseException(sprintf('Malformed inline YAML string %s', $sequence));
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a mapping to a YAML string.
|
||||
* Parses a YAML mapping.
|
||||
*
|
||||
* @param string $mapping
|
||||
* @param int $flags
|
||||
* @param int &$i
|
||||
* @param array $references
|
||||
*
|
||||
* @return string A YAML string
|
||||
* @return array|\stdClass
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseMapping($mapping, &$i = 0, $references = array())
|
||||
private static function parseMapping($mapping, $flags, &$i = 0, $references = array())
|
||||
{
|
||||
$output = array();
|
||||
$len = strlen($mapping);
|
||||
|
@ -371,7 +457,15 @@ class Inline
|
|||
}
|
||||
|
||||
// key
|
||||
$key = self::parseScalar($mapping, array(':', ' '), array('"', "'"), $i, false);
|
||||
$key = self::parseScalar($mapping, $flags, array(':', ' '), array('"', "'"), $i, false);
|
||||
|
||||
if (false === $i = strpos($mapping, ':', $i)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isset($mapping[$i + 1]) || !in_array($mapping[$i + 1], array(' ', '[', ']', '{', '}'), true)) {
|
||||
@trigger_error('Using a colon that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}" is deprecated since version 3.2 and will throw a ParseException in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
// value
|
||||
$done = false;
|
||||
|
@ -380,23 +474,27 @@ class Inline
|
|||
switch ($mapping[$i]) {
|
||||
case '[':
|
||||
// nested sequence
|
||||
$value = self::parseSequence($mapping, $i, $references);
|
||||
$value = self::parseSequence($mapping, $flags, $i, $references);
|
||||
// Spec: Keys MUST be unique; first one wins.
|
||||
// Parser cannot abort this mapping earlier, since lines
|
||||
// are processed sequentially.
|
||||
if (!isset($output[$key])) {
|
||||
$output[$key] = $value;
|
||||
} else {
|
||||
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
|
||||
}
|
||||
$done = true;
|
||||
break;
|
||||
case '{':
|
||||
// nested mapping
|
||||
$value = self::parseMapping($mapping, $i, $references);
|
||||
$value = self::parseMapping($mapping, $flags, $i, $references);
|
||||
// Spec: Keys MUST be unique; first one wins.
|
||||
// Parser cannot abort this mapping earlier, since lines
|
||||
// are processed sequentially.
|
||||
if (!isset($output[$key])) {
|
||||
$output[$key] = $value;
|
||||
} else {
|
||||
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
|
||||
}
|
||||
$done = true;
|
||||
break;
|
||||
|
@ -404,12 +502,14 @@ class Inline
|
|||
case ' ':
|
||||
break;
|
||||
default:
|
||||
$value = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i, true, $references);
|
||||
$value = self::parseScalar($mapping, $flags, array(',', '}'), array('"', "'"), $i, true, $references);
|
||||
// Spec: Keys MUST be unique; first one wins.
|
||||
// Parser cannot abort this mapping earlier, since lines
|
||||
// are processed sequentially.
|
||||
if (!isset($output[$key])) {
|
||||
$output[$key] = $value;
|
||||
} else {
|
||||
@trigger_error(sprintf('Duplicate key "%s" detected on line %d whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since version 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key, self::$parsedLineNumber + 1), E_USER_DEPRECATED);
|
||||
}
|
||||
$done = true;
|
||||
--$i;
|
||||
|
@ -423,20 +523,21 @@ class Inline
|
|||
}
|
||||
}
|
||||
|
||||
throw new ParseException(sprintf('Malformed inline YAML string %s', $mapping));
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping));
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates scalars and replaces magic values.
|
||||
*
|
||||
* @param string $scalar
|
||||
* @param int $flags
|
||||
* @param array $references
|
||||
*
|
||||
* @return string A YAML string
|
||||
*
|
||||
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object or when a reference could not be resolved
|
||||
*/
|
||||
private static function evaluateScalar($scalar, $references = array())
|
||||
private static function evaluateScalar($scalar, $flags, $references = array())
|
||||
{
|
||||
$scalar = trim($scalar);
|
||||
$scalarLower = strtolower($scalar);
|
||||
|
@ -475,7 +576,7 @@ class Inline
|
|||
case 0 === strpos($scalar, '!str'):
|
||||
return (string) substr($scalar, 5);
|
||||
case 0 === strpos($scalar, '! '):
|
||||
return (int) self::parseScalar(substr($scalar, 2));
|
||||
return (int) self::parseScalar(substr($scalar, 2), $flags);
|
||||
case 0 === strpos($scalar, '!php/object:'):
|
||||
if (self::$objectSupport) {
|
||||
return unserialize(substr($scalar, 12));
|
||||
|
@ -488,6 +589,8 @@ class Inline
|
|||
return;
|
||||
case 0 === strpos($scalar, '!!php/object:'):
|
||||
if (self::$objectSupport) {
|
||||
@trigger_error('The !!php/object tag to indicate dumped PHP objects is deprecated since version 3.1 and will be removed in 4.0. Use the !php/object tag instead.', E_USER_DEPRECATED);
|
||||
|
||||
return unserialize(substr($scalar, 13));
|
||||
}
|
||||
|
||||
|
@ -495,9 +598,25 @@ class Inline
|
|||
throw new ParseException('Object support when parsing a YAML file has been disabled.');
|
||||
}
|
||||
|
||||
return;
|
||||
case 0 === strpos($scalar, '!php/const:'):
|
||||
if (self::$constantSupport) {
|
||||
if (defined($const = substr($scalar, 11))) {
|
||||
return constant($const);
|
||||
}
|
||||
|
||||
throw new ParseException(sprintf('The constant "%s" is not defined.', $const));
|
||||
}
|
||||
if (self::$exceptionOnInvalidType) {
|
||||
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Have you forgotten to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar));
|
||||
}
|
||||
|
||||
return;
|
||||
case 0 === strpos($scalar, '!!float '):
|
||||
return (float) substr($scalar, 8);
|
||||
case preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar):
|
||||
$scalar = str_replace('_', '', (string) $scalar);
|
||||
// omitting the break / return as integers are handled in the next case
|
||||
case ctype_digit($scalar):
|
||||
$raw = $scalar;
|
||||
$cast = (int) $scalar;
|
||||
|
@ -510,15 +629,29 @@ class Inline
|
|||
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw);
|
||||
case is_numeric($scalar):
|
||||
case preg_match(self::getHexRegex(), $scalar):
|
||||
$scalar = str_replace('_', '', $scalar);
|
||||
|
||||
return '0x' === $scalar[0].$scalar[1] ? hexdec($scalar) : (float) $scalar;
|
||||
case '.inf' === $scalarLower:
|
||||
case '.nan' === $scalarLower:
|
||||
return -log(0);
|
||||
case '-.inf' === $scalarLower:
|
||||
return log(0);
|
||||
case preg_match('/^(-|\+)?[0-9,]+(\.[0-9]+)?$/', $scalar):
|
||||
return (float) str_replace(',', '', $scalar);
|
||||
case 0 === strpos($scalar, '!!binary '):
|
||||
return self::evaluateBinaryScalar(substr($scalar, 9));
|
||||
case preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
|
||||
case preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
|
||||
if (false !== strpos($scalar, ',')) {
|
||||
@trigger_error('Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return (float) str_replace(array(',', '_'), '', $scalar);
|
||||
case preg_match(self::getTimestampRegex(), $scalar):
|
||||
if (Yaml::PARSE_DATETIME & $flags) {
|
||||
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
|
||||
return new \DateTime($scalar, new \DateTimeZone('UTC'));
|
||||
}
|
||||
|
||||
$timeZone = date_default_timezone_get();
|
||||
date_default_timezone_set('UTC');
|
||||
$time = strtotime($scalar);
|
||||
|
@ -531,6 +664,33 @@ class Inline
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $scalar
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function evaluateBinaryScalar($scalar)
|
||||
{
|
||||
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
||||
|
||||
if (0 !== (strlen($parsedBinaryData) % 4)) {
|
||||
throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', strlen($parsedBinaryData)));
|
||||
}
|
||||
|
||||
if (!preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) {
|
||||
throw new ParseException(sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData));
|
||||
}
|
||||
|
||||
return base64_decode($parsedBinaryData, true);
|
||||
}
|
||||
|
||||
private static function isBinaryString($value)
|
||||
{
|
||||
return !preg_match('//u', $value) || preg_match('/[^\x09-\x0d\x20-\xff]/', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a regex that matches a YAML date.
|
||||
*
|
||||
|
@ -563,6 +723,6 @@ EOF;
|
|||
*/
|
||||
private static function getHexRegex()
|
||||
{
|
||||
return '~^0x[0-9a-f]++$~i';
|
||||
return '~^0x[0-9a-f_]++$~i';
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue