You are here

public static function Inline::parse in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/symfony/yaml/Inline.php \Symfony\Component\Yaml\Inline::parse()

Converts a YAML string to a PHP array.

Parameters

string $value A YAML string:

bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise:

bool $objectSupport true if object support is enabled, false otherwise:

array $references Mapping of variable names to values:

Return value

array A PHP array representing the YAML string

Throws

ParseException

14 calls to Inline::parse()
InlineTest::testDump in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testParse in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testParseInvalidMappingKeyShouldThrowException in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
@expectedException \Symfony\Component\Yaml\Exception\ParseException
InlineTest::testParseInvalidMappingShouldThrowException in vendor/symfony/yaml/Symfony/Component/Yaml/Tests/InlineTest.php
@expectedException \Symfony\Component\Yaml\Exception\ParseException

... See full list

File

vendor/symfony/yaml/Symfony/Component/Yaml/Inline.php, line 41

Class

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

Namespace

Symfony\Component\Yaml

Code

public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $references = array()) {
  self::$exceptionOnInvalidType = $exceptionOnInvalidType;
  self::$objectSupport = $objectSupport;
  $value = trim($value);
  if ('' === $value) {
    return '';
  }
  if (function_exists('mb_internal_encoding') && (int) ini_get('mbstring.func_overload') & 2) {
    $mbEncoding = mb_internal_encoding();
    mb_internal_encoding('ASCII');
  }
  $i = 0;
  switch ($value[0]) {
    case '[':
      $result = self::parseSequence($value, $i, $references);
      ++$i;
      break;
    case '{':
      $result = self::parseMapping($value, $i, $references);
      ++$i;
      break;
    default:
      $result = self::parseScalar($value, null, array(
        '"',
        "'",
      ), $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)));
  }
  if (isset($mbEncoding)) {
    mb_internal_encoding($mbEncoding);
  }
  return $result;
}