diff options
Diffstat (limited to 'core/command/base.php')
-rw-r--r-- | core/command/base.php | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/core/command/base.php b/core/command/base.php index 7dba2fde010..7e61c0cb9ab 100644 --- a/core/command/base.php +++ b/core/command/base.php @@ -75,13 +75,37 @@ class Base extends Command { } } - protected function valueToString($value) { + /** + * @param InputInterface $input + * @param OutputInterface $output + * @param mixed $item + */ + protected function writeMixedInOutputFormat(InputInterface $input, OutputInterface $output, $item) { + if (is_array($item)) { + $this->writeArrayInOutputFormat($input, $output, $item, ''); + return; + } + + switch ($input->getOption('output')) { + case 'json': + $output->writeln(json_encode($item)); + break; + case 'json_pretty': + $output->writeln(json_encode($item, JSON_PRETTY_PRINT)); + break; + default: + $output->writeln($this->valueToString($item, false)); + break; + } + } + + protected function valueToString($value, $returnNull = true) { if ($value === false) { return 'false'; } else if ($value === true) { return 'true'; } else if ($value === null) { - null; + return ($returnNull) ? null : 'null'; } else { return $value; } |