Fix nested array lists

This commit is contained in:
Joas Schilling 2015-04-30 15:42:18 +02:00
parent 6d4cb1b480
commit 6ed8ba0ce9
1 changed files with 9 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class Base extends Command {
* @param OutputInterface $output * @param OutputInterface $output
* @param array $items * @param array $items
*/ */
protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items) { protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') {
switch ($input->getOption('output')) { switch ($input->getOption('output')) {
case 'json': case 'json':
$output->writeln(json_encode($items)); $output->writeln(json_encode($items));
@ -54,15 +54,20 @@ class Base extends Command {
break; break;
default: default:
foreach ($items as $key => $item) { foreach ($items as $key => $item) {
if (is_array($item)) {
$output->writeln($prefix . $key . ':');
$this->writeArrayInOutputFormat($input, $output, $item, ' ' . $prefix);
continue;
}
if (!is_int($key)) { if (!is_int($key)) {
$value = $this->valueToString($item); $value = $this->valueToString($item);
if (!is_null($value)) { if (!is_null($value)) {
$output->writeln(' - ' . $key . ': ' . $value); $output->writeln($prefix . $key . ': ' . $value);
} else { } else {
$output->writeln(' - ' . $key); $output->writeln($prefix . $key);
} }
} else { } else {
$output->writeln(' - ' . $this->valueToString($item)); $output->writeln($prefix . $this->valueToString($item));
} }
} }
break; break;