Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Inline.php

function Inline::parse

Converts a YAML string to a PHP value.

Parameters

int $flags A bit field of Yaml::PARSE_* constants to customize the YAML parser behavior:

array $references Mapping of variable names to values:

Throws

ParseException

2 calls to Inline::parse()
Parser::doParse in vendor/symfony/yaml/Parser.php
Parser::parseValue in vendor/symfony/yaml/Parser.php
Parses a YAML value.

File

vendor/symfony/yaml/Inline.php, line 58

Class

Inline
Inline implements a YAML parser/dumper for the YAML inline syntax.

Namespace

Symfony\Component\Yaml

Code

public static function parse(string $value, int $flags = 0, array &$references = []) : mixed {
    self::initialize($flags);
    $value = trim($value);
    if ('' === $value) {
        return '';
    }
    $i = 0;
    $tag = self::parseTag($value, $i, $flags);
    switch ($value[$i]) {
        case '[':
            $result = self::parseSequence($value, $flags, $i, $references);
            ++$i;
            break;
        case '{':
            $result = self::parseMapping($value, $flags, $i, $references);
            ++$i;
            break;
        default:
            $result = self::parseScalar($value, $flags, null, $i, true, $references);
    }
    // some comments are allowed at the end
    if (preg_replace('/\\s*#.*$/A', '', substr($value, $i))) {
        throw new ParseException(\sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
    }
    if (null !== $tag && '' !== $tag) {
        return new TaggedValue($tag, $result);
    }
    return $result;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal