Merge branch '3.3' into 3.4
* 3.3: include file and line number in deprecation parse merge keys with PARSE_OBJECT_FOR_MAP flag
This commit is contained in:
commit
ee545bf8d4
@ -654,10 +654,18 @@ class YamlFileLoader extends FileLoader
|
|||||||
$this->yamlParser = new YamlParser();
|
$this->yamlParser = new YamlParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($file, &$prevErrorHandler) {
|
||||||
|
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$file.'"$0', $message) : $message;
|
||||||
|
|
||||||
|
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
|
$configuration = $this->yamlParser->parseFile($file, Yaml::PARSE_CONSTANT | Yaml::PARSE_CUSTOM_TAGS);
|
||||||
} catch (ParseException $e) {
|
} catch (ParseException $e) {
|
||||||
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
|
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->validate($configuration, $file);
|
return $this->validate($configuration, $file);
|
||||||
|
@ -57,10 +57,18 @@ class YamlFileLoader extends FileLoader
|
|||||||
$this->yamlParser = new YamlParser();
|
$this->yamlParser = new YamlParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($file, &$prevErrorHandler) {
|
||||||
|
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$file.'"$0', $message) : $message;
|
||||||
|
|
||||||
|
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$parsedConfig = $this->yamlParser->parseFile($path);
|
$parsedConfig = $this->yamlParser->parseFile($path);
|
||||||
} catch (ParseException $e) {
|
} catch (ParseException $e) {
|
||||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
|
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection = new RouteCollection();
|
$collection = new RouteCollection();
|
||||||
|
@ -38,10 +38,18 @@ class YamlFileLoader extends FileLoader
|
|||||||
$this->yamlParser = new YamlParser();
|
$this->yamlParser = new YamlParser();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($resource, &$prevErrorHandler) {
|
||||||
|
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$resource.'"$0', $message) : $message;
|
||||||
|
|
||||||
|
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$messages = $this->yamlParser->parseFile($resource);
|
$messages = $this->yamlParser->parseFile($resource);
|
||||||
} catch (ParseException $e) {
|
} catch (ParseException $e) {
|
||||||
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
|
throw new InvalidResourceException(sprintf('Error parsing YAML, invalid file "%s"', $resource), 0, $e);
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $messages;
|
||||||
|
@ -115,10 +115,18 @@ class YamlFileLoader extends FileLoader
|
|||||||
*/
|
*/
|
||||||
private function parseFile($path)
|
private function parseFile($path)
|
||||||
{
|
{
|
||||||
|
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($path, &$prevErrorHandler) {
|
||||||
|
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$path.'"$0', $message) : $message;
|
||||||
|
|
||||||
|
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
|
$classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
|
||||||
} catch (ParseException $e) {
|
} catch (ParseException $e) {
|
||||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
|
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
|
||||||
|
} finally {
|
||||||
|
restore_error_handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty file
|
// empty file
|
||||||
|
@ -39,14 +39,14 @@ class Inline
|
|||||||
* @param int|null $parsedLineNumber
|
* @param int|null $parsedLineNumber
|
||||||
* @param string|null $parsedFilename
|
* @param string|null $parsedFilename
|
||||||
*/
|
*/
|
||||||
public static function initialize($flags, $parsedLineNumber = null, $parsedFilename = null)
|
public static function initialize($flags, $parsedLineNumber = 0, $parsedFilename = null)
|
||||||
{
|
{
|
||||||
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
self::$exceptionOnInvalidType = (bool) (Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE & $flags);
|
||||||
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
self::$objectSupport = (bool) (Yaml::PARSE_OBJECT & $flags);
|
||||||
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
|
self::$objectForMap = (bool) (Yaml::PARSE_OBJECT_FOR_MAP & $flags);
|
||||||
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
|
self::$constantSupport = (bool) (Yaml::PARSE_CONSTANT & $flags);
|
||||||
self::$parsedFilename = $parsedFilename;
|
self::$parsedFilename = $parsedFilename;
|
||||||
self::$parsedLineNumber = null !== $parsedLineNumber ? $parsedLineNumber : -1;
|
self::$parsedLineNumber = $parsedLineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,7 +128,7 @@ class Inline
|
|||||||
|
|
||||||
// some comments are allowed at the end
|
// some comments are allowed at the end
|
||||||
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
||||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber, $value, self::$parsedFilename);
|
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($mbEncoding)) {
|
if (isset($mbEncoding)) {
|
||||||
@ -322,7 +322,7 @@ class Inline
|
|||||||
if (null !== $delimiters) {
|
if (null !== $delimiters) {
|
||||||
$tmp = ltrim(substr($scalar, $i), ' ');
|
$tmp = ltrim(substr($scalar, $i), ' ');
|
||||||
if (!in_array($tmp[0], $delimiters)) {
|
if (!in_array($tmp[0], $delimiters)) {
|
||||||
throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException(sprintf('Unexpected characters (%s).', substr($scalar, $i)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -339,12 +339,12 @@ class Inline
|
|||||||
$output = $match[1];
|
$output = $match[1];
|
||||||
$i += strlen($output);
|
$i += strlen($output);
|
||||||
} else {
|
} else {
|
||||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $scalar), self::$parsedLineNumber, 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 >)
|
// 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])) {
|
||||||
throw new ParseException(sprintf('The reserved indicator "%s" cannot start a plain scalar; you need to quote the scalar.', $output[0]), self::$parsedLineNumber, $output, self::$parsedFilename);
|
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]) {
|
if ($output && '%' === $output[0]) {
|
||||||
@ -372,7 +372,7 @@ class Inline
|
|||||||
private static function parseQuotedScalar($scalar, &$i)
|
private static function parseQuotedScalar($scalar, &$i)
|
||||||
{
|
{
|
||||||
if (!Parser::preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
|
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, $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);
|
$output = substr($match[0], 1, strlen($match[0]) - 2);
|
||||||
@ -455,7 +455,7 @@ class Inline
|
|||||||
++$i;
|
++$i;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence), self::$parsedLineNumber, null, self::$parsedFilename);
|
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $sequence), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -572,7 +572,7 @@ class Inline
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping), self::$parsedLineNumber, null, self::$parsedFilename);
|
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -600,11 +600,11 @@ class Inline
|
|||||||
|
|
||||||
// an unquoted *
|
// an unquoted *
|
||||||
if (false === $value || '' === $value) {
|
if (false === $value || '' === $value) {
|
||||||
throw new ParseException('A reference must contain at least one character.', self::$parsedLineNumber, $value, self::$parsedFilename);
|
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, $value, self::$parsedFilename);
|
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $references[$value];
|
return $references[$value];
|
||||||
@ -639,7 +639,7 @@ class Inline
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self::$exceptionOnInvalidType) {
|
if (self::$exceptionOnInvalidType) {
|
||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -651,7 +651,7 @@ class Inline
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self::$exceptionOnInvalidType) {
|
if (self::$exceptionOnInvalidType) {
|
||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -661,7 +661,7 @@ class Inline
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (self::$exceptionOnInvalidType) {
|
if (self::$exceptionOnInvalidType) {
|
||||||
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException('Object support when parsing a YAML file has been disabled.', self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -673,10 +673,10 @@ class Inline
|
|||||||
return constant($const);
|
return constant($const);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
if (self::$exceptionOnInvalidType) {
|
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, $scalar, self::$parsedFilename);
|
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;
|
return;
|
||||||
@ -686,10 +686,10 @@ class Inline
|
|||||||
return constant($const);
|
return constant($const);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException(sprintf('The constant "%s" is not defined.', $const), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
if (self::$exceptionOnInvalidType) {
|
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, $scalar, self::$parsedFilename);
|
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;
|
return;
|
||||||
@ -781,7 +781,7 @@ class Inline
|
|||||||
|
|
||||||
// Built-in tags
|
// 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, $value, self::$parsedFilename);
|
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) {
|
if (Yaml::PARSE_CUSTOM_TAGS & $flags) {
|
||||||
@ -790,7 +790,7 @@ class Inline
|
|||||||
return $tag;
|
return $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(sprintf('Tags support is not enabled. Enable the `Yaml::PARSE_CUSTOM_TAGS` flag to use "!%s".', $tag), self::$parsedLineNumber, $value, self::$parsedFilename);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -805,11 +805,11 @@ class Inline
|
|||||||
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
$parsedBinaryData = self::parseScalar(preg_replace('/\s/', '', $scalar));
|
||||||
|
|
||||||
if (0 !== (strlen($parsedBinaryData) % 4)) {
|
if (0 !== (strlen($parsedBinaryData) % 4)) {
|
||||||
throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', strlen($parsedBinaryData)), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException(sprintf('The normalized base64 encoded data (data without whitespace characters) length must be a multiple of four (%d bytes given).', strlen($parsedBinaryData)), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Parser::preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) {
|
if (!Parser::preg_match('#^[A-Z0-9+/]+={0,2}$#i', $parsedBinaryData)) {
|
||||||
throw new ParseException(sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData), self::$parsedLineNumber, $scalar, self::$parsedFilename);
|
throw new ParseException(sprintf('The base64 encoded data (%s) contains invalid characters.', $parsedBinaryData), self::$parsedLineNumber + 1, $scalar, self::$parsedFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return base64_decode($parsedBinaryData, true);
|
return base64_decode($parsedBinaryData, true);
|
||||||
@ -864,7 +864,7 @@ EOF;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-1 !== self::$parsedLineNumber) {
|
if (-1 !== self::$parsedLineNumber) {
|
||||||
$message .= ' on line '.self::$parsedLineNumber;
|
$message .= ' on line '.(self::$parsedLineNumber + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $message.'.';
|
return $message.'.';
|
||||||
|
@ -283,7 +283,7 @@ class Parser
|
|||||||
if ('<<' === $key) {
|
if ('<<' === $key) {
|
||||||
$mergeNode = true;
|
$mergeNode = true;
|
||||||
$allowOverwrite = true;
|
$allowOverwrite = true;
|
||||||
if (isset($values['value']) && 0 === strpos($values['value'], '*')) {
|
if (isset($values['value'][0]) && '*' === $values['value'][0]) {
|
||||||
$refName = substr(rtrim($values['value']), 1);
|
$refName = substr(rtrim($values['value']), 1);
|
||||||
if (!array_key_exists($refName, $this->refs)) {
|
if (!array_key_exists($refName, $this->refs)) {
|
||||||
throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
throw new ParseException(sprintf('Reference "%s" does not exist.', $refName), $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
||||||
@ -291,6 +291,10 @@ class Parser
|
|||||||
|
|
||||||
$refValue = $this->refs[$refName];
|
$refValue = $this->refs[$refName];
|
||||||
|
|
||||||
|
if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && $refValue instanceof \stdClass) {
|
||||||
|
$refValue = (array) $refValue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($refValue)) {
|
if (!is_array($refValue)) {
|
||||||
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
||||||
}
|
}
|
||||||
@ -304,6 +308,10 @@ class Parser
|
|||||||
}
|
}
|
||||||
$parsed = $this->parseBlock($this->getRealCurrentLineNb() + 1, $value, $flags);
|
$parsed = $this->parseBlock($this->getRealCurrentLineNb() + 1, $value, $flags);
|
||||||
|
|
||||||
|
if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && $parsed instanceof \stdClass) {
|
||||||
|
$parsed = (array) $parsed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($parsed)) {
|
if (!is_array($parsed)) {
|
||||||
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
throw new ParseException('YAML merge keys used with a scalar value instead of an array.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
||||||
}
|
}
|
||||||
@ -313,6 +321,10 @@ class Parser
|
|||||||
// and each of these nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier
|
// and each of these nodes is merged in turn according to its order in the sequence. Keys in mapping nodes earlier
|
||||||
// in the sequence override keys specified in later mapping nodes.
|
// in the sequence override keys specified in later mapping nodes.
|
||||||
foreach ($parsed as $parsedItem) {
|
foreach ($parsed as $parsedItem) {
|
||||||
|
if (Yaml::PARSE_OBJECT_FOR_MAP & $flags && $parsedItem instanceof \stdClass) {
|
||||||
|
$parsedItem = (array) $parsedItem;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_array($parsedItem)) {
|
if (!is_array($parsedItem)) {
|
||||||
throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem, $this->filename);
|
throw new ParseException('Merge items must be arrays.', $this->getRealCurrentLineNb() + 1, $parsedItem, $this->filename);
|
||||||
}
|
}
|
||||||
@ -940,7 +952,7 @@ class Parser
|
|||||||
|
|
||||||
// remove leading comments
|
// remove leading comments
|
||||||
$trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
|
$trimmedValue = preg_replace('#^(\#.*?\n)+#s', '', $value, -1, $count);
|
||||||
if (1 == $count) {
|
if (1 === $count) {
|
||||||
// items have been removed, update the offset
|
// items have been removed, update the offset
|
||||||
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
||||||
$value = $trimmedValue;
|
$value = $trimmedValue;
|
||||||
@ -948,7 +960,7 @@ class Parser
|
|||||||
|
|
||||||
// remove start of the document marker (---)
|
// remove start of the document marker (---)
|
||||||
$trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
|
$trimmedValue = preg_replace('#^\-\-\-.*?\n#s', '', $value, -1, $count);
|
||||||
if (1 == $count) {
|
if (1 === $count) {
|
||||||
// items have been removed, update the offset
|
// items have been removed, update the offset
|
||||||
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
$this->offset += substr_count($value, "\n") - substr_count($trimmedValue, "\n");
|
||||||
$value = $trimmedValue;
|
$value = $trimmedValue;
|
||||||
|
@ -81,7 +81,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.
|
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
|
||||||
*/
|
*/
|
||||||
public function testDeprecatedConstantTag()
|
public function testDeprecatedConstantTag()
|
||||||
{
|
{
|
||||||
@ -182,7 +182,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0.
|
* @expectedDeprecation Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since version 3.2 and will throw a ParseException in 4.0 on line 1.
|
||||||
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||||
*/
|
*/
|
||||||
public function testParseMappingKeyWithColonNotFollowedBySpace()
|
public function testParseMappingKeyWithColonNotFollowedBySpace()
|
||||||
@ -270,7 +270,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
* @expectedExceptionMessage A reference must contain at least one character.
|
* @expectedExceptionMessage A reference must contain at least one character at line 1.
|
||||||
*/
|
*/
|
||||||
public function testParseUnquotedAsterisk()
|
public function testParseUnquotedAsterisk()
|
||||||
{
|
{
|
||||||
@ -279,7 +279,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
* @expectedExceptionMessage A reference must contain at least one character.
|
* @expectedExceptionMessage A reference must contain at least one character at line 1.
|
||||||
*/
|
*/
|
||||||
public function testParseUnquotedAsteriskFollowedByAComment()
|
public function testParseUnquotedAsteriskFollowedByAComment()
|
||||||
{
|
{
|
||||||
@ -293,9 +293,9 @@ class InlineTest extends TestCase
|
|||||||
{
|
{
|
||||||
if (method_exists($this, 'expectExceptionMessage')) {
|
if (method_exists($this, 'expectExceptionMessage')) {
|
||||||
$this->expectException(ParseException::class);
|
$this->expectException(ParseException::class);
|
||||||
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar (near "%sfoo ").', $indicator));
|
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
|
||||||
} else {
|
} else {
|
||||||
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar (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));
|
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
|
||||||
@ -313,9 +313,9 @@ class InlineTest extends TestCase
|
|||||||
{
|
{
|
||||||
if (method_exists($this, 'expectExceptionMessage')) {
|
if (method_exists($this, 'expectExceptionMessage')) {
|
||||||
$this->expectException(ParseException::class);
|
$this->expectException(ParseException::class);
|
||||||
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar (near "%sfoo ").', $indicator));
|
$this->expectExceptionMessage(sprintf('cannot start a plain scalar; you need to quote the scalar at line 1 (near "%sfoo ").', $indicator));
|
||||||
} else {
|
} else {
|
||||||
$this->setExpectedException(ParseException::class, sprintf('cannot start a plain scalar; you need to quote the scalar (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));
|
Inline::parse(sprintf('{ foo: %sfoo }', $indicator));
|
||||||
@ -328,7 +328,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @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.
|
* @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
|
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||||
*/
|
*/
|
||||||
public function testParseUnquotedScalarStartingWithPercentCharacter()
|
public function testParseUnquotedScalarStartingWithPercentCharacter()
|
||||||
@ -705,7 +705,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
* @expectedException \Symfony\Component\Yaml\Exception\ParseException
|
||||||
* @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported}.
|
* @expectedExceptionMessage Malformed inline YAML string: {this, is not, supported} at line 1.
|
||||||
*/
|
*/
|
||||||
public function testNotSupportedMissingValue()
|
public function testNotSupportedMissingValue()
|
||||||
{
|
{
|
||||||
@ -724,7 +724,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.
|
* @expectedDeprecation Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0 on line 1.
|
||||||
*/
|
*/
|
||||||
public function testOmittedMappingKeyIsParsedAsColon()
|
public function testOmittedMappingKeyIsParsedAsColon()
|
||||||
{
|
{
|
||||||
@ -754,7 +754,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
|
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1.
|
||||||
* @dataProvider getNotPhpCompatibleMappingKeyData
|
* @dataProvider getNotPhpCompatibleMappingKeyData
|
||||||
*/
|
*/
|
||||||
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
|
public function testImplicitStringCastingOfMappingKeysIsDeprecated($yaml, $expected)
|
||||||
@ -765,7 +765,7 @@ class InlineTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since version 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.
|
* @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since version 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 version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead.
|
* @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since version 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line 1.
|
||||||
* @dataProvider getNotPhpCompatibleMappingKeyData
|
* @dataProvider getNotPhpCompatibleMappingKeyData
|
||||||
*/
|
*/
|
||||||
public function testExplicitStringCastingOfMappingKeys($yaml, $expected)
|
public function testExplicitStringCastingOfMappingKeys($yaml, $expected)
|
||||||
@ -785,7 +785,7 @@ class InlineTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead.
|
* @expectedDeprecation Support for the !str tag is deprecated since version 3.4. Use the !!str tag instead on line 1.
|
||||||
*/
|
*/
|
||||||
public function testDeprecatedStrTag()
|
public function testDeprecatedStrTag()
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@ class ParserTest extends TestCase
|
|||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
$this->assertCount(1, $deprecations);
|
$this->assertCount(1, $deprecations);
|
||||||
$this->assertContains(true !== $deprecated ? $deprecated : 'Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0.', $deprecations[0]);
|
$this->assertContains(true !== $deprecated ? $deprecated : 'Using the comma as a group separator for floats is deprecated since version 3.2 and will be removed in 4.0 on line 1.', $deprecations[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -868,7 +868,7 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @dataProvider getParseExceptionOnDuplicateData
|
* @dataProvider getParseExceptionOnDuplicateData
|
||||||
* @expectedDeprecation Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated %s.
|
* @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
|
* throws \Symfony\Component\Yaml\Exception\ParseException in 4.0
|
||||||
*/
|
*/
|
||||||
public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber)
|
public function testParseExceptionOnDuplicate($input, $duplicateKey, $lineNumber)
|
||||||
@ -1689,7 +1689,7 @@ YAML
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
* @expectedDeprecation Using the unquoted scalar value "!iterator foo" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it.
|
* @expectedDeprecation Using the unquoted scalar value "!iterator foo" is deprecated since version 3.3 and will be considered as a tagged value in 4.0. You must quote it on line 1.
|
||||||
*/
|
*/
|
||||||
public function testUnsupportedTagWithScalar()
|
public function testUnsupportedTagWithScalar()
|
||||||
{
|
{
|
||||||
@ -1852,9 +1852,9 @@ YAML;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
|
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 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 version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
|
||||||
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
|
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1.
|
||||||
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.
|
|
||||||
* @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since version 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead.
|
|
||||||
*/
|
*/
|
||||||
public function testDeprecatedPhpConstantTagMappingKey()
|
public function testDeprecatedPhpConstantTagMappingKey()
|
||||||
{
|
{
|
||||||
@ -1906,6 +1906,43 @@ YAML;
|
|||||||
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS));
|
$this->assertSame($expected, $this->parser->parse($yaml, Yaml::PARSE_CONSTANT | Yaml::PARSE_KEYS_AS_STRINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMergeKeysWhenMappingsAreParsedAsObjects()
|
||||||
|
{
|
||||||
|
$yaml = <<<YAML
|
||||||
|
foo: &FOO
|
||||||
|
bar: 1
|
||||||
|
bar: &BAR
|
||||||
|
baz: 2
|
||||||
|
<<: *FOO
|
||||||
|
baz:
|
||||||
|
baz_foo: 3
|
||||||
|
<<:
|
||||||
|
baz_bar: 4
|
||||||
|
foobar:
|
||||||
|
bar: ~
|
||||||
|
<<: [*FOO, *BAR]
|
||||||
|
YAML;
|
||||||
|
$expected = (object) array(
|
||||||
|
'foo' => (object) array(
|
||||||
|
'bar' => 1,
|
||||||
|
),
|
||||||
|
'bar' => (object) array(
|
||||||
|
'baz' => 2,
|
||||||
|
'bar' => 1,
|
||||||
|
),
|
||||||
|
'baz' => (object) array(
|
||||||
|
'baz_foo' => 3,
|
||||||
|
'baz_bar' => 4,
|
||||||
|
),
|
||||||
|
'foobar' => (object) array(
|
||||||
|
'bar' => null,
|
||||||
|
'baz' => 2,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $this->parser->parse($yaml, Yaml::PARSE_OBJECT_FOR_MAP));
|
||||||
|
}
|
||||||
|
|
||||||
public function testFilenamesAreParsedAsStringsWithoutFlag()
|
public function testFilenamesAreParsedAsStringsWithoutFlag()
|
||||||
{
|
{
|
||||||
$file = __DIR__.'/Fixtures/index.yml';
|
$file = __DIR__.'/Fixtures/index.yml';
|
||||||
|
Reference in New Issue
Block a user