DumpCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 5
c 4
b 0
f 3
lcom 0
cbo 4
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 19 4
A configure() 0 17 1
1
<?php
2
3
namespace Sleepness\UberTranslationBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Dump all translations stored in memcache
11
 *
12
 * @author Viktor Novikov <[email protected]>
13
 */
14
class DumpCommand extends ContainerAwareCommand
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function configure()
20
    {
21
        $this
22
            ->setName('uber:translations:dump')
23
            ->setDefinition(array())
24
            ->setDescription('Dump translations what stores in memcached')
25
            ->setHelp("
26
The <info>uber:translations:dump</info> command dump all translations from memcahced and output to console:
27
28
  <info>./app/console uber:translations:dumpe</info>
29
30
Command example:
31
32
  <info>./app/console uber:translations:dump</info>
33
34
            ");
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $uberMemcached = $this->getContainer()->get('uber.memcached'); // get uber memcached
43
        $memcachedKeys = $uberMemcached->getAllKeys();
44
        $output->writeln("\033[37;43m Translations from memcache: \033[0m");
45
        foreach ($memcachedKeys as $key) { // run through locales
46
            $output->writeln("\033[94mLocale: $key \033[0m");
47
            $translations = $uberMemcached->getItem($key);
48
            foreach ($translations as $domain => $messages) {
49
                $output->writeln("-------------------------");
50
                $output->writeln("\033[96mDomain: $domain \033[0m");
51
                $output->writeln("-------------------------");
52
                $output->writeln("\033[92m| Key | Value | \033[0m");
53
                foreach ($messages as $key => $value) {
54
                    $output->writeln("| $key | $value |");
55
                }
56
            }
57
        }
58
    }
59
}
60