updated-packages
This commit is contained in:
245
vendor/symfony/yaml/Inline.php
vendored
245
vendor/symfony/yaml/Inline.php
vendored
@@ -24,7 +24,7 @@ use Symfony\Component\Yaml\Tag\TaggedValue;
|
||||
*/
|
||||
class Inline
|
||||
{
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';
|
||||
public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*+(?:\\\\.[^"\\\\]*+)*+)"|\'([^\']*+(?:\'\'[^\']*+)*+)\')';
|
||||
|
||||
public static $parsedLineNumber = -1;
|
||||
public static $parsedFilename;
|
||||
@@ -34,12 +34,7 @@ class Inline
|
||||
private static $objectForMap = false;
|
||||
private static $constantSupport = false;
|
||||
|
||||
/**
|
||||
* @param int $flags
|
||||
* @param int|null $parsedLineNumber
|
||||
* @param string|null $parsedFilename
|
||||
*/
|
||||
public static function initialize($flags, $parsedLineNumber = null, $parsedFilename = null)
|
||||
public static function initialize(int $flags, int $parsedLineNumber = null, string $parsedFilename = null)
|
||||
{
|
||||
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
||||
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
||||
@@ -63,7 +58,7 @@ class Inline
|
||||
*
|
||||
* @throws ParseException
|
||||
*/
|
||||
public static function parse(string $value = null, int $flags = 0, array $references = array())
|
||||
public static function parse(string $value = null, int $flags = 0, array &$references = [])
|
||||
{
|
||||
self::initialize($flags);
|
||||
|
||||
@@ -73,40 +68,42 @@ class Inline
|
||||
return '';
|
||||
}
|
||||
|
||||
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
|
||||
if (2 /* MB_OVERLOAD_STRING */ & (int) \ini_get('mbstring.func_overload')) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('ASCII');
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$tag = self::parseTag($value, $i, $flags);
|
||||
switch ($value[$i]) {
|
||||
case '[':
|
||||
$result = self::parseSequence($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
case '{':
|
||||
$result = self::parseMapping($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
default:
|
||||
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
|
||||
}
|
||||
try {
|
||||
$i = 0;
|
||||
$tag = self::parseTag($value, $i, $flags);
|
||||
switch ($value[$i]) {
|
||||
case '[':
|
||||
$result = self::parseSequence($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
case '{':
|
||||
$result = self::parseMapping($value, $flags, $i, $references);
|
||||
++$i;
|
||||
break;
|
||||
default:
|
||||
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
|
||||
}
|
||||
|
||||
if (null !== $tag && '' !== $tag) {
|
||||
return new TaggedValue($tag, $result);
|
||||
}
|
||||
// some comments are allowed at the end
|
||||
if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
|
||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
// some comments are allowed at the end
|
||||
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
if (null !== $tag && '' !== $tag) {
|
||||
return new TaggedValue($tag, $result);
|
||||
}
|
||||
|
||||
if (isset($mbEncoding)) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
return $result;
|
||||
} finally {
|
||||
if (isset($mbEncoding)) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,9 +124,11 @@ class Inline
|
||||
throw new DumpException(sprintf('Unable to dump PHP resources in a YAML file ("%s").', get_resource_type($value)));
|
||||
}
|
||||
|
||||
return 'null';
|
||||
return self::dumpNull($flags);
|
||||
case $value instanceof \DateTimeInterface:
|
||||
return $value->format('c');
|
||||
case $value instanceof \UnitEnum:
|
||||
return sprintf('!php/const %s::%s', \get_class($value), $value->name);
|
||||
case \is_object($value):
|
||||
if ($value instanceof TaggedValue) {
|
||||
return '!'.$value->getTag().' '.self::dump($value->getValue(), $flags);
|
||||
@@ -140,7 +139,7 @@ class Inline
|
||||
}
|
||||
|
||||
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
|
||||
$output = array();
|
||||
$output = [];
|
||||
|
||||
foreach ($value as $key => $val) {
|
||||
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
|
||||
@@ -153,21 +152,21 @@ class Inline
|
||||
throw new DumpException('Object support when dumping a YAML file has been disabled.');
|
||||
}
|
||||
|
||||
return 'null';
|
||||
return self::dumpNull($flags);
|
||||
case \is_array($value):
|
||||
return self::dumpArray($value, $flags);
|
||||
case null === $value:
|
||||
return 'null';
|
||||
return self::dumpNull($flags);
|
||||
case true === $value:
|
||||
return 'true';
|
||||
case false === $value:
|
||||
return 'false';
|
||||
case ctype_digit($value):
|
||||
return \is_string($value) ? "'$value'" : (int) $value;
|
||||
case is_numeric($value):
|
||||
$locale = setlocale(LC_NUMERIC, 0);
|
||||
case \is_int($value):
|
||||
return $value;
|
||||
case is_numeric($value) && false === strpbrk($value, "\f\n\r\t\v"):
|
||||
$locale = setlocale(\LC_NUMERIC, 0);
|
||||
if (false !== $locale) {
|
||||
setlocale(LC_NUMERIC, 'C');
|
||||
setlocale(\LC_NUMERIC, 'C');
|
||||
}
|
||||
if (\is_float($value)) {
|
||||
$repr = (string) $value;
|
||||
@@ -181,7 +180,7 @@ class Inline
|
||||
$repr = \is_string($value) ? "'$value'" : (string) $value;
|
||||
}
|
||||
if (false !== $locale) {
|
||||
setlocale(LC_NUMERIC, $locale);
|
||||
setlocale(\LC_NUMERIC, $locale);
|
||||
}
|
||||
|
||||
return $repr;
|
||||
@@ -237,7 +236,7 @@ class Inline
|
||||
{
|
||||
// array
|
||||
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
|
||||
$output = array();
|
||||
$output = [];
|
||||
foreach ($value as $val) {
|
||||
$output[] = self::dump($val, $flags);
|
||||
}
|
||||
@@ -246,7 +245,7 @@ class Inline
|
||||
}
|
||||
|
||||
// hash
|
||||
$output = array();
|
||||
$output = [];
|
||||
foreach ($value as $key => $val) {
|
||||
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
|
||||
}
|
||||
@@ -254,6 +253,15 @@ class Inline
|
||||
return sprintf('{ %s }', implode(', ', $output));
|
||||
}
|
||||
|
||||
private static function dumpNull(int $flags): string
|
||||
{
|
||||
if (Yaml::DUMP_NULL_AS_TILDE & $flags) {
|
||||
return '~';
|
||||
}
|
||||
|
||||
return 'null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a YAML scalar.
|
||||
*
|
||||
@@ -261,14 +269,15 @@ class Inline
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = array())
|
||||
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array &$references = [], bool &$isQuoted = null)
|
||||
{
|
||||
if (\in_array($scalar[$i], array('"', "'"))) {
|
||||
if (\in_array($scalar[$i], ['"', "'"])) {
|
||||
// quoted scalar
|
||||
$isQuoted = true;
|
||||
$output = self::parseQuotedScalar($scalar, $i);
|
||||
|
||||
if (null !== $delimiters) {
|
||||
$tmp = ltrim(substr($scalar, $i), ' ');
|
||||
$tmp = ltrim(substr($scalar, $i), " \n");
|
||||
if ('' === $tmp) {
|
||||
throw new ParseException(sprintf('Unexpected end of line, expected one of "%s".', implode('', $delimiters)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
}
|
||||
@@ -278,12 +287,14 @@ class Inline
|
||||
}
|
||||
} else {
|
||||
// "normal" string
|
||||
$isQuoted = false;
|
||||
|
||||
if (!$delimiters) {
|
||||
$output = substr($scalar, $i);
|
||||
$i += \strlen($output);
|
||||
|
||||
// remove comments
|
||||
if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
|
||||
if (Parser::preg_match('/[ \t]+#/', $output, $match, \PREG_OFFSET_CAPTURE)) {
|
||||
$output = substr($output, 0, $match[0][1]);
|
||||
}
|
||||
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
|
||||
@@ -291,7 +302,7 @@ class Inline
|
||||
$i += \strlen($output);
|
||||
$output = trim($output);
|
||||
} else {
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $scalar), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
}
|
||||
|
||||
// a non-quoted string cannot start with @ or ` (reserved) nor with a scalar indicator (| or >)
|
||||
@@ -300,7 +311,7 @@ class Inline
|
||||
}
|
||||
|
||||
if ($evaluate) {
|
||||
$output = self::evaluateScalar($output, $flags, $references);
|
||||
$output = self::evaluateScalar($output, $flags, $references, $isQuoted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,10 +323,10 @@ class Inline
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseQuotedScalar(string $scalar, int &$i): string
|
||||
private static function parseQuotedScalar(string $scalar, int &$i = 0): string
|
||||
{
|
||||
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
}
|
||||
|
||||
$output = substr($match[0], 1, \strlen($match[0]) - 2);
|
||||
@@ -337,9 +348,9 @@ class Inline
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = array()): array
|
||||
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array &$references = []): array
|
||||
{
|
||||
$output = array();
|
||||
$output = [];
|
||||
$len = \strlen($sequence);
|
||||
++$i;
|
||||
|
||||
@@ -365,8 +376,7 @@ class Inline
|
||||
$value = self::parseMapping($sequence, $flags, $i, $references);
|
||||
break;
|
||||
default:
|
||||
$isQuoted = \in_array($sequence[$i], array('"', "'"));
|
||||
$value = self::parseScalar($sequence, $flags, array(',', ']'), $i, null === $tag, $references);
|
||||
$value = self::parseScalar($sequence, $flags, [',', ']'], $i, null === $tag, $references, $isQuoted);
|
||||
|
||||
// the value can be an array if a reference has been resolved to an array var
|
||||
if (\is_string($value) && !$isQuoted && false !== strpos($value, ': ')) {
|
||||
@@ -379,6 +389,11 @@ class Inline
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
|
||||
$references[$matches['ref']] = $matches['value'];
|
||||
$value = $matches['value'];
|
||||
}
|
||||
|
||||
--$i;
|
||||
}
|
||||
|
||||
@@ -391,7 +406,7 @@ class Inline
|
||||
++$i;
|
||||
}
|
||||
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,9 +416,9 @@ class Inline
|
||||
*
|
||||
* @throws ParseException When malformed inline YAML string is parsed
|
||||
*/
|
||||
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = array())
|
||||
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array &$references = [])
|
||||
{
|
||||
$output = array();
|
||||
$output = [];
|
||||
$len = \strlen($mapping);
|
||||
++$i;
|
||||
$allowOverwrite = false;
|
||||
@@ -413,6 +428,7 @@ class Inline
|
||||
switch ($mapping[$i]) {
|
||||
case ' ':
|
||||
case ',':
|
||||
case "\n":
|
||||
++$i;
|
||||
continue 2;
|
||||
case '}':
|
||||
@@ -425,13 +441,18 @@ class Inline
|
||||
|
||||
// key
|
||||
$offsetBeforeKeyParsing = $i;
|
||||
$isKeyQuoted = \in_array($mapping[$i], array('"', "'"), true);
|
||||
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array());
|
||||
$isKeyQuoted = \in_array($mapping[$i], ['"', "'"], true);
|
||||
$key = self::parseScalar($mapping, $flags, [':', ' '], $i, false);
|
||||
|
||||
if ($offsetBeforeKeyParsing === $i) {
|
||||
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
|
||||
}
|
||||
|
||||
if ('!php/const' === $key) {
|
||||
$key .= ' '.self::parseScalar($mapping, $flags, [':'], $i, false);
|
||||
$key = self::evaluateScalar($key, $flags);
|
||||
}
|
||||
|
||||
if (false === $i = strpos($mapping, ':', $i)) {
|
||||
break;
|
||||
}
|
||||
@@ -444,7 +465,7 @@ class Inline
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
|
||||
if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], [' ', ',', '[', ']', '{', '}', "\n"], true))) {
|
||||
throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping);
|
||||
}
|
||||
|
||||
@@ -453,7 +474,7 @@ class Inline
|
||||
}
|
||||
|
||||
while ($i < $len) {
|
||||
if (':' === $mapping[$i] || ' ' === $mapping[$i]) {
|
||||
if (':' === $mapping[$i] || ' ' === $mapping[$i] || "\n" === $mapping[$i]) {
|
||||
++$i;
|
||||
|
||||
continue;
|
||||
@@ -502,7 +523,7 @@ class Inline
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$value = self::parseScalar($mapping, $flags, array(',', '}'), $i, null === $tag, $references);
|
||||
$value = self::parseScalar($mapping, $flags, [',', '}', "\n"], $i, null === $tag, $references, $isValueQuoted);
|
||||
// Spec: Keys MUST be unique; first one wins.
|
||||
// Parser cannot abort this mapping earlier, since lines
|
||||
// are processed sequentially.
|
||||
@@ -510,6 +531,11 @@ class Inline
|
||||
if ('<<' === $key) {
|
||||
$output += $value;
|
||||
} elseif ($allowOverwrite || !isset($output[$key])) {
|
||||
if (!$isValueQuoted && \is_string($value) && '' !== $value && '&' === $value[0] && Parser::preg_match(Parser::REFERENCE_PATTERN, $value, $matches)) {
|
||||
$references[$matches['ref']] = $matches['value'];
|
||||
$value = $matches['value'];
|
||||
}
|
||||
|
||||
if (null !== $tag) {
|
||||
$output[$key] = new TaggedValue($tag, $value);
|
||||
} else {
|
||||
@@ -526,7 +552,7 @@ class Inline
|
||||
}
|
||||
}
|
||||
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
throw new ParseException(sprintf('Malformed inline YAML string: "%s".', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -536,8 +562,9 @@ class Inline
|
||||
*
|
||||
* @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(string $scalar, int $flags, array $references = array())
|
||||
private static function evaluateScalar(string $scalar, int $flags, array &$references = [], bool &$isQuotedString = null)
|
||||
{
|
||||
$isQuotedString = false;
|
||||
$scalar = trim($scalar);
|
||||
$scalarLower = strtolower($scalar);
|
||||
|
||||
@@ -553,7 +580,7 @@ class Inline
|
||||
throw new ParseException('A reference must contain at least one character.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
if (!array_key_exists($value, $references)) {
|
||||
if (!\array_key_exists($value, $references)) {
|
||||
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
@@ -564,7 +591,7 @@ class Inline
|
||||
case 'null' === $scalarLower:
|
||||
case '' === $scalar:
|
||||
case '~' === $scalar:
|
||||
return;
|
||||
return null;
|
||||
case 'true' === $scalarLower:
|
||||
return true;
|
||||
case 'false' === $scalarLower:
|
||||
@@ -572,11 +599,22 @@ class Inline
|
||||
case '!' === $scalar[0]:
|
||||
switch (true) {
|
||||
case 0 === strpos($scalar, '!!str '):
|
||||
return (string) substr($scalar, 6);
|
||||
$s = (string) substr($scalar, 6);
|
||||
|
||||
if (\in_array($s[0] ?? '', ['"', "'"], true)) {
|
||||
$isQuotedString = true;
|
||||
$s = self::parseQuotedScalar($s);
|
||||
}
|
||||
|
||||
return $s;
|
||||
case 0 === strpos($scalar, '! '):
|
||||
return substr($scalar, 2);
|
||||
case 0 === strpos($scalar, '!php/object'):
|
||||
if (self::$objectSupport) {
|
||||
if (!isset($scalar[12])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return unserialize(self::parseScalar(substr($scalar, 12)));
|
||||
}
|
||||
|
||||
@@ -584,9 +622,13 @@ class Inline
|
||||
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
}
|
||||
|
||||
return;
|
||||
return null;
|
||||
case 0 === strpos($scalar, '!php/const'):
|
||||
if (self::$constantSupport) {
|
||||
if (!isset($scalar[11])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
if (\defined($const = self::parseScalar(substr($scalar, 11), 0, null, $i, false))) {
|
||||
return \constant($const);
|
||||
@@ -595,10 +637,10 @@ class Inline
|
||||
throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
}
|
||||
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), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
throw new ParseException(sprintf('The string "%s" could not be parsed as a constant. Did you forget to pass the "Yaml::PARSE_CONSTANT" flag to the parser?', $scalar), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||
}
|
||||
|
||||
return;
|
||||
return null;
|
||||
case 0 === strpos($scalar, '!!float '):
|
||||
return (float) substr($scalar, 8);
|
||||
case 0 === strpos($scalar, '!!binary '):
|
||||
@@ -610,21 +652,27 @@ class Inline
|
||||
// Optimize for returning strings.
|
||||
// no break
|
||||
case '+' === $scalar[0] || '-' === $scalar[0] || '.' === $scalar[0] || is_numeric($scalar[0]):
|
||||
if (Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar)) {
|
||||
$scalar = str_replace('_', '', $scalar);
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case Parser::preg_match('{^[+-]?[0-9][0-9_]*$}', $scalar):
|
||||
$scalar = str_replace('_', '', (string) $scalar);
|
||||
// omitting the break / return as integers are handled in the next case
|
||||
// no break
|
||||
case ctype_digit($scalar):
|
||||
$raw = $scalar;
|
||||
if (preg_match('/^0[0-7]+$/', $scalar)) {
|
||||
return octdec($scalar);
|
||||
}
|
||||
|
||||
$cast = (int) $scalar;
|
||||
|
||||
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
|
||||
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
|
||||
$raw = $scalar;
|
||||
if (preg_match('/^-0[0-7]+$/', $scalar)) {
|
||||
return -octdec(substr($scalar, 1));
|
||||
}
|
||||
|
||||
$cast = (int) $scalar;
|
||||
|
||||
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw === (string) $cast) ? $cast : $raw);
|
||||
return ($scalar === (string) $cast) ? $cast : $scalar;
|
||||
case is_numeric($scalar):
|
||||
case Parser::preg_match(self::getHexRegex(), $scalar):
|
||||
$scalar = str_replace('_', '', $scalar);
|
||||
@@ -638,17 +686,22 @@ class Inline
|
||||
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
|
||||
return (float) str_replace('_', '', $scalar);
|
||||
case Parser::preg_match(self::getTimestampRegex(), $scalar):
|
||||
// When no timezone is provided in the parsed date, YAML spec says we must assume UTC.
|
||||
$time = new \DateTime($scalar, new \DateTimeZone('UTC'));
|
||||
|
||||
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'));
|
||||
return $time;
|
||||
}
|
||||
|
||||
$timeZone = date_default_timezone_get();
|
||||
date_default_timezone_set('UTC');
|
||||
$time = strtotime($scalar);
|
||||
date_default_timezone_set($timeZone);
|
||||
try {
|
||||
if (false !== $scalar = $time->getTimestamp()) {
|
||||
return $scalar;
|
||||
}
|
||||
} catch (\ValueError $e) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
return $time;
|
||||
return $time->format('U');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,8 +720,12 @@ class Inline
|
||||
$nextOffset = $i + $tagLength + 1;
|
||||
$nextOffset += strspn($value, ' ', $nextOffset);
|
||||
|
||||
if ('' === $tag && (!isset($value[$nextOffset]) || \in_array($value[$nextOffset], [']', '}', ','], true))) {
|
||||
throw new ParseException('Using the unquoted scalar value "!" is not supported. You must quote it.', self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
// Is followed by a scalar and is a built-in tag
|
||||
if ($tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], array('[', '{'), true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
|
||||
if ('' !== $tag && (!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], ['[', '{'], true)) && ('!' === $tag[0] || 'str' === $tag || 'php/const' === $tag || 'php/object' === $tag)) {
|
||||
// Manage in {@link self::evaluateScalar()}
|
||||
return null;
|
||||
}
|
||||
@@ -676,10 +733,14 @@ class Inline
|
||||
$i = $nextOffset;
|
||||
|
||||
// Built-in tags
|
||||
if ($tag && '!' === $tag[0]) {
|
||||
if ('' !== $tag && '!' === $tag[0]) {
|
||||
throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
if ('' !== $tag && !isset($value[$i])) {
|
||||
throw new ParseException(sprintf('Missing value for tag "%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
if ('' === $tag || Yaml::PARSE_CUSTOM_TAGS & $flags) {
|
||||
return $tag;
|
||||
}
|
||||
@@ -734,8 +795,6 @@ EOF;
|
||||
|
||||
/**
|
||||
* Gets a regex that matches a YAML number in hexadecimal notation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getHexRegex(): string
|
||||
{
|
||||
|
Reference in New Issue
Block a user