private static function Inline::parseMapping in Lockr 7.3
Parses a YAML mapping.
Parameters
string $mapping:
int $flags:
int &$i:
array $references:
Return value
array|\stdClass
Throws
ParseException When malformed inline YAML string is parsed
2 calls to Inline::parseMapping()
- Inline::parse in vendor/
symfony/ yaml/ Inline.php - Converts a YAML string to a PHP value.
- Inline::parseSequence in vendor/
symfony/ yaml/ Inline.php - Parses a YAML sequence.
File
- vendor/
symfony/ yaml/ Inline.php, line 481
Class
- Inline
- Inline implements a YAML parser/dumper for the YAML inline syntax.
Namespace
Symfony\Component\YamlCode
private static function parseMapping($mapping, $flags, &$i = 0, $references = []) {
$output = [];
$len = \strlen($mapping);
++$i;
$allowOverwrite = false;
// {foo: bar, bar:foo, ...}
while ($i < $len) {
switch ($mapping[$i]) {
case ' ':
case ',':
++$i;
continue 2;
case '}':
if (self::$objectForMap) {
return (object) $output;
}
return $output;
}
// key
$isKeyQuoted = \in_array($mapping[$i], [
'"',
"'",
], true);
$key = self::parseScalar($mapping, $flags, [
':',
' ',
], $i, false, [], true);
if (':' !== $key && false === ($i = strpos($mapping, ':', $i))) {
break;
}
if (':' === $key) {
@trigger_error(self::getDeprecationMessage('Omitting the key of a mapping is deprecated and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
}
if (!$isKeyQuoted) {
$evaluatedKey = self::evaluateScalar($key, $flags, $references);
if ('' !== $key && $evaluatedKey !== $key && !\is_string($evaluatedKey) && !\is_int($evaluatedKey)) {
@trigger_error(self::getDeprecationMessage('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.'), E_USER_DEPRECATED);
}
}
if (':' !== $key && !$isKeyQuoted && (!isset($mapping[$i + 1]) || !\in_array($mapping[$i + 1], [
' ',
',',
'[',
']',
'{',
'}',
], true))) {
@trigger_error(self::getDeprecationMessage('Using a colon after an unquoted mapping key that is not followed by an indication character (i.e. " ", ",", "[", "]", "{", "}") is deprecated since Symfony 3.2 and will throw a ParseException in 4.0.'), E_USER_DEPRECATED);
}
if ('<<' === $key) {
$allowOverwrite = true;
}
while ($i < $len) {
if (':' === $mapping[$i] || ' ' === $mapping[$i]) {
++$i;
continue;
}
$tag = self::parseTag($mapping, $i, $flags);
switch ($mapping[$i]) {
case '[':
// nested sequence
$value = self::parseSequence($mapping, $flags, $i, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
// But overwriting is allowed when a merge node is used in current block.
if ('<<' === $key) {
foreach ($value as $parsedValue) {
$output += $parsedValue;
}
}
elseif ($allowOverwrite || !isset($output[$key])) {
if (null !== $tag) {
$output[$key] = new TaggedValue($tag, $value);
}
else {
$output[$key] = $value;
}
}
elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \\Symfony\\Component\\Yaml\\Exception\\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
}
break;
case '{':
// nested mapping
$value = self::parseMapping($mapping, $flags, $i, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
// But overwriting is allowed when a merge node is used in current block.
if ('<<' === $key) {
$output += $value;
}
elseif ($allowOverwrite || !isset($output[$key])) {
if (null !== $tag) {
$output[$key] = new TaggedValue($tag, $value);
}
else {
$output[$key] = $value;
}
}
elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \\Symfony\\Component\\Yaml\\Exception\\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
}
break;
default:
$value = self::parseScalar($mapping, $flags, [
',',
'}',
], $i, null === $tag, $references);
// Spec: Keys MUST be unique; first one wins.
// Parser cannot abort this mapping earlier, since lines
// are processed sequentially.
// But overwriting is allowed when a merge node is used in current block.
if ('<<' === $key) {
$output += $value;
}
elseif ($allowOverwrite || !isset($output[$key])) {
if (null !== $tag) {
$output[$key] = new TaggedValue($tag, $value);
}
else {
$output[$key] = $value;
}
}
elseif (isset($output[$key])) {
@trigger_error(self::getDeprecationMessage(sprintf('Duplicate key "%s" detected whilst parsing YAML. Silent handling of duplicate mapping keys in YAML is deprecated since Symfony 3.2 and will throw \\Symfony\\Component\\Yaml\\Exception\\ParseException in 4.0.', $key)), E_USER_DEPRECATED);
}
--$i;
}
++$i;
continue 2;
}
}
throw new ParseException(sprintf('Malformed inline YAML string: %s.', $mapping), self::$parsedLineNumber + 1, null, self::$parsedFilename);
}