diff --git a/core/command/app/listapps.php b/core/command/app/listapps.php index e30baddb74..e483037d45 100644 --- a/core/command/app/listapps.php +++ b/core/command/app/listapps.php @@ -73,7 +73,7 @@ class ListApps extends Base { */ protected function writeAppList(InputInterface $input, OutputInterface $output, $items) { switch ($input->getOption('output')) { - case 'plain': + case self::OUTPUT_FORMAT_PLAIN: $output->writeln('Enabled:'); parent::writeArrayInOutputFormat($input, $output, $items['enabled']); diff --git a/core/command/base.php b/core/command/base.php index 7936e683dc..0a4b002c1c 100644 --- a/core/command/base.php +++ b/core/command/base.php @@ -27,7 +27,11 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Base extends Command { - protected $defaultOutputFormat = 'plain'; + const OUTPUT_FORMAT_PLAIN = 'plain'; + const OUTPUT_FORMAT_JSON = 'json'; + const OUTPUT_FORMAT_JSON_PRETTY = 'json_pretty'; + + protected $defaultOutputFormat = self::OUTPUT_FORMAT_PLAIN; protected function configure() { $this @@ -49,10 +53,10 @@ class Base extends Command { */ protected function writeArrayInOutputFormat(InputInterface $input, OutputInterface $output, $items, $prefix = ' - ') { switch ($input->getOption('output')) { - case 'json': + case self::OUTPUT_FORMAT_JSON: $output->writeln(json_encode($items)); break; - case 'json_pretty': + case self::OUTPUT_FORMAT_JSON_PRETTY: $output->writeln(json_encode($items, JSON_PRETTY_PRINT)); break; default: @@ -89,10 +93,10 @@ class Base extends Command { } switch ($input->getOption('output')) { - case 'json': + case self::OUTPUT_FORMAT_JSON: $output->writeln(json_encode($item)); break; - case 'json_pretty': + case self::OUTPUT_FORMAT_JSON_PRETTY: $output->writeln(json_encode($item, JSON_PRETTY_PRINT)); break; default: diff --git a/core/command/config/listconfigs.php b/core/command/config/listconfigs.php index d80bd2b98c..fed6a8e9db 100644 --- a/core/command/config/listconfigs.php +++ b/core/command/config/listconfigs.php @@ -30,7 +30,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ListConfigs extends Base { - protected $defaultOutputFormat = 'json_pretty'; + protected $defaultOutputFormat = self::OUTPUT_FORMAT_JSON_PRETTY; /** @var array */ protected $sensitiveValues = [ diff --git a/core/command/encryption/listmodules.php b/core/command/encryption/listmodules.php index d55480def8..cc436ea562 100644 --- a/core/command/encryption/listmodules.php +++ b/core/command/encryption/listmodules.php @@ -65,7 +65,7 @@ class ListModules extends Base { * @param array $items */ protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { - if ($input->getOption('output') === 'plain') { + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { array_walk($items, function(&$item) { if (!$item['default']) { $item = $item['displayName'];