From 1e7bbdeba1f5824781df4f8b116f79425c22c91c Mon Sep 17 00:00:00 2001 From: Alexis Thinardon Date: Thu, 4 Jan 2018 11:57:29 +0100 Subject: [PATCH] Change style when dump dictionaries --- CHANGELOG.md | 2 ++ .../Command/DictionaryDumpCommand.php | 27 ++++++++++--------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06c78ab4..77b44617 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Improve the format when call dump command ## [2.1.0] - 2017-12-22 ### Added diff --git a/src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php b/src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php index 5b516418..3816d451 100644 --- a/src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php +++ b/src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php @@ -63,11 +63,19 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->newLine(); // Read dictionaries information - $tableRows = $this->getDictionariesDetail($dictionaryName); + if (\is_null($dictionaryName)) { + $dictionaries = $this->registry->all(); + } else { + $dictionaries = [$this->registry->get($dictionaryName)]; + } + + $tableRows = $this->getDictionariesDetail($dictionaries); // Output data if (\sizeof($tableRows) > 0) { - $io->table([], $tableRows); + foreach ($tableRows as $header => $raws) { + $io->table([$header], $raws); + } } elseif (!\is_null($dictionaryName) && 0 === \sizeof($tableRows)) { $errorIo->error("No dictionary named $dictionaryName"); } @@ -75,21 +83,16 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * Get all dictionaries with they values - * If $dictionaryName is set, only display dictionary matching dictionary * - * @param null|string $dictionaryName the dictionary name asked for filtering + * @param array $dictionaries * @return array rows to display */ - private function getDictionariesDetail($dictionaryName = null) + private function getDictionariesDetail(array $dictionaries = []) { $tableRows = []; - /** @var Dictionary $dico */ - foreach ($this->registry->all() as $dico) { - if (!\is_null($dictionaryName) && $dictionaryName === $dico->getName() || \is_null($dictionaryName)) { - $tableRows[] = ["{$dico->getName()}"]; - foreach ($dico as $key => $value) { - $tableRows[] = [" $key\t| $value"]; - } + foreach ($dictionaries as $dico) { + foreach ($dico as $key => $value) { + $tableRows["{$dico->getName()}"][] = [$key, $value]; } }