You are here

private static function Inline::dumpArray in Zircon Profile 8

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

Dumps a PHP array to a YAML string.

Parameters

array $value The PHP array to dump:

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:

Return value

string The YAML string representing the PHP array

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

File

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

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);
  $keysCount = count($keys);
  if (1 === $keysCount && '0' == $keys[0] || $keysCount > 1 && array_reduce($keys, function ($v, $w) {
    return (int) $v + $w;
  }, 0) === $keysCount * ($keysCount - 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));
}