You are here

public static function Inline::parse in Service Container 7.2

Same name and namespace in other branches
  1. 7 modules/providers/service_container_symfony/lib/Symfony/Component/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:

bool $objectForMap true if maps should return a stdClass instead of array():

array $references Mapping of variable names to values:

Return value

array A PHP array representing the YAML string

Throws

ParseException

15 calls to Inline::parse()
InlineTest::testDump in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Tests/InlineTest.php
@dataProvider getTestsForDump
InlineTest::testHashStringsResemblingExponentialNumericsShouldNotBeChangedToINF in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Tests/InlineTest.php
InlineTest::testParse in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Tests/InlineTest.php
@dataProvider getTestsForParse
InlineTest::testParseInvalidMappingKeyShouldThrowException in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Tests/InlineTest.php
@expectedException \Symfony\Component\Yaml\Exception\ParseException
InlineTest::testParseInvalidMappingShouldThrowException in modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Tests/InlineTest.php
@expectedException \Symfony\Component\Yaml\Exception\ParseException

... See full list

File

modules/providers/service_container_symfony/lib/Symfony/Component/Yaml/Inline.php, line 43

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, $objectForMap = false, $references = array()) {
  self::$exceptionOnInvalidType = $exceptionOnInvalidType;
  self::$objectSupport = $objectSupport;
  self::$objectForMap = $objectForMap;
  $value = trim($value);
  if (0 == strlen($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;
}