You are here

private static function Inline::dumpArray in Translation template extractor 6.3

Same name and namespace in other branches
  1. 7.3 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::dumpArray()
  2. 7.2 vendor/Symfony/Component/Yaml/Inline.php \Symfony\Component\Yaml\Inline::dumpArray()

Dumps a PHP array to a YAML string.

Parameters

array $value The PHP array to dump:

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

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

Return value

string The YAML string representing the PHP array

1 call to Inline::dumpArray()
Inline::dump in vendor/Symfony/Component/Yaml/Inline.php
Dumps a given PHP variable to a YAML string.

File

vendor/Symfony/Component/Yaml/Inline.php, line 156

Class

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

Namespace

Symfony\Component\Yaml

Code

private static function dumpArray($value, $exceptionOnInvalidType, $objectSupport) {

  // array
  $keys = array_keys($value);
  if (1 == count($keys) && '0' == $keys[0] || count($keys) > 1 && array_reduce($keys, function ($v, $w) {
    return (int) $v + $w;
  }, 0) == count($keys) * (count($keys) - 1) / 2) {
    $output = array();
    foreach ($value as $val) {
      $output[] = self::dump($val, $exceptionOnInvalidType, $objectSupport);
    }
    return sprintf('[%s]', implode(', ', $output));
  }

  // mapping
  $output = array();
  foreach ($value as $key => $val) {
    $output[] = sprintf('%s: %s', self::dump($key, $exceptionOnInvalidType, $objectSupport), self::dump($val, $exceptionOnInvalidType, $objectSupport));
  }
  return sprintf('{ %s }', implode(', ', $output));
}