Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -1,6 +1,36 @@
CHANGELOG
=========
4.0.0
-----
* The behavior of the non-specific tag `!` is changed and now forces
non-evaluating your values.
* complex mappings will throw a `ParseException`
* support for the comma as a group separator for floats has been dropped, use
the underscore instead
* support for the `!!php/object` tag has been dropped, use the `!php/object`
tag instead
* duplicate mapping keys throw a `ParseException`
* non-string mapping keys throw a `ParseException`, use the `Yaml::PARSE_KEYS_AS_STRINGS`
flag to cast them to strings
* `%` at the beginning of an unquoted string throw a `ParseException`
* mappings with a colon (`:`) that is not followed by a whitespace throw a
`ParseException`
* the `Dumper::setIndentation()` method has been removed
* being able to pass boolean options to the `Yaml::parse()`, `Yaml::dump()`,
`Parser::parse()`, and `Dumper::dump()` methods to configure the behavior of
the parser and dumper is no longer supported, pass bitmask flags instead
* the constructor arguments of the `Parser` class have been removed
* the `Inline` class is internal and no longer part of the BC promise
* removed support for the `!str` tag, use the `!!str` tag instead
* added support for tagged scalars.
```yml
Yaml::parse('!foo bar', Yaml::PARSE_CUSTOM_TAGS);
// returns TaggedValue('foo', 'bar');
```
3.4.0
-----

View File

@@ -38,7 +38,7 @@ class LintCommand extends Command
private $directoryIteratorProvider;
private $isReadableProvider;
public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null)
{
parent::__construct($name);

View File

@@ -16,7 +16,7 @@ namespace Symfony\Component\Yaml;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since version 3.4
* @final
*/
class Dumper
{
@@ -27,10 +27,7 @@ class Dumper
*/
protected $indentation;
/**
* @param int $indentation
*/
public function __construct($indentation = 4)
public function __construct(int $indentation = 4)
{
if ($indentation < 1) {
throw new \InvalidArgumentException('The indentation must be greater than zero.');
@@ -39,20 +36,6 @@ class Dumper
$this->indentation = $indentation;
}
/**
* Sets the indentation.
*
* @param int $num The amount of spaces to use for indentation of nested nodes
*
* @deprecated since version 3.1, to be removed in 4.0. Pass the indentation to the constructor instead.
*/
public function setIndentation($num)
{
@trigger_error('The '.__METHOD__.' method is deprecated since Symfony 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED);
$this->indentation = (int) $num;
}
/**
* Dumps a PHP value to YAML.
*
@@ -63,26 +46,8 @@ class Dumper
*
* @return string The YAML representation of the PHP value
*/
public function dump($input, $inline = 0, $indent = 0, $flags = 0)
public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0): string
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 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() >= 5) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(4)) {
$flags |= Yaml::DUMP_OBJECT;
}
}
$output = '';
$prefix = $indent ? str_repeat(' ', $indent) : '';
$dumpObjectAsInlineMap = true;

View File

@@ -50,7 +50,7 @@ class Escaper
*
* @return bool True if the value would require double quotes
*/
public static function requiresDoubleQuoting($value)
public static function requiresDoubleQuoting(string $value): bool
{
return 0 < preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
}
@@ -62,7 +62,7 @@ class Escaper
*
* @return string The quoted, escaped string
*/
public static function escapeWithDoubleQuotes($value)
public static function escapeWithDoubleQuotes(string $value): string
{
return sprintf('"%s"', str_replace(self::$escapees, self::$escaped, $value));
}
@@ -74,7 +74,7 @@ class Escaper
*
* @return bool True if the value would require single quotes
*/
public static function requiresSingleQuoting($value)
public static function requiresSingleQuoting(string $value): bool
{
// Determines if a PHP value is entirely composed of a value that would
// require single quoting in YAML.
@@ -94,7 +94,7 @@ class Escaper
*
* @return string The quoted, escaped string
*/
public static function escapeWithSingleQuotes($value)
public static function escapeWithSingleQuotes(string $value): string
{
return sprintf("'%s'", str_replace('\'', '\'\'', $value));
}

View File

@@ -30,7 +30,7 @@ class ParseException extends RuntimeException
* @param string|null $parsedFile The file name where the error occurred
* @param \Exception|null $previous The previous exception
*/
public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null)
public function __construct(string $message, int $parsedLine = -1, string $snippet = null, string $parsedFile = null, \Exception $previous = null)
{
$this->parsedFile = $parsedFile;
$this->parsedLine = $parsedLine;

View File

@@ -63,40 +63,8 @@ class Inline
*
* @throws ParseException
*/
public static function parse($value, $flags = 0, $references = array())
public static function parse(string $value = null, int $flags = 0, array $references = array())
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 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 Symfony 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 Symfony 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::initialize($flags);
$value = trim($value);
@@ -125,7 +93,7 @@ class Inline
$result = self::parseScalar($value, $flags, null, $i, null === $tag, $references);
}
if (null !== $tag) {
if (null !== $tag && '' !== $tag) {
return new TaggedValue($tag, $result);
}
@@ -151,26 +119,8 @@ class Inline
*
* @throws DumpException When trying to dump PHP resource
*/
public static function dump($value, $flags = 0)
public static function dump($value, int $flags = 0): string
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 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 Symfony 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 (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
@@ -190,7 +140,13 @@ class Inline
}
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \stdClass || $value instanceof \ArrayObject)) {
return self::dumpArray($value, $flags & ~Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
$output = array();
foreach ($value as $key => $val) {
$output[] = sprintf('%s: %s', self::dump($key, $flags), self::dump($val, $flags));
}
return sprintf('{ %s }', implode(', ', $output));
}
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $flags) {
@@ -248,13 +204,11 @@ class Inline
/**
* Check if given array is hash or just normal indexed array.
*
* @internal
*
* @param array|\ArrayObject|\stdClass $value The PHP array or array-like object to check
*
* @return bool true if value is hash array, false otherwise
*/
public static function isHash($value)
public static function isHash($value): bool
{
if ($value instanceof \stdClass || $value instanceof \ArrayObject) {
return true;
@@ -279,7 +233,7 @@ class Inline
*
* @return string The YAML string representing the PHP array
*/
private static function dumpArray($value, $flags)
private static function dumpArray(array $value, int $flags): string
{
// array
if (($value || Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE & $flags) && !self::isHash($value)) {
@@ -303,20 +257,11 @@ class Inline
/**
* Parses a YAML scalar.
*
* @param string $scalar
* @param int $flags
* @param string[] $delimiters
* @param int &$i
* @param bool $evaluate
* @param array $references
*
* @return string
* @return mixed
*
* @throws ParseException When malformed inline YAML string is parsed
*
* @internal
*/
public static function parseScalar($scalar, $flags = 0, $delimiters = null, &$i = 0, $evaluate = true, $references = array(), $legacyOmittedKeySupport = false)
public static function parseScalar(string $scalar, int $flags = 0, array $delimiters = null, int &$i = 0, bool $evaluate = true, array $references = array())
{
if (\in_array($scalar[$i], array('"', "'"))) {
// quoted scalar
@@ -341,22 +286,19 @@ class Inline
if (Parser::preg_match('/[ \t]+#/', $output, $match, PREG_OFFSET_CAPTURE)) {
$output = substr($output, 0, $match[0][1]);
}
} elseif (Parser::preg_match('/^(.'.($legacyOmittedKeySupport ? '+' : '*').'?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
} elseif (Parser::preg_match('/^(.*?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
$output = $match[1];
$i += \strlen($output);
$output = trim($output);
} else {
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 >)
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0])) {
if ($output && ('@' === $output[0] || '`' === $output[0] || '|' === $output[0] || '>' === $output[0] || '%' === $output[0])) {
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]), self::$parsedLineNumber + 1, $output, self::$parsedFilename);
}
if ($output && '%' === $output[0]) {
@trigger_error(self::getDeprecationMessage(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, $flags, $references);
}
@@ -368,14 +310,9 @@ class Inline
/**
* Parses a YAML quoted scalar.
*
* @param string $scalar
* @param int &$i
*
* @return string
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseQuotedScalar($scalar, &$i)
private static function parseQuotedScalar(string $scalar, int &$i): 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);
@@ -398,16 +335,9 @@ class Inline
/**
* Parses a YAML sequence.
*
* @param string $sequence
* @param int $flags
* @param int &$i
* @param array $references
*
* @return array
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseSequence($sequence, $flags, &$i = 0, $references = array())
private static function parseSequence(string $sequence, int $flags, int &$i = 0, array $references = array()): array
{
$output = array();
$len = \strlen($sequence);
@@ -452,7 +382,7 @@ class Inline
--$i;
}
if (null !== $tag) {
if (null !== $tag && '' !== $tag) {
$value = new TaggedValue($tag, $value);
}
@@ -467,16 +397,11 @@ class Inline
/**
* Parses a YAML mapping.
*
* @param string $mapping
* @param int $flags
* @param int &$i
* @param array $references
*
* @return array|\stdClass
*
* @throws ParseException When malformed inline YAML string is parsed
*/
private static function parseMapping($mapping, $flags, &$i = 0, $references = array())
private static function parseMapping(string $mapping, int $flags, int &$i = 0, array $references = array())
{
$output = array();
$len = \strlen($mapping);
@@ -499,27 +424,28 @@ class Inline
}
// key
$offsetBeforeKeyParsing = $i;
$isKeyQuoted = \in_array($mapping[$i], array('"', "'"), true);
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array(), true);
$key = self::parseScalar($mapping, $flags, array(':', ' '), $i, false, array());
if (':' !== $key && false === $i = strpos($mapping, ':', $i)) {
break;
if ($offsetBeforeKeyParsing === $i) {
throw new ParseException('Missing mapping key.', self::$parsedLineNumber + 1, $mapping);
}
if (':' === $key) {
@trigger_error(self::getDeprecationMessage('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
if (false === $i = strpos($mapping, ':', $i)) {
break;
}
if (!$isKeyQuoted) {
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
if ('' !== $key && $evaluatedKey !== $key && !\is_string($evaluatedKey) && !\is_int($evaluatedKey)) {
@trigger_error(self::getDeprecationMessage('Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.'), E_USER_DEPRECATED);
throw new ParseException('Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead.', self::$parsedLineNumber + 1, $mapping);
}
}
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
@trigger_error(self::getDeprecationMessage('Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since Symfony 3.2 and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
if (!$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], array(' ', ',', '[', ']', '{', '}'), true))) {
throw new ParseException('Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}").', self::$parsedLineNumber + 1, $mapping);
}
if ('<<' === $key) {
@@ -553,7 +479,7 @@ class Inline
$output[$key] = $value;
}
} elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
}
break;
case '{':
@@ -572,7 +498,7 @@ class Inline
$output[$key] = $value;
}
} elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
}
break;
default:
@@ -590,7 +516,7 @@ class Inline
$output[$key] = $value;
}
} elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), self::$parsedLineNumber + 1, $mapping);
}
--$i;
}
@@ -606,15 +532,11 @@ class Inline
/**
* Evaluates scalars and replaces magic values.
*
* @param string $scalar
* @param int $flags
* @param array $references
*
* @return mixed The evaluated 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, $flags, $references = array())
private static function evaluateScalar(string $scalar, int $flags, array $references = array())
{
$scalar = trim($scalar);
$scalarLower = strtolower($scalar);
@@ -649,40 +571,10 @@ class Inline
return false;
case '!' === $scalar[0]:
switch (true) {
case 0 === strpos($scalar, '!str'):
@trigger_error(self::getDeprecationMessage('Support for the !str tag is deprecated since Symfony 3.4. Use the !!str tag instead.'), E_USER_DEPRECATED);
return (string) substr($scalar, 5);
case 0 === strpos($scalar, '!!str '):
return (string) substr($scalar, 6);
case 0 === strpos($scalar, '! '):
@trigger_error(self::getDeprecationMessage('Using the non-specific tag "!" is deprecated since Symfony 3.4 as its behavior will change in 4.0. It will force non-evaluating your values in 4.0. Use plain integers or !!float instead.'), E_USER_DEPRECATED);
return (int) self::parseScalar(substr($scalar, 2), $flags);
case 0 === strpos($scalar, '!php/object:'):
if (self::$objectSupport) {
@trigger_error(self::getDeprecationMessage('The !php/object: tag to indicate dumped PHP objects is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.'), E_USER_DEPRECATED);
return unserialize(substr($scalar, 12));
}
if (self::$exceptionOnInvalidType) {
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}
return;
case 0 === strpos($scalar, '!!php/object:'):
if (self::$objectSupport) {
@trigger_error(self::getDeprecationMessage('The !!php/object: tag to indicate dumped PHP objects is deprecated since Symfony 3.1 and will be removed in 4.0. Use the !php/object (without the colon) tag instead.'), E_USER_DEPRECATED);
return unserialize(substr($scalar, 13));
}
if (self::$exceptionOnInvalidType) {
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}
return;
return substr($scalar, 2);
case 0 === strpos($scalar, '!php/object'):
if (self::$objectSupport) {
return unserialize(self::parseScalar(substr($scalar, 12)));
@@ -692,21 +584,6 @@ class Inline
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
}
return;
case 0 === strpos($scalar, '!php/const:'):
if (self::$constantSupport) {
@trigger_error(self::getDeprecationMessage('The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.'), E_USER_DEPRECATED);
if (\defined($const = substr($scalar, 11))) {
return \constant($const);
}
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);
}
return;
case 0 === strpos($scalar, '!php/const'):
if (self::$constantSupport) {
@@ -727,7 +604,7 @@ class Inline
case 0 === strpos($scalar, '!!binary '):
return self::evaluateBinaryScalar(substr($scalar, 9));
default:
@trigger_error(self::getDeprecationMessage(sprintf('Using the unquoted scalar value "%s" is deprecated since Symfony 3.3 and will be considered as a tagged value in 4.0. You must quote it.', $scalar)), E_USER_DEPRECATED);
throw new ParseException(sprintf('The string "%s" could not be parsed as it uses an unsupported built-in tag.', $scalar), self::$parsedLineNumber, $scalar, self::$parsedFilename);
}
// Optimize for returning strings.
@@ -758,13 +635,8 @@ class Inline
return -log(0);
case '-.inf' === $scalarLower:
return log(0);
case Parser::preg_match('/^(-|\+)?[0-9][0-9,]*(\.[0-9_]+)?$/', $scalar):
case Parser::preg_match('/^(-|\+)?[0-9][0-9_]*(\.[0-9_]+)?$/', $scalar):
if (false !== strpos($scalar, ',')) {
@trigger_error(self::getDeprecationMessage('Using the comma as a group separator for floats is deprecated since Symfony 3.2 and will be removed in 4.0.'), E_USER_DEPRECATED);
}
return (float) str_replace(array(',', '_'), '', $scalar);
return (float) str_replace('_', '', $scalar);
case Parser::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.
@@ -783,53 +655,39 @@ class Inline
return (string) $scalar;
}
/**
* @param string $value
* @param int &$i
* @param int $flags
*
* @return null|string
*/
private static function parseTag($value, &$i, $flags)
private static function parseTag(string $value, int &$i, int $flags): ?string
{
if ('!' !== $value[$i]) {
return;
return null;
}
$tagLength = strcspn($value, " \t\n", $i + 1);
$tagLength = strcspn($value, " \t\n[]{},", $i + 1);
$tag = substr($value, $i + 1, $tagLength);
$nextOffset = $i + $tagLength + 1;
$nextOffset += strspn($value, ' ', $nextOffset);
// Is followed by a scalar
if ((!isset($value[$nextOffset]) || !\in_array($value[$nextOffset], array('[', '{'), true)) && 'tagged' !== $tag) {
// Manage non-whitelisted scalars in {@link self::evaluateScalar()}
return;
// 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)) {
// Manage in {@link self::evaluateScalar()}
return null;
}
$i = $nextOffset;
// Built-in tags
if ($tag && '!' === $tag[0]) {
throw new ParseException(sprintf('The built-in tag "!%s" is not implemented.', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
}
if (Yaml::PARSE_CUSTOM_TAGS & $flags) {
$i = $nextOffset;
if ('' === $tag || Yaml::PARSE_CUSTOM_TAGS & $flags) {
return $tag;
}
throw new ParseException(sprintf('Tags support is not enabled. Enable the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!%s".', $tag), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
}
/**
* @param string $scalar
*
* @return string
*
* @internal
*/
public static function evaluateBinaryScalar($scalar)
public static function evaluateBinaryScalar(string $scalar): string
{
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
@@ -844,7 +702,7 @@ class Inline
return base64_decode($parsedBinaryData, true);
}
private static function isBinaryString($value)
private static function isBinaryString(string $value)
{
return !preg_match('//u', $value) || preg_match('/[^\x00\x07-\x0d\x1B\x20-\xff]/', $value);
}
@@ -856,7 +714,7 @@ class Inline
*
* @see http://www.yaml.org/spec/1.2/spec.html#id2761573
*/
private static function getTimestampRegex()
private static function getTimestampRegex(): string
{
return <<<EOF
~^
@@ -879,23 +737,8 @@ EOF;
*
* @return string
*/
private static function getHexRegex()
private static function getHexRegex(): string
{
return '~^0x[0-9a-f_]++$~i';
}
private static function getDeprecationMessage($message)
{
$message = rtrim($message, '.');
if (null !== self::$parsedFilename) {
$message .= ' in '.self::$parsedFilename;
}
if (-1 !== self::$parsedLineNumber) {
$message .= ' on line '.(self::$parsedLineNumber + 1);
}
return $message.'.';
}
}

View File

@@ -19,7 +19,7 @@ use Symfony\Component\Yaml\Tag\TaggedValue;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since version 3.4
* @final
*/
class Parser
{
@@ -36,21 +36,6 @@ class Parser
private $skippedLineNumbers = array();
private $locallySkippedLineNumbers = array();
public function __construct()
{
if (\func_num_args() > 0) {
@trigger_error(sprintf('The constructor arguments $offset, $totalNumberOfLines, $skippedLineNumbers of %s are deprecated and will be removed in 4.0', self::class), E_USER_DEPRECATED);
$this->offset = func_get_arg(0);
if (\func_num_args() > 1) {
$this->totalNumberOfLines = func_get_arg(1);
}
if (\func_num_args() > 2) {
$this->skippedLineNumbers = func_get_arg(2);
}
}
}
/**
* Parses a YAML file into a PHP value.
*
@@ -61,7 +46,7 @@ class Parser
*
* @throws ParseException If the file could not be read or the YAML is not valid
*/
public function parseFile($filename, $flags = 0)
public function parseFile(string $filename, int $flags = 0)
{
if (!is_file($filename)) {
throw new ParseException(sprintf('File "%s" does not exist.', $filename));
@@ -90,38 +75,8 @@ class Parser
*
* @throws ParseException If the YAML is not valid
*/
public function parse($value, $flags = 0)
public function parse(string $value, int $flags = 0)
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 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) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(2)) {
$flags |= Yaml::PARSE_OBJECT;
}
}
if (\func_num_args() >= 4) {
@trigger_error('Passing a boolean flag to toggle object for map support is deprecated since Symfony 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 (Yaml::PARSE_KEYS_AS_STRINGS & $flags) {
@trigger_error('Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.', E_USER_DEPRECATED);
}
if (false === preg_match('//u', $value)) {
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
}
@@ -129,7 +84,6 @@ class Parser
$this->refs = array();
$mbEncoding = null;
$e = null;
$data = null;
if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) {
@@ -139,28 +93,31 @@ class Parser
try {
$data = $this->doParse($value, $flags);
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
if (null !== $mbEncoding) {
mb_internal_encoding($mbEncoding);
}
$this->lines = array();
$this->currentLine = '';
$this->refs = array();
$this->skippedLineNumbers = array();
$this->locallySkippedLineNumbers = array();
if (null !== $e) {
throw $e;
} finally {
if (null !== $mbEncoding) {
mb_internal_encoding($mbEncoding);
}
$this->lines = array();
$this->currentLine = '';
$this->refs = array();
$this->skippedLineNumbers = array();
$this->locallySkippedLineNumbers = array();
}
return $data;
}
private function doParse($value, $flags)
/**
* @internal
*
* @return int
*/
public function getLastLineNumberBeforeDeprecation(): int
{
return $this->getRealCurrentLineNb();
}
private function doParse(string $value, int $flags)
{
$this->currentLineNb = -1;
$this->currentLine = '';
@@ -216,12 +173,12 @@ class Parser
}
if (isset($values['value'][1]) && '?' === $values['value'][0] && ' ' === $values['value'][1]) {
@trigger_error($this->getDeprecationMessage('Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.'), E_USER_DEPRECATED);
throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
// array
if (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true), $flags);
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
$data[] = new TaggedValue(
$subTag,
@@ -255,15 +212,7 @@ class Parser
$context = 'mapping';
try {
$i = 0;
$evaluateKey = !(Yaml::PARSE_KEYS_AS_STRINGS & $flags);
// constants in key will be evaluated anyway
if (isset($values['key'][0]) && '!' === $values['key'][0] && Yaml::PARSE_CONSTANT & $flags) {
$evaluateKey = true;
}
$key = Inline::parseScalar($values['key'], 0, null, $i, $evaluateKey);
$key = Inline::parseScalar($values['key']);
} catch (ParseException $e) {
$e->setParsedLine($this->getRealCurrentLineNb() + 1);
$e->setSnippet($this->currentLine);
@@ -272,8 +221,7 @@ class Parser
}
if (!\is_string($key) && !\is_int($key)) {
$keyType = is_numeric($key) ? 'numeric key' : 'non-string key';
@trigger_error($this->getDeprecationMessage(sprintf('Implicit casting of %s to string is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.', $keyType)), E_USER_DEPRECATED);
throw new ParseException(sprintf('%s keys are not supported. Quote your evaluable mapping keys instead.', is_numeric($key) ? 'Numeric' : 'Non-string'), $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
// Convert float keys to strings, to avoid being converted to integers by PHP
@@ -359,9 +307,11 @@ class Parser
$data[$key] = null;
}
} else {
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
} else {
// remember the parsed line number here in case we need it to provide some contexts in error messages below
$realCurrentLineNbKey = $this->getRealCurrentLineNb();
$value = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(), $flags);
if ('<<' === $key) {
$this->refs[$refMatches['ref']] = $value;
@@ -380,7 +330,7 @@ class Parser
$data[$key] = $value;
}
} else {
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $realCurrentLineNbKey + 1, $this->currentLine);
}
}
} else {
@@ -390,7 +340,7 @@ class Parser
if ($allowOverwrite || !isset($data[$key])) {
$data[$key] = $value;
} else {
@trigger_error($this->getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
throw new ParseException(sprintf('Duplicate key "%s" detected.', $key), $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
}
if ($isRef) {
@@ -403,7 +353,7 @@ class Parser
}
if ($deprecatedUsage = (isset($this->currentLine[1]) && '?' === $this->currentLine[0] && ' ' === $this->currentLine[1])) {
@trigger_error($this->getDeprecationMessage('Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0.'), E_USER_DEPRECATED);
throw new ParseException('Complex mappings are not supported.', $this->getRealCurrentLineNb() + 1, $this->currentLine);
}
// 1-liner optionally followed by newline(s)
@@ -483,7 +433,7 @@ class Parser
return empty($data) ? null : $data;
}
private function parseBlock($offset, $yaml, $flags)
private function parseBlock(int $offset, string $yaml, int $flags)
{
$skippedLineNumbers = $this->skippedLineNumbers;
@@ -511,7 +461,7 @@ class Parser
*
* @return int The current line number
*/
public function getRealCurrentLineNb()
public function getRealCurrentLineNb(): int
{
$realCurrentLineNumber = $this->currentLineNb + $this->offset;
@@ -531,7 +481,7 @@ class Parser
*
* @return int The current line indentation
*/
private function getCurrentLineIndentation()
private function getCurrentLineIndentation(): int
{
return \strlen($this->currentLine) - \strlen(ltrim($this->currentLine, ' '));
}
@@ -539,14 +489,14 @@ class Parser
/**
* Returns the next embed block of YAML.
*
* @param int $indentation The indent level at which the block is to be read, or null for default
* @param bool $inSequence True if the enclosing data structure is a sequence
* @param int|null $indentation The indent level at which the block is to be read, or null for default
* @param bool $inSequence True if the enclosing data structure is a sequence
*
* @return string A YAML string
*
* @throws ParseException When indentation problem are detected
*/
private function getNextEmbedBlock($indentation = null, $inSequence = false)
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): ?string
{
$oldLineIndentation = $this->getCurrentLineIndentation();
$blockScalarIndentations = array();
@@ -556,7 +506,7 @@ class Parser
}
if (!$this->moveToNextLine()) {
return;
return null;
}
if (null === $indentation) {
@@ -599,7 +549,7 @@ class Parser
} else {
$this->moveToPreviousLine();
return;
return null;
}
if ($inSequence && $oldLineIndentation === $newIndent && isset($data[0][0]) && '-' === $data[0][0]) {
@@ -607,7 +557,7 @@ class Parser
// and therefore no nested list or mapping
$this->moveToPreviousLine();
return;
return null;
}
$isItUnindentedCollection = $this->isStringUnIndentedCollectionItem();
@@ -667,7 +617,7 @@ class Parser
*
* @return bool
*/
private function moveToNextLine()
private function moveToNextLine(): bool
{
if ($this->currentLineNb >= \count($this->lines) - 1) {
return false;
@@ -683,7 +633,7 @@ class Parser
*
* @return bool
*/
private function moveToPreviousLine()
private function moveToPreviousLine(): bool
{
if ($this->currentLineNb < 1) {
return false;
@@ -705,7 +655,7 @@ class Parser
*
* @throws ParseException When reference does not exist
*/
private function parseValue($value, $flags, $context)
private function parseValue(string $value, int $flags, string $context)
{
if (0 === strpos($value, '*')) {
if (false !== $pos = strpos($value, '#')) {
@@ -726,14 +676,12 @@ class Parser
$data = $this->parseBlockScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), (int) abs($modifiers));
if ('' !== $matches['tag']) {
if ('' !== $matches['tag'] && '!' !== $matches['tag']) {
if ('!!binary' === $matches['tag']) {
return Inline::evaluateBinaryScalar($data);
} elseif ('tagged' === $matches['tag']) {
return new TaggedValue(substr($matches['tag'], 1), $data);
} elseif ('!' !== $matches['tag']) {
@trigger_error($this->getDeprecationMessage(sprintf('Using the custom tag "%s" for the value "%s" is deprecated since Symfony 3.3. It will be replaced by an instance of %s in 4.0.', $matches['tag'], $data, TaggedValue::class)), E_USER_DEPRECATED);
}
return new TaggedValue(substr($matches['tag'], 1), $data);
}
return $data;
@@ -804,7 +752,7 @@ class Parser
*
* @return string The text value
*/
private function parseBlockScalar($style, $chomping = '', $indentation = 0)
private function parseBlockScalar(string $style, string $chomping = '', int $indentation = 0): string
{
$notEOF = $this->moveToNextLine();
if (!$notEOF) {
@@ -911,7 +859,7 @@ class Parser
*
* @return bool Returns true if the next line is indented, false otherwise
*/
private function isNextLineIndented()
private function isNextLineIndented(): bool
{
$currentIndentation = $this->getCurrentLineIndentation();
$movements = 0;
@@ -942,7 +890,7 @@ class Parser
*
* @return bool Returns true if the current line is empty or if it is a comment line, false otherwise
*/
private function isCurrentLineEmpty()
private function isCurrentLineEmpty(): bool
{
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
}
@@ -952,7 +900,7 @@ class Parser
*
* @return bool Returns true if the current line is blank, false otherwise
*/
private function isCurrentLineBlank()
private function isCurrentLineBlank(): bool
{
return '' == trim($this->currentLine, ' ');
}
@@ -962,7 +910,7 @@ class Parser
*
* @return bool Returns true if the current line is a comment line, false otherwise
*/
private function isCurrentLineComment()
private function isCurrentLineComment(): bool
{
//checking explicitly the first char of the trim is faster than loops or strpos
$ltrimmedLine = ltrim($this->currentLine, ' ');
@@ -970,7 +918,7 @@ class Parser
return '' !== $ltrimmedLine && '#' === $ltrimmedLine[0];
}
private function isCurrentLineLastLineInDocument()
private function isCurrentLineLastLineInDocument(): bool
{
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
}
@@ -982,7 +930,7 @@ class Parser
*
* @return string A cleaned up YAML string
*/
private function cleanup($value)
private function cleanup(string $value): string
{
$value = str_replace(array("\r\n", "\r"), "\n", $value);
@@ -1018,7 +966,7 @@ class Parser
*
* @return bool Returns true if the next line starts unindented collection, false otherwise
*/
private function isNextLineUnIndentedCollection()
private function isNextLineUnIndentedCollection(): bool
{
$currentIndentation = $this->getCurrentLineIndentation();
$movements = 0;
@@ -1049,7 +997,7 @@ class Parser
*
* @return bool Returns true if the string is un-indented collection item, false otherwise
*/
private function isStringUnIndentedCollectionItem()
private function isStringUnIndentedCollectionItem(): bool
{
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
}
@@ -1059,7 +1007,7 @@ class Parser
*
* @return bool
*/
private function isBlockScalarHeader()
private function isBlockScalarHeader(): bool
{
return (bool) self::preg_match('~'.self::BLOCK_SCALAR_HEADER_PATTERN.'$~', $this->currentLine);
}
@@ -1077,7 +1025,7 @@ class Parser
*
* @internal
*/
public static function preg_match($pattern, $subject, &$matches = null, $flags = 0, $offset = 0)
public static function preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int
{
if (false === $ret = preg_match($pattern, $subject, $matches, $flags, $offset)) {
switch (preg_last_error()) {
@@ -1112,7 +1060,7 @@ class Parser
* Prevent values such as `!foo {quz: bar}` to be considered as
* a mapping block.
*/
private function trimTag($value)
private function trimTag(string $value): string
{
if ('!' === $value[0]) {
return ltrim(substr($value, 1, strcspn($value, " \r\n", 1)), ' ');
@@ -1121,14 +1069,14 @@ class Parser
return $value;
}
private function getLineTag($value, $flags, $nextLineCheck = true)
private function getLineTag(string $value, int $flags, bool $nextLineCheck = true): ?string
{
if ('' === $value || '!' !== $value[0] || 1 !== self::preg_match('/^'.self::TAG_PATTERN.' *( +#.*)?$/', $value, $matches)) {
return;
return null;
}
if ($nextLineCheck && !$this->isNextLineIndented()) {
return;
return null;
}
$tag = substr($matches['tag'], 1);
@@ -1144,17 +1092,4 @@ class Parser
throw new ParseException(sprintf('Tags support is not enabled. You must use the flag `Yaml::PARSE_CUSTOM_TAGS` to use "%s".', $matches['tag']), $this->getRealCurrentLineNb() + 1, $value, $this->filename);
}
private function getDeprecationMessage($message)
{
$message = rtrim($message, '.');
if (null !== $this->filename) {
$message .= ' in '.$this->filename;
}
$message .= ' on line '.($this->getRealCurrentLineNb() + 1);
return $message.'.';
}
}

View File

@@ -20,27 +20,17 @@ final class TaggedValue
private $tag;
private $value;
/**
* @param string $tag
* @param mixed $value
*/
public function __construct($tag, $value)
public function __construct(string $tag, $value)
{
$this->tag = $tag;
$this->value = $value;
}
/**
* @return string
*/
public function getTag()
public function getTag(): string
{
return $this->tag;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;

View File

@@ -77,35 +77,6 @@ EOF;
$this->assertEquals($expected, $dumper->dump($this->array, 4, 0));
}
/**
* @group legacy
*/
public function testSetIndentation()
{
$this->dumper->setIndentation(7);
$expected = <<<'EOF'
'': bar
foo: '#bar'
'foo''bar': { }
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
EOF;
$this->assertEquals($expected, $this->dumper->dump($this->array, 4, 0));
}
public function testSpecifications()
{
$files = $this->parser->parse(file_get_contents($this->path.'/index.yml'));
@@ -213,16 +184,6 @@ EOF;
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
}
/**
* @group legacy
*/
public function testObjectSupportEnabledPassingTrue()
{
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, false, true);
$this->assertEquals('{ foo: !php/object \'O:30:"Symfony\Component\Yaml\Tests\A":1:{s:1:"a";s:3:"foo";}\', bar: 1 }', $dump, '->dump() is able to dump objects');
}
public function testObjectSupportDisabledButNoExceptions()
{
$dump = $this->dumper->dump(array('foo' => new A(), 'bar' => 1));
@@ -238,33 +199,6 @@ EOF;
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE);
}
/**
* @group legacy
* @expectedException \Symfony\Component\Yaml\Exception\DumpException
*/
public function testObjectSupportDisabledWithExceptionsPassingTrue()
{
$this->dumper->dump(array('foo' => new A(), 'bar' => 1), 0, 0, true);
}
public function testEmptyArray()
{
$dump = $this->dumper->dump(array());
$this->assertEquals('{ }', $dump);
$dump = $this->dumper->dump(array(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
$this->assertEquals('[]', $dump);
$dump = $this->dumper->dump(array(), 9, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
$this->assertEquals('[]', $dump);
$dump = $this->dumper->dump(new \ArrayObject(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP);
$this->assertEquals('{ }', $dump);
$dump = $this->dumper->dump(new \stdClass(), 0, 0, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP);
$this->assertEquals('{ }', $dump);
}
/**
* @dataProvider getEscapeSequences
*/

View File

@@ -518,16 +518,6 @@ php: |
'hexadecimal' => 0xC
)
---
test: Decimal Integer
deprecated: true
spec: 2.19
yaml: |
decimal: +12,345
php: |
array(
'decimal' => 12345.0,
)
---
# FIX: spec shows parens around -inf and NaN
test: Floating point
spec: 2.20
@@ -546,16 +536,6 @@ php: |
'float as whole number' => (float) 1
)
---
test: Fixed Floating point
deprecated: true
spec: 2.20
yaml: |
fixed: 1,230.15
php: |
array(
'fixed' => 1230.15,
)
---
test: Timestamps
todo: true
spec: 2.22
@@ -928,13 +908,12 @@ documents: 2
---
test: Explicit typing
deprecated: Using the non-specific tag "!" is deprecated since Symfony 3.4 as its behavior will change in 4.0.
yaml: |
integer: 12
also int: ! "12"
no int: ! 12
string: !!str 12
php: |
array( 'integer' => 12, 'also int' => 12, 'string' => '12' )
array( 'integer' => 12, 'no int' => '12', 'string' => '12' )
---
test: Private types
todo: true
@@ -1531,24 +1510,6 @@ php: |
'hexadecimal' => 12
)
---
test: Decimal
deprecated: true
yaml: |
decimal: +12,345
php: |
array(
'decimal' => 12345.0,
)
---
test: Fixed Float
deprecated: true
yaml: |
fixed: 1,230.15
php: |
array(
'fixed' => 1230.15,
)
---
test: Float
yaml: |
canonical: 1.23015e+3

View File

@@ -182,34 +182,6 @@ php: |
'simple' => 12,
)
---
test: Positive Big Integer
deprecated: true
dump_skip: true
brief: >
An integer is a series of numbers, optionally
starting with a positive or negative sign. Integers
may also contain commas for readability.
yaml: |
one-thousand: 1,000
php: |
array(
'one-thousand' => 1000.0,
)
---
test: Negative Big Integer
deprecated: true
dump_skip: true
brief: >
An integer is a series of numbers, optionally
starting with a positive or negative sign. Integers
may also contain commas for readability.
yaml: |
negative one-thousand: -1,000
php: |
array(
'negative one-thousand' => -1000.0
)
---
test: Floats
dump_skip: true
brief: >
@@ -225,20 +197,6 @@ php: |
'scientific notation' => 1000.09
)
---
test: Larger Float
dump_skip: true
deprecated: true
brief: >
Floats are represented by numbers with decimals,
allowing for scientific notation, as well as
positive and negative infinity and "not a number."
yaml: |
larger float: 1,000.09
php: |
array(
'larger float' => 1000.09,
)
---
test: Time
todo: true
brief: >

View File

@@ -1,23 +0,0 @@
--- %YAML:1.0
test: Miscellaneous
spec: 2.21
yaml: |
true: true
false: false
php: |
array(
1 => true,
0 => false,
)
---
test: Boolean
yaml: |
false: used as key
logical: true
answer: false
php: |
array(
false => 'used as key',
'logical' => true,
'answer' => false
)

View File

@@ -1,2 +0,0 @@
- legacyBooleanMappingKeys
- legacyNullMappingKey

View File

@@ -1,9 +0,0 @@
--- %YAML:1.0
test: Miscellaneous
spec: 2.21
yaml: |
null: ~
php: |
array(
'' => null,
)

View File

@@ -14,6 +14,7 @@ namespace Symfony\Component\Yaml\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Inline;
use Symfony\Component\Yaml\Tag\TaggedValue;
use Symfony\Component\Yaml\Yaml;
class InlineTest extends TestCase
@@ -80,38 +81,6 @@ class InlineTest extends TestCase
Inline::parse('!php/const PHP_INT_MAX', Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}
/**
* @group legacy
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
* @dataProvider getTestsForParseLegacyPhpConstants
*/
public function testDeprecatedConstantTag($yaml, $expectedValue)
{
$this->assertSame($expectedValue, Inline::parse($yaml, Yaml::PARSE_CONSTANT));
}
public function getTestsForParseLegacyPhpConstants()
{
return array(
array('!php/const:Symfony\Component\Yaml\Yaml::PARSE_CONSTANT', Yaml::PARSE_CONSTANT),
array('!php/const:PHP_INT_MAX', PHP_INT_MAX),
array('[!php/const:PHP_INT_MAX]', array(PHP_INT_MAX)),
array('{ foo: !php/const:PHP_INT_MAX }', array('foo' => PHP_INT_MAX)),
array('!php/const:NULL', null),
);
}
/**
* @group legacy
* @dataProvider getTestsForParseWithMapObjects
*/
public function testParseWithMapObjectsPassingTrue($yaml, $value)
{
$actual = Inline::parse($yaml, false, false, true);
$this->assertSame(serialize($value), serialize($actual));
}
/**
* @dataProvider getTestsForDump
*/
@@ -194,13 +163,12 @@ class InlineTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since Symfony 3.2 and will throw a ParseException in 4.0 on line 1.
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Colons must be followed by a space or an indication character (i.e. " ", ",", "[", "]", "{", "}")
*/
public function testParseMappingKeyWithColonNotFollowedBySpace()
{
Inline::parse('{1:""}');
Inline::parse('{foo:""}');
}
/**
@@ -235,15 +203,6 @@ class InlineTest extends TestCase
$this->assertSame($expected, Inline::parse($yaml, 0, array('var' => 'var-value')));
}
/**
* @group legacy
* @dataProvider getDataForParseReferences
*/
public function testParseReferencesAsFifthArgument($yaml, $expected)
{
$this->assertSame($expected, Inline::parse($yaml, false, false, false, array('var' => 'var-value')));
}
public function getDataForParseReferences()
{
return array(
@@ -268,19 +227,6 @@ class InlineTest extends TestCase
$this->assertSame(array($foo), Inline::parse('[*foo]', 0, array('foo' => $foo)));
}
/**
* @group legacy
*/
public function testParseMapReferenceInSequenceAsFifthArgument()
{
$foo = array(
'a' => 'Steve',
'b' => 'Clark',
'c' => 'Brian',
);
$this->assertSame(array($foo), Inline::parse('[*foo]', false, false, false, array('foo' => $foo)));
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage A reference must contain at least one character at line 1.
@@ -306,9 +252,9 @@ class InlineTest extends TestCase
{
if (method_exists($this, 'expectExceptionMessage')) {
$this->expectException(ParseException::class);
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
} else {
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
}
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
@@ -326,9 +272,9 @@ class InlineTest extends TestCase
{
if (method_exists($this, 'expectExceptionMessage')) {
$this->expectException(ParseException::class);
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
} else {
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo").', $indicator));
}
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
@@ -336,17 +282,7 @@ class InlineTest extends TestCase
public function getScalarIndicators()
{
return array(array('|'), array('>'));
}
/**
* @group legacy
* @expectedDeprecation Not quoting the scalar "%bar " starting with the "%" indicator character is deprecated since Symfony 3.1 and will throw a ParseException in 4.0 on line 1.
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
*/
public function testParseUnquotedScalarStartingWithPercentCharacter()
{
Inline::parse('{ foo: %bar }');
return array(array('|'), array('>'), array('%'));
}
/**
@@ -611,12 +547,7 @@ class InlineTest extends TestCase
$expected = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day);
if (\PHP_VERSION_ID >= 70100) {
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
} else {
$expected->setTime($hour, $minute, $second);
}
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
$date = Inline::parse($yaml, Yaml::PARSE_DATETIME);
$this->assertEquals($expected, $date);
@@ -641,11 +572,7 @@ class InlineTest extends TestCase
$expected = new \DateTime($yaml);
$expected->setTimeZone(new \DateTimeZone('UTC'));
$expected->setDate($year, $month, $day);
if (\PHP_VERSION_ID >= 70100) {
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
} else {
$expected->setTime($hour, $minute, $second);
}
$expected->setTime($hour, $minute, $second, 1000000 * ($second - (int) $second));
$expectedNested = array('nested' => array($expected));
$yamlNested = "{nested: [$yaml]}";
@@ -736,12 +663,12 @@ class InlineTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0 on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Missing mapping key
*/
public function testOmittedMappingKeyIsParsedAsColon()
public function testMappingKeysCannotBeOmitted()
{
$this->assertSame(array(':' => 'foo'), Inline::parse('{: foo}'));
Inline::parse('{: foo}');
}
/**
@@ -766,8 +693,9 @@ class InlineTest extends TestCase
}
/**
* @group legacy
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Implicit casting of incompatible mapping keys to strings is not supported. Quote your evaluable mapping keys instead
*
* @dataProvider getNotPhpCompatibleMappingKeyData
*/
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
@@ -775,17 +703,6 @@ class InlineTest extends TestCase
$this->assertSame($expected, Inline::parse($yaml));
}
/**
* @group legacy
* @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1.
* @dataProvider getNotPhpCompatibleMappingKeyData
*/
public function testExplicitStringCastingOfMappingKeys($yaml, $expected)
{
$this->assertSame($expected, Yaml::parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS));
}
public function getNotPhpCompatibleMappingKeyData()
{
return array(
@@ -796,13 +713,40 @@ class InlineTest extends TestCase
);
}
/**
* @group legacy
* @expectedDeprecation Support for the !str tag is deprecated since Symfony 3.4. Use the !!str tag instead on line 1.
*/
public function testDeprecatedStrTag()
public function testTagWithoutValueInSequence()
{
$this->assertSame(array('foo' => 'bar'), Inline::parse('{ foo: !str bar }'));
$value = Inline::parse('[!foo]', Yaml::PARSE_CUSTOM_TAGS);
$this->assertInstanceOf(TaggedValue::class, $value[0]);
$this->assertSame('foo', $value[0]->getTag());
$this->assertSame('', $value[0]->getValue());
}
public function testTagWithEmptyValueInSequence()
{
$value = Inline::parse('[!foo ""]', Yaml::PARSE_CUSTOM_TAGS);
$this->assertInstanceOf(TaggedValue::class, $value[0]);
$this->assertSame('foo', $value[0]->getTag());
$this->assertSame('', $value[0]->getValue());
}
public function testTagWithoutValueInMapping()
{
$value = Inline::parse('{foo: !bar}', Yaml::PARSE_CUSTOM_TAGS);
$this->assertInstanceOf(TaggedValue::class, $value['foo']);
$this->assertSame('bar', $value['foo']->getTag());
$this->assertSame('', $value['foo']->getValue());
}
public function testTagWithEmptyValueInMapping()
{
$value = Inline::parse('{foo: !bar ""}', Yaml::PARSE_CUSTOM_TAGS);
$this->assertInstanceOf(TaggedValue::class, $value['foo']);
$this->assertSame('bar', $value['foo']->getTag());
$this->assertSame('', $value['foo']->getValue());
}
/**

View File

@@ -37,34 +37,9 @@ class ParserTest extends TestCase
/**
* @dataProvider getDataFormSpecifications
*/
public function testSpecifications($expected, $yaml, $comment, $deprecated)
public function testSpecifications($expected, $yaml, $comment)
{
$deprecations = array();
if ($deprecated) {
set_error_handler(function ($type, $msg) use (&$deprecations) {
if (E_USER_DEPRECATED !== $type) {
restore_error_handler();
if (class_exists('PHPUnit_Util_ErrorHandler')) {
return \call_user_func_array('PHPUnit_Util_ErrorHandler::handleError', \func_get_args());
}
return \call_user_func_array('PHPUnit\Util\ErrorHandler::handleError', \func_get_args());
}
$deprecations[] = $msg;
});
}
$this->assertEquals($expected, var_export($this->parser->parse($yaml), true), $comment);
if ($deprecated) {
restore_error_handler();
$this->assertCount(1, $deprecations);
$this->assertContains(true !== $deprecated ? $deprecated : 'Using the comma as a group separator for floats is deprecated since Symfony 3.2 and will be removed in 4.0 on line 1.', $deprecations[0]);
}
}
public function getDataFormSpecifications()
@@ -72,35 +47,11 @@ class ParserTest extends TestCase
return $this->loadTestsFromFixtureFiles('index.yml');
}
/**
* @group legacy
* @expectedDeprecationMessage Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable
* @dataProvider getNonStringMappingKeysData
*/
public function testNonStringMappingKeys($expected, $yaml, $comment)
{
$this->assertSame($expected, var_export($this->parser->parse($yaml, Yaml::PARSE_KEYS_AS_STRINGS), true), $comment);
}
public function getNonStringMappingKeysData()
{
return $this->loadTestsFromFixtureFiles('nonStringKeys.yml');
}
/**
* @group legacy
* @dataProvider getLegacyNonStringMappingKeysData
*/
public function testLegacyNonStringMappingKeys($expected, $yaml, $comment)
{
$this->assertSame($expected, var_export($this->parser->parse($yaml), true), $comment);
}
public function getLegacyNonStringMappingKeysData()
{
return $this->loadTestsFromFixtureFiles('legacyNonStringKeys.yml');
}
public function testTabsInYaml()
{
// test tabs in YAML
@@ -479,50 +430,12 @@ EOF;
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
}
/**
* @group legacy
*/
public function testObjectSupportEnabledPassingTrue()
public function testObjectSupportDisabledButNoExceptions()
{
$input = <<<'EOF'
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
foo: !php/object O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($input, false, true), '->parse() is able to parse objects');
}
/**
* @group legacy
* @dataProvider deprecatedObjectValueProvider
*/
public function testObjectSupportEnabledWithDeprecatedTag($yaml)
{
$this->assertEquals(array('foo' => new B(), 'bar' => 1), $this->parser->parse($yaml, Yaml::PARSE_OBJECT), '->parse() is able to parse objects');
}
public function deprecatedObjectValueProvider()
{
return array(
array(
<<<YAML
foo: !!php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
bar: 1
YAML
),
array(
<<<YAML
foo: !php/object:O:30:"Symfony\Component\Yaml\Tests\B":1:{s:1:"b";s:3:"foo";}
bar: 1
YAML
),
);
}
/**
* @dataProvider invalidDumpedObjectProvider
*/
public function testObjectSupportDisabledButNoExceptions($input)
{
$this->assertEquals(array('foo' => null, 'bar' => 1), $this->parser->parse($input), '->parse() does not parse objects');
}
@@ -536,15 +449,6 @@ YAML
$this->assertEquals($expected, $this->parser->parse($yaml, $flags));
}
/**
* @group legacy
* @dataProvider getObjectForMapTests
*/
public function testObjectForMapEnabledWithMappingUsingBooleanToggles($yaml, $expected)
{
$this->assertEquals($expected, $this->parser->parse($yaml, false, false, true));
}
public function getObjectForMapTests()
{
$tests = array();
@@ -609,11 +513,15 @@ YAML;
}
/**
* @dataProvider invalidDumpedObjectProvider
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testObjectsSupportDisabledWithExceptions($yaml)
public function testObjectsSupportDisabledWithExceptions()
{
$yaml = <<<'EOF'
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;
$this->parser->parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}
@@ -628,33 +536,6 @@ YAML;
$this->assertSame($expected, $this->parser->parse($yaml));
}
/**
* @group legacy
* @dataProvider invalidDumpedObjectProvider
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
*/
public function testObjectsSupportDisabledWithExceptionsUsingBooleanToggles($yaml)
{
$this->parser->parse($yaml, true);
}
public function invalidDumpedObjectProvider()
{
$yamlTag = <<<'EOF'
foo: !!php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;
$localTag = <<<'EOF'
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
bar: 1
EOF;
return array(
'yaml-tag' => array($yamlTag),
'local-tag' => array($localTag),
);
}
/**
* @requires extension iconv
*/
@@ -902,6 +783,9 @@ EOF
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Duplicate key "child" detected
*
* > It is an error for two equal keys to appear in the same mapping node.
* > In such a case the YAML processor may continue, ignoring the second
* > `key: value` pair and issuing an appropriate warning. This strategy
@@ -910,7 +794,6 @@ EOF
*
* @see http://yaml.org/spec/1.2/spec.html#id2759572
* @see http://yaml.org/spec/1.1/#id932806
* @group legacy
*/
public function testMappingDuplicateKeyBlock()
{
@@ -931,7 +814,8 @@ EOD;
}
/**
* @group legacy
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Duplicate key "child" detected
*/
public function testMappingDuplicateKeyFlow()
{
@@ -948,13 +832,13 @@ EOD;
}
/**
* @group legacy
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @dataProvider getParseExceptionOnDuplicateData
* @expectedDeprecation Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0 on line %d.
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
*/
public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber)
{
$this->expectExceptionMessage(sprintf('Duplicate key "%s" detected at line %d', $duplicateKey, $lineNumber));
Yaml::parse($input);
}
@@ -1177,8 +1061,8 @@ EOF;
}
/**
* @group legacy
* @expectedDeprecation Implicit casting of numeric key to string is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 2.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Numeric keys are not supported. Quote your evaluable mapping keys instead
*/
public function testFloatKeys()
{
@@ -1188,19 +1072,12 @@ foo:
1.3: "baz"
EOF;
$expected = array(
'foo' => array(
'1.2' => 'bar',
'1.3' => 'baz',
),
);
$this->assertEquals($expected, $this->parser->parse($yaml));
$this->parser->parse($yaml);
}
/**
* @group legacy
* @expectedDeprecation Implicit casting of non-string key to string is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Non-string keys are not supported. Quote your evaluable mapping keys instead
*/
public function testBooleanKeys()
{
@@ -1209,12 +1086,7 @@ true: foo
false: bar
EOF;
$expected = array(
1 => 'foo',
0 => 'bar',
);
$this->assertEquals($expected, $this->parser->parse($yaml));
$this->parser->parse($yaml);
}
public function testExplicitStringCasting()
@@ -1776,6 +1648,18 @@ EOF;
public function taggedValuesProvider()
{
return array(
'scalars' => array(
array(
'foo' => new TaggedValue('inline', 'bar'),
'quz' => new TaggedValue('long', 'this is a long text'),
),
<<<YAML
foo: !inline bar
quz: !long >
this is a long
text
YAML
),
'sequences' => array(
array(new TaggedValue('foo', array('yaml')), new TaggedValue('quz', array('bar'))),
<<<YAML
@@ -1800,9 +1684,18 @@ YAML
- !quz {foo: bar, quz: !bar {one: bar}}
YAML
),
'spaces-around-tag-value-in-sequence' => array(
array(new TaggedValue('foo', 'bar')),
'[ !foo bar ]',
),
);
}
public function testNonSpecificTagSupport()
{
$this->assertSame('12', $this->parser->parse('! 12'));
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Tags support is not enabled. Enable the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!iterator" at line 1 (near "!iterator [foo]").
@@ -1813,12 +1706,21 @@ YAML
}
/**
* @group legacy
* @expectedDeprecation Using the unquoted scalar value "!iterator foo" is deprecated since Symfony 3.3 and will be considered as a tagged value in 4.0. You must quote it on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Tags support is not enabled. Enable the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!iterator" at line 1 (near "!iterator foo").
*/
public function testUnsupportedTagWithScalar()
{
$this->assertEquals('!iterator foo', $this->parser->parse('!iterator foo'));
$this->parser->parse('!iterator foo');
}
/**
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage The string "!!iterator foo" could not be parsed as it uses an unsupported built-in tag at line 1 (near "!!iterator foo").
*/
public function testUnsupportedBuiltInTagWithScalar()
{
$this->parser->parse('!!iterator foo');
}
/**
@@ -1831,8 +1733,8 @@ YAML
}
/**
* @group legacy
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0 on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Complex mappings are not supported at line 1 (near "? "1"").
*/
public function testComplexMappingThrowsParseException()
{
@@ -1846,8 +1748,8 @@ YAML;
}
/**
* @group legacy
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0 on line 2.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Complex mappings are not supported at line 2 (near "? "1"").
*/
public function testComplexMappingNestedInMappingThrowsParseException()
{
@@ -1862,8 +1764,8 @@ YAML;
}
/**
* @group legacy
* @expectedDeprecation Starting an unquoted string with a question mark followed by a space is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0 on line 1.
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
* @expectedExceptionMessage Complex mappings are not supported at line 1 (near "- ? "1"").
*/
public function testComplexMappingNestedInSequenceThrowsParseException()
{
@@ -1912,7 +1814,7 @@ INI;
} else {
eval('$expected = '.trim($test['php']).';');
$tests[] = array(var_export($expected, true), $test['yaml'], $test['test'], isset($test['deprecated']) ? $test['deprecated'] : false);
$tests[] = array(var_export($expected, true), $test['yaml'], $test['test']);
}
}
}
@@ -1975,62 +1877,6 @@ YAML;
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
}
/**
* @group legacy
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 2.
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 4.
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 5.
*/
public function testDeprecatedPhpConstantTagMappingKey()
{
$yaml = <<<YAML
transitions:
!php/const:Symfony\Component\Yaml\Tests\B::FOO:
from:
- !php/const:Symfony\Component\Yaml\Tests\B::BAR
to: !php/const:Symfony\Component\Yaml\Tests\B::BAZ
YAML;
$expected = array(
'transitions' => array(
'foo' => array(
'from' => array(
'bar',
),
'to' => 'baz',
),
),
);
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT));
}
/**
* @group legacy
* @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.
*/
public function testPhpConstantTagMappingKeyWithKeysCastToStrings()
{
$yaml = <<<YAML
transitions:
!php/const 'Symfony\Component\Yaml\Tests\B::FOO':
from:
- !php/const 'Symfony\Component\Yaml\Tests\B::BAR'
to: !php/const 'Symfony\Component\Yaml\Tests\B::BAZ'
YAML;
$expected = array(
'transitions' => array(
'foo' => array(
'from' => array(
'bar',
),
'to' => 'baz',
),
),
);
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS));
}
public function testMergeKeysWhenMappingsAreParsedAsObjects()
{
$yaml = <<<YAML

View File

@@ -35,7 +35,7 @@ class Unescaper
*
* @return string The unescaped string
*/
public function unescapeSingleQuotedString($value)
public function unescapeSingleQuotedString(string $value): string
{
return str_replace('\'\'', '\'', $value);
}
@@ -47,7 +47,7 @@ class Unescaper
*
* @return string The unescaped string
*/
public function unescapeDoubleQuotedString($value)
public function unescapeDoubleQuotedString(string $value): string
{
$callback = function ($match) {
return $this->unescapeCharacter($match[0]);
@@ -64,7 +64,7 @@ class Unescaper
*
* @return string The unescaped character
*/
private function unescapeCharacter($value)
private function unescapeCharacter(string $value): string
{
switch ($value[1]) {
case '0':
@@ -120,12 +120,8 @@ class Unescaper
/**
* Get the UTF-8 character for the given code point.
*
* @param int $c The unicode code point
*
* @return string The corresponding UTF-8 character
*/
private static function utf8chr($c)
private static function utf8chr(int $c): string
{
if (0x80 > $c %= 0x200000) {
return \chr($c);

View File

@@ -18,7 +18,7 @@ use Symfony\Component\Yaml\Exception\ParseException;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final since version 3.4
* @final
*/
class Yaml
{
@@ -34,11 +34,6 @@ class Yaml
const PARSE_CUSTOM_TAGS = 512;
const DUMP_EMPTY_ARRAY_AS_SEQUENCE = 1024;
/**
* @deprecated since version 3.4, to be removed in 4.0. Quote your evaluable keys instead.
*/
const PARSE_KEYS_AS_STRINGS = 2048;
/**
* Parses a YAML file into a PHP value.
*
@@ -55,7 +50,7 @@ class Yaml
*
* @throws ParseException If the file could not be read or the YAML is not valid
*/
public static function parseFile($filename, $flags = 0)
public static function parseFile(string $filename, int $flags = 0)
{
$yaml = new Parser();
@@ -78,34 +73,8 @@ class Yaml
*
* @throws ParseException If the YAML is not valid
*/
public static function parse($input, $flags = 0)
public static function parse(string $input, int $flags = 0)
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
if ($flags) {
$flags = self::PARSE_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 Symfony 3.1 and will be removed in 4.0. Use the PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(2)) {
$flags |= self::PARSE_OBJECT;
}
}
if (\func_num_args() >= 4) {
@trigger_error('Passing a boolean flag to toggle object for map support is deprecated since Symfony 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 |= self::PARSE_OBJECT_FOR_MAP;
}
}
$yaml = new Parser();
return $yaml->parse($input, $flags);
@@ -124,26 +93,8 @@ class Yaml
*
* @return string A YAML string representing the original PHP value
*/
public static function dump($input, $inline = 2, $indent = 4, $flags = 0)
public static function dump($input, int $inline = 2, int $indent = 4, int $flags = 0): string
{
if (\is_bool($flags)) {
@trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the DUMP_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
if ($flags) {
$flags = self::DUMP_EXCEPTION_ON_INVALID_TYPE;
} else {
$flags = 0;
}
}
if (\func_num_args() >= 5) {
@trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the DUMP_OBJECT flag instead.', E_USER_DEPRECATED);
if (func_get_arg(4)) {
$flags |= self::DUMP_OBJECT;
}
}
$yaml = new Dumper($indent);
return $yaml->dump($input, $inline, 0, $flags);

View File

@@ -16,7 +16,7 @@
}
],
"require": {
"php": "^5.5.9|>=7.0.8",
"php": "^7.1.3",
"symfony/polyfill-ctype": "~1.8"
},
"require-dev": {
@@ -37,7 +37,7 @@
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "3.4-dev"
"dev-master": "4.1-dev"
}
}
}