Symfony\Component\Yaml\Parser::parseValue PHP Method

parseValue() private method

Parses a YAML value.
private parseValue ( string $value, integer $flags, string $context ) : mixed
$value string A YAML value
$flags integer A bit field of PARSE_* constants to customize the YAML parser behavior
$context string The parser context (either sequence or mapping)
return mixed A PHP value
    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)) {
                throw new ParseException(sprintf('Reference "%s" does not exist.', $value), $this->currentLineNb + 1, $this->currentLine);
            }
            return $this->refs[$value];
        }
        if (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 (isset($matches['tag']) && '!!binary' === $matches['tag']) {
                return Inline::evaluateBinaryScalar($data);
            }
            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 && preg_match('/^' . $quotation . '.*' . $quotation . '(\\s*#.*)?$/', $value)) {
                return Inline::parse($value, $flags, $this->refs);
            }
            while ($this->moveToNextLine()) {
                // unquoted strings end before the first unindented line
                if (null === $quotation && $this->getCurrentLineIndentation() === 0) {
                    $this->moveToPreviousLine();
                    break;
                }
                $value .= ' ' . 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;
                }
            }
            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.');
            }
            return $parsedValue;
        } catch (ParseException $e) {
            $e->setParsedLine($this->getRealCurrentLineNb() + 1);
            $e->setSnippet($this->currentLine);
            throw $e;
        }
    }