private function Parser::parseValue in Lockr 7.3
Parses a YAML value.
Parameters
string $value A YAML value:
int $flags A bit field of PARSE_* constants to customize the YAML parser behavior:
string $context The parser context (either sequence or mapping):
Return value
mixed A PHP value
Throws
ParseException When reference does not exist
1 call to Parser::parseValue()
- Parser::doParse in vendor/
symfony/ yaml/ Parser.php
File
- vendor/
symfony/ yaml/ Parser.php, line 692
Class
- Parser
- Parser parses YAML strings to convert them to PHP arrays.
Namespace
Symfony\Component\YamlCode
private function parseValue($value, $flags, $context) {
if (0 === strpos($value, '*')) {
if (false !== ($pos = strpos($value, '#'))) {
$value = substr($value, 1, $pos - 2);
}
else {
$value = substr($value, 1);
}
if (!\array_key_exists($value, $this->refs)) {
if (false !== ($pos = array_search($value, $this->refsBeingParsed, true))) {
throw new ParseException(sprintf('Circular reference [%s, %s] detected for reference "%s".', implode(', ', \array_slice($this->refsBeingParsed, $pos)), $value, $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
}
throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine, $this->filename);
}
return $this->refs[$value];
}
if (self::preg_match('/^(?:' . self::TAG_PATTERN . ' +)?' . self::BLOCK_SCALAR_HEADER_PATTERN . '$/', $value, $matches)) {
$modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
$data = $this
->parseBlockScalar($matches['separator'], preg_replace('#\\d+#', '', $modifiers), (int) abs($modifiers));
if ('' !== $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 $data;
}
try {
$quotation = '' !== $value && ('"' === $value[0] || "'" === $value[0]) ? $value[0] : null;
// do not take following lines into account when the current line is a quoted single line value
if (null !== $quotation && self::preg_match('/^' . $quotation . '.*' . $quotation . '(\\s*#.*)?$/', $value)) {
return Inline::parse($value, $flags, $this->refs);
}
$lines = [];
while ($this
->moveToNextLine()) {
// unquoted strings end before the first unindented line
if (null === $quotation && 0 === $this
->getCurrentLineIndentation()) {
$this
->moveToPreviousLine();
break;
}
$lines[] = trim($this->currentLine);
// quoted string values end with a line that is terminated with the quotation character
if ('' !== $this->currentLine && substr($this->currentLine, -1) === $quotation) {
break;
}
}
for ($i = 0, $linesCount = \count($lines), $previousLineBlank = false; $i < $linesCount; ++$i) {
if ('' === $lines[$i]) {
$value .= "\n";
$previousLineBlank = true;
}
elseif ($previousLineBlank) {
$value .= $lines[$i];
$previousLineBlank = false;
}
else {
$value .= ' ' . $lines[$i];
$previousLineBlank = false;
}
}
Inline::$parsedLineNumber = $this
->getRealCurrentLineNb();
$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, ': ')) {
throw new ParseException('A colon cannot be used in an unquoted mapping value.', $this
->getRealCurrentLineNb() + 1, $value, $this->filename);
}
return $parsedValue;
} catch (ParseException $e) {
$e
->setParsedLine($this
->getRealCurrentLineNb() + 1);
$e
->setSnippet($this->currentLine);
throw $e;
}
}