Completed
Push — 2.x-dev-kit ( 6f250c )
by
unknown
02:44
created

CacheFlushAllCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 6
c 4
b 1
f 1
lcom 0
cbo 4
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 20 5
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\CacheBundle\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class CacheFlushAllCommand extends BaseCacheCommand
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function configure()
24
    {
25
        $this->setName('sonata:cache:flush-all');
26
        $this->setDescription('Flush all information set in cache managers');
27
28
        $this->addOption('cache', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Flush elements stored in given cache');
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        $output->writeln('<info>clearing cache information</info>');
37
38
        foreach ($this->getManager()->getCacheServices() as $name => $cache) {
39
            if ($input->getOption('cache') && !in_array($name, $input->getOption('cache'))) {
40
                continue;
41
            }
42
43
            $output->write(sprintf(' > %s : starting .... ', $name));
44
45
            if ($cache->flushAll() === true) {
46
                $output->writeln('<info>OK</info>');
47
            } else {
48
                $output->writeln('<error>FAILED!</error>');
49
            }
50
        }
51
52
        $output->writeln('<info>done!</info>');
53
    }
54
}
55