You are here

public static function Inline::parse in Lockr 7.3

Converts a YAML string to a PHP value.

Parameters

string $value A YAML string:

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

array $references Mapping of variable names to values:

Return value

mixed A PHP value

Throws

ParseException

41 calls to Inline::parse()
InlineTest::testDeprecatedConstantTag in vendor/symfony/yaml/Tests/InlineTest.php
@group legacy @expectedDeprecation The !php/const: tag to indicate dumped PHP constants is deprecated since Symfony 3.4 and will be removed in 4.0. Use the !php/const (without the colon) tag instead on line 1. @dataProvider…
InlineTest::testDeprecatedStrTag in vendor/symfony/yaml/Tests/InlineTest.php
@group legacy @expectedDeprecation Support for the !str tag is deprecated since Symfony 3.4. Use the !!str tag instead on line 1.
InlineTest::testDump in vendor/symfony/yaml/Tests/InlineTest.php
@dataProvider getTestsForDump
InlineTest::testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF in vendor/symfony/yaml/Tests/InlineTest.php
InlineTest::testImplicitStringCastingOfMappingKeysIsDeprecated in vendor/symfony/yaml/Tests/InlineTest.php
@group legacy @expectedDeprecation Implicit casting of incompatible mapping keys to strings is deprecated since Symfony 3.3 and will throw \Symfony\Component\Yaml\Exception\ParseException in 4.0. Quote your evaluable mapping keys instead on line…

... See full list

File

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

Class

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

Namespace

Symfony\Component\Yaml

Code

public static function parse($value, $flags = 0, $references = []) {
  if (\is_bool($flags)) {
    @trigger_error('Passing a boolean flag to toggle exception handling is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE flag instead.', E_USER_DEPRECATED);
    if ($flags) {
      $flags = Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE;
    }
    else {
      $flags = 0;
    }
  }
  if (\func_num_args() >= 3 && !\is_array($references)) {
    @trigger_error('Passing a boolean flag to toggle object support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT flag instead.', E_USER_DEPRECATED);
    if ($references) {
      $flags |= Yaml::PARSE_OBJECT;
    }
    if (\func_num_args() >= 4) {
      @trigger_error('Passing a boolean flag to toggle object for map support is deprecated since Symfony 3.1 and will be removed in 4.0. Use the Yaml::PARSE_OBJECT_FOR_MAP flag instead.', E_USER_DEPRECATED);
      if (func_get_arg(3)) {
        $flags |= Yaml::PARSE_OBJECT_FOR_MAP;
      }
    }
    if (\func_num_args() >= 5) {
      $references = func_get_arg(4);
    }
    else {
      $references = [];
    }
  }
  self::initialize($flags);
  $value = trim($value);
  if ('' === $value) {
    return '';
  }
  if (2 & (int) ini_get('mbstring.func_overload')) {
    $mbEncoding = mb_internal_encoding();
    mb_internal_encoding('ASCII');
  }
  try {
    $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, null === $tag, $references);
    }
    if (null !== $tag) {
      return new TaggedValue($tag, $result);
    }

    // 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);
    }
    return $result;
  } finally {
    if (isset($mbEncoding)) {
      mb_internal_encoding($mbEncoding);
    }
  }
}