Skip to content

Commit

Permalink
Fix some mistakes asked in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Awkan committed Dec 22, 2017
1 parent b7d605c commit 4f5e73c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,20 @@ App\Entity\User:
city: <dictionary('cities')>
```

## Use dictionary command

You can use the following command to show your app dictionaries easily:
```bash
php app/console knp:dictionary:dump # SF2
php bin/console knp:dictionary:dump # SF3 / SF4
```

If you want to display only one dictionary, you can set it name in argument
```bash
php app/console knp:dictionary:dump my_dictionary # SF2
php bin/console knp:dictionary:dump my_dictionary # SF3 / SF4
```

## Create your own dictionary implementation

### Dictionary
Expand Down
18 changes: 9 additions & 9 deletions src/Knp/DictionaryBundle/Command/DictionaryDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Knp\DictionaryBundle\Dictionary;
use Knp\DictionaryBundle\Dictionary\DictionaryRegistry;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -13,7 +13,7 @@
/**
* Dump dictionaries with their related values
*/
class DictionaryDumpCommand extends ContainerAwareCommand
class DictionaryDumpCommand extends Command
{
protected static $defaultName = 'knp:dictionary:dump';

Expand All @@ -31,14 +31,14 @@ public function __construct(DictionaryRegistry $registry)
protected function configure()
{
$this
->setDescription('Dump KNP Dictionnaries')
->setDescription('Dump Dictionaries')
->setHelp('This command allows you to dump KNP dictionnaries and their values')
->addArgument(
'dictionary',
InputArgument::OPTIONAL,
'Dictionary name you want to display'
)
->setHelp(<<<'EOF'
->setHelp(<<<EOF
The <info>%command.name%</info> list all dictionaries with their related values.
You can choose to list a specific dictionary:
Expand All @@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// Add output context text
$io->title('KNP Dictionary');
$io->text('Here is the KNP Directory with their related values');
$io->text('Here are the dictionaries with their related key-values:');
if (!\is_null($dictionaryName)) {
$io->text("Search for dictionary named <fg=green>$dictionaryName</fg=green>");
}
Expand All @@ -66,9 +66,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$tableRows = $this->getDictionariesDetail($dictionaryName);

// Output data
if (sizeof($tableRows) > 0) {
if (\sizeof($tableRows) > 0) {
$io->table([], $tableRows);
} elseif (!\is_null($dictionaryName) && 0 === sizeof($tableRows)) {
} elseif (!\is_null($dictionaryName) && 0 === \sizeof($tableRows)) {
$errorIo->error("No dictionary named $dictionaryName");
}
}
Expand All @@ -87,8 +87,8 @@ private function getDictionariesDetail($dictionaryName = null)
foreach ($this->registry->all() as $dico) {
if (!\is_null($dictionaryName) && $dictionaryName === $dico->getName() || \is_null($dictionaryName)) {
$tableRows[] = ["<fg=cyan>{$dico->getName()}</fg=cyan>"];
foreach ($dico->getValues() as $value) {
$tableRows[] = [" $value"];
foreach ($dico as $key => $value) {
$tableRows[] = [" $key\t| $value"];
}
}
}
Expand Down

0 comments on commit 4f5e73c

Please sign in to comment.