Update Composer packages
This commit is contained in:
parent
a80f1abaa4
commit
0a904482ae
41 changed files with 922 additions and 679 deletions
146
kirby/vendor/symfony/yaml/Parser.php
vendored
146
kirby/vendor/symfony/yaml/Parser.php
vendored
|
@ -27,17 +27,17 @@ class Parser
|
|||
public const BLOCK_SCALAR_HEADER_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
|
||||
public const REFERENCE_PATTERN = '#^&(?P<ref>[^ ]++) *+(?P<value>.*)#u';
|
||||
|
||||
private $filename;
|
||||
private $offset = 0;
|
||||
private $numberOfParsedLines = 0;
|
||||
private $totalNumberOfLines;
|
||||
private $lines = [];
|
||||
private $currentLineNb = -1;
|
||||
private $currentLine = '';
|
||||
private $refs = [];
|
||||
private $skippedLineNumbers = [];
|
||||
private $locallySkippedLineNumbers = [];
|
||||
private $refsBeingParsed = [];
|
||||
private ?string $filename = null;
|
||||
private int $offset = 0;
|
||||
private int $numberOfParsedLines = 0;
|
||||
private ?int $totalNumberOfLines = null;
|
||||
private array $lines = [];
|
||||
private int $currentLineNb = -1;
|
||||
private string $currentLine = '';
|
||||
private array $refs = [];
|
||||
private array $skippedLineNumbers = [];
|
||||
private array $locallySkippedLineNumbers = [];
|
||||
private array $refsBeingParsed = [];
|
||||
|
||||
/**
|
||||
* Parses a YAML file into a PHP value.
|
||||
|
@ -45,11 +45,9 @@ class Parser
|
|||
* @param string $filename The path to the YAML file to be parsed
|
||||
* @param int $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws ParseException If the file could not be read or the YAML is not valid
|
||||
*/
|
||||
public function parseFile(string $filename, int $flags = 0)
|
||||
public function parseFile(string $filename, int $flags = 0): mixed
|
||||
{
|
||||
if (!is_file($filename)) {
|
||||
throw new ParseException(sprintf('File "%s" does not exist.', $filename));
|
||||
|
@ -74,11 +72,9 @@ class Parser
|
|||
* @param string $value A YAML string
|
||||
* @param int $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws ParseException If the YAML is not valid
|
||||
*/
|
||||
public function parse(string $value, int $flags = 0)
|
||||
public function parse(string $value, int $flags = 0): mixed
|
||||
{
|
||||
if (false === preg_match('//u', $value)) {
|
||||
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, $this->filename);
|
||||
|
@ -86,19 +82,9 @@ class Parser
|
|||
|
||||
$this->refs = [];
|
||||
|
||||
$mbEncoding = null;
|
||||
|
||||
if (2 /* MB_OVERLOAD_STRING */ & (int) \ini_get('mbstring.func_overload')) {
|
||||
$mbEncoding = mb_internal_encoding();
|
||||
mb_internal_encoding('UTF-8');
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $this->doParse($value, $flags);
|
||||
} finally {
|
||||
if (null !== $mbEncoding) {
|
||||
mb_internal_encoding($mbEncoding);
|
||||
}
|
||||
$this->refsBeingParsed = [];
|
||||
$this->offset = 0;
|
||||
$this->lines = [];
|
||||
|
@ -113,7 +99,7 @@ class Parser
|
|||
return $data;
|
||||
}
|
||||
|
||||
private function doParse(string $value, int $flags)
|
||||
private function doParse(string $value, int $flags): mixed
|
||||
{
|
||||
$this->currentLineNb = -1;
|
||||
$this->currentLine = '';
|
||||
|
@ -121,10 +107,7 @@ class Parser
|
|||
$this->lines = explode("\n", $value);
|
||||
$this->numberOfParsedLines = \count($this->lines);
|
||||
$this->locallySkippedLineNumbers = [];
|
||||
|
||||
if (null === $this->totalNumberOfLines) {
|
||||
$this->totalNumberOfLines = $this->numberOfParsedLines;
|
||||
}
|
||||
$this->totalNumberOfLines ??= $this->numberOfParsedLines;
|
||||
|
||||
if (!$this->moveToNextLine()) {
|
||||
return null;
|
||||
|
@ -175,7 +158,7 @@ class Parser
|
|||
}
|
||||
|
||||
// array
|
||||
if (isset($values['value']) && 0 === strpos(ltrim($values['value'], ' '), '-')) {
|
||||
if (isset($values['value']) && str_starts_with(ltrim($values['value'], ' '), '-')) {
|
||||
// Inline first child
|
||||
$currentLineNumber = $this->getRealCurrentLineNb();
|
||||
|
||||
|
@ -184,7 +167,7 @@ class Parser
|
|||
$sequenceYaml .= "\n".$this->getNextEmbedBlock($sequenceIndentation, true);
|
||||
|
||||
$data[] = $this->parseBlock($currentLineNumber, rtrim($sequenceYaml), $flags);
|
||||
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || 0 === strpos(ltrim($values['value'], ' '), '#')) {
|
||||
} elseif (!isset($values['value']) || '' == trim($values['value'], ' ') || str_starts_with(ltrim($values['value'], ' '), '#')) {
|
||||
$data[] = $this->parseBlock($this->getRealCurrentLineNb() + 1, $this->getNextEmbedBlock(null, true) ?? '', $flags);
|
||||
} elseif (null !== $subTag = $this->getLineTag(ltrim($values['value'], ' '), $flags)) {
|
||||
$data[] = new TaggedValue(
|
||||
|
@ -199,9 +182,8 @@ class Parser
|
|||
|| self::preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->trimTag($values['value']), $matches)
|
||||
)
|
||||
) {
|
||||
// this is a compact notation element, add to next block and parse
|
||||
$block = $values['value'];
|
||||
if ($this->isNextLineIndented()) {
|
||||
if ($this->isNextLineIndented() || isset($matches['value']) && '>-' === $matches['value']) {
|
||||
$block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + \strlen($values['leadspaces']) + 1);
|
||||
}
|
||||
|
||||
|
@ -215,9 +197,14 @@ class Parser
|
|||
array_pop($this->refsBeingParsed);
|
||||
}
|
||||
} elseif (
|
||||
// @todo in 7.0 remove legacy "(?:!?!php/const:)?"
|
||||
self::preg_match('#^(?P<key>(?:![^\s]++\s++)?(?:'.Inline::REGEX_QUOTED_STRING.'|(?:!?!php/const:)?[^ \'"\[\{!].*?)) *\:(( |\t)++(?P<value>.+))?$#u', rtrim($this->currentLine), $values)
|
||||
&& (false === strpos($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
|
||||
&& (!str_contains($values['key'], ' #') || \in_array($values['key'][0], ['"', "'"]))
|
||||
) {
|
||||
if (str_starts_with($values['key'], '!php/const:')) {
|
||||
trigger_deprecation('symfony/yaml', '6.2', 'YAML syntax for key "%s" is deprecated and replaced by "!php/const %s".', $values['key'], substr($values['key'], 11));
|
||||
}
|
||||
|
||||
if ($context && 'sequence' == $context) {
|
||||
throw new ParseException('You cannot define a mapping item when in a sequence.', $this->currentLineNb + 1, $this->currentLine, $this->filename);
|
||||
}
|
||||
|
@ -311,7 +298,7 @@ class Parser
|
|||
$subTag = null;
|
||||
if ($mergeNode) {
|
||||
// Merge keys
|
||||
} elseif (!isset($values['value']) || '' === $values['value'] || 0 === strpos($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
|
||||
} elseif (!isset($values['value']) || '' === $values['value'] || str_starts_with($values['value'], '#') || (null !== $subTag = $this->getLineTag($values['value'], $flags)) || '<<' === $key) {
|
||||
// hash
|
||||
// if next line is less indented or equal, then it means that the current value is null
|
||||
if (!$this->isNextLineIndented() && !$this->isNextLineUnIndentedCollection()) {
|
||||
|
@ -459,7 +446,7 @@ class Parser
|
|||
throw new ParseException('Unable to parse.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
||||
}
|
||||
|
||||
if (false !== strpos($line, ': ')) {
|
||||
if (str_contains($line, ': ')) {
|
||||
throw new ParseException('Mapping values are not allowed in multi-line blocks.', $this->getRealCurrentLineNb() + 1, $this->currentLine, $this->filename);
|
||||
}
|
||||
|
||||
|
@ -469,7 +456,7 @@ class Parser
|
|||
$value .= ' ';
|
||||
}
|
||||
|
||||
if ('' !== $trimmedLine && '\\' === substr($line, -1)) {
|
||||
if ('' !== $trimmedLine && str_ends_with($line, '\\')) {
|
||||
$value .= ltrim(substr($line, 0, -1));
|
||||
} elseif ('' !== $trimmedLine) {
|
||||
$value .= $trimmedLine;
|
||||
|
@ -478,7 +465,7 @@ class Parser
|
|||
if ('' === $trimmedLine) {
|
||||
$previousLineWasNewline = true;
|
||||
$previousLineWasTerminatedWithBackslash = false;
|
||||
} elseif ('\\' === substr($line, -1)) {
|
||||
} elseif (str_ends_with($line, '\\')) {
|
||||
$previousLineWasNewline = false;
|
||||
$previousLineWasTerminatedWithBackslash = true;
|
||||
} else {
|
||||
|
@ -489,7 +476,7 @@ class Parser
|
|||
|
||||
try {
|
||||
return Inline::parse(trim($value));
|
||||
} catch (ParseException $e) {
|
||||
} catch (ParseException) {
|
||||
// fall-through to the ParseException thrown below
|
||||
}
|
||||
}
|
||||
|
@ -515,7 +502,7 @@ class Parser
|
|||
return empty($data) ? null : $data;
|
||||
}
|
||||
|
||||
private function parseBlock(int $offset, string $yaml, int $flags)
|
||||
private function parseBlock(int $offset, string $yaml, int $flags): mixed
|
||||
{
|
||||
$skippedLineNumbers = $this->skippedLineNumbers;
|
||||
|
||||
|
@ -557,9 +544,6 @@ class Parser
|
|||
return $realCurrentLineNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current line indentation.
|
||||
*/
|
||||
private function getCurrentLineIndentation(): int
|
||||
{
|
||||
if (' ' !== ($this->currentLine[0] ?? '')) {
|
||||
|
@ -577,7 +561,7 @@ class Parser
|
|||
*
|
||||
* @throws ParseException When indentation problem are detected
|
||||
*/
|
||||
private function getNextEmbedBlock(int $indentation = null, bool $inSequence = false): string
|
||||
private function getNextEmbedBlock(?int $indentation = null, bool $inSequence = false): string
|
||||
{
|
||||
$oldLineIndentation = $this->getCurrentLineIndentation();
|
||||
|
||||
|
@ -654,12 +638,12 @@ class Parser
|
|||
}
|
||||
|
||||
if ($this->isCurrentLineBlank()) {
|
||||
$data[] = substr($this->currentLine, $newIndent);
|
||||
$data[] = substr($this->currentLine, $newIndent ?? 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($indent >= $newIndent) {
|
||||
$data[] = substr($this->currentLine, $newIndent);
|
||||
$data[] = substr($this->currentLine, $newIndent ?? 0);
|
||||
} elseif ($this->isCurrentLineComment()) {
|
||||
$data[] = $this->currentLine;
|
||||
} elseif (0 == $indent) {
|
||||
|
@ -714,13 +698,11 @@ class Parser
|
|||
* @param int $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior
|
||||
* @param string $context The parser context (either sequence or mapping)
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws ParseException When reference does not exist
|
||||
*/
|
||||
private function parseValue(string $value, int $flags, string $context)
|
||||
private function parseValue(string $value, int $flags, string $context): mixed
|
||||
{
|
||||
if (0 === strpos($value, '*')) {
|
||||
if (str_starts_with($value, '*')) {
|
||||
if (false !== $pos = strpos($value, '#')) {
|
||||
$value = substr($value, 1, $pos - 2);
|
||||
} else {
|
||||
|
@ -807,7 +789,7 @@ class Parser
|
|||
|
||||
$parsedValue = Inline::parse($value, $flags, $this->refs);
|
||||
|
||||
if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && false !== strpos($parsedValue, ': ')) {
|
||||
if ('mapping' === $context && \is_string($parsedValue) && '"' !== $value[0] && "'" !== $value[0] && '[' !== $value[0] && '{' !== $value[0] && '!' !== $value[0] && str_contains($parsedValue, ': ')) {
|
||||
throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this->getRealCurrentLineNb() + 1, $value, $this->filename);
|
||||
}
|
||||
|
||||
|
@ -861,8 +843,8 @@ class Parser
|
|||
|
||||
while (
|
||||
$notEOF && (
|
||||
$isCurrentLineBlank ||
|
||||
self::preg_match($pattern, $this->currentLine, $matches)
|
||||
$isCurrentLineBlank
|
||||
|| self::preg_match($pattern, $this->currentLine, $matches)
|
||||
)
|
||||
) {
|
||||
if ($isCurrentLineBlank && \strlen($this->currentLine) > $indentation) {
|
||||
|
@ -949,6 +931,10 @@ class Parser
|
|||
} while (!$EOF && ($this->isCurrentLineEmpty() || $this->isCurrentLineComment()));
|
||||
|
||||
if ($EOF) {
|
||||
for ($i = 0; $i < $movements; ++$i) {
|
||||
$this->moveToPreviousLine();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -961,25 +947,16 @@ class Parser
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is blank or if it is a comment line.
|
||||
*/
|
||||
private function isCurrentLineEmpty(): bool
|
||||
{
|
||||
return $this->isCurrentLineBlank() || $this->isCurrentLineComment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is blank.
|
||||
*/
|
||||
private function isCurrentLineBlank(): bool
|
||||
{
|
||||
return '' === $this->currentLine || '' === trim($this->currentLine, ' ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current line is a comment line.
|
||||
*/
|
||||
private function isCurrentLineComment(): bool
|
||||
{
|
||||
// checking explicitly the first char of the trim is faster than loops or strpos
|
||||
|
@ -993,11 +970,6 @@ class Parser
|
|||
return ($this->offset + $this->currentLineNb) >= ($this->totalNumberOfLines - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanups a YAML string to be parsed.
|
||||
*
|
||||
* @param string $value The input YAML string
|
||||
*/
|
||||
private function cleanup(string $value): string
|
||||
{
|
||||
$value = str_replace(["\r\n", "\r"], "\n", $value);
|
||||
|
@ -1029,9 +1001,6 @@ class Parser
|
|||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the next line starts unindented collection.
|
||||
*/
|
||||
private function isNextLineUnIndentedCollection(): bool
|
||||
{
|
||||
$currentIndentation = $this->getCurrentLineIndentation();
|
||||
|
@ -1058,12 +1027,9 @@ class Parser
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string is un-indented collection item.
|
||||
*/
|
||||
private function isStringUnIndentedCollectionItem(): bool
|
||||
{
|
||||
return '-' === rtrim($this->currentLine) || 0 === strpos($this->currentLine, '- ');
|
||||
return '-' === rtrim($this->currentLine) || str_starts_with($this->currentLine, '- ');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1075,34 +1041,12 @@ class Parser
|
|||
*
|
||||
* @throws ParseException on a PCRE internal error
|
||||
*
|
||||
* @see preg_last_error()
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static function preg_match(string $pattern, string $subject, array &$matches = null, int $flags = 0, int $offset = 0): int
|
||||
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()) {
|
||||
case \PREG_INTERNAL_ERROR:
|
||||
$error = 'Internal PCRE error.';
|
||||
break;
|
||||
case \PREG_BACKTRACK_LIMIT_ERROR:
|
||||
$error = 'pcre.backtrack_limit reached.';
|
||||
break;
|
||||
case \PREG_RECURSION_LIMIT_ERROR:
|
||||
$error = 'pcre.recursion_limit reached.';
|
||||
break;
|
||||
case \PREG_BAD_UTF8_ERROR:
|
||||
$error = 'Malformed UTF-8 data.';
|
||||
break;
|
||||
case \PREG_BAD_UTF8_OFFSET_ERROR:
|
||||
$error = 'Offset doesn\'t correspond to the begin of a valid UTF-8 code point.';
|
||||
break;
|
||||
default:
|
||||
$error = 'Error.';
|
||||
}
|
||||
|
||||
throw new ParseException($error);
|
||||
throw new ParseException(preg_last_error_msg());
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue