Completed
Push — master ( 74cb0e...b4285c )
by David
02:35
created

ClearCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 62
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 15 1
A execute() 0 22 3
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\HttpCacheBundle\Command;
13
14
use FOS\HttpCache\CacheInvalidator;
15
use FOS\HttpCacheBundle\CacheManager;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * A command to clear the whole cache from the command line.
21
 *
22
 * @author Alexander Schranz <[email protected]>
23
 */
24
class ClearCommand extends BaseInvalidateCommand
25
{
26
    use PathSanityCheck;
27
28
    protected static $defaultName = 'fos:httpcache:clear';
29
30
    /**
31
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
32
     * is automatically loaded.
33
     *
34
     * @param CacheManager|null $cacheManager The cache manager to talk to
35
     */
36 7
    public function __construct(CacheManager $cacheManager = null)
37
    {
38 7
        parent::__construct($cacheManager);
39 7
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 7
    protected function configure()
45
    {
46
        $this
47 7
            ->setDescription('Clear the HTTP cache.')
48 7
            ->setHelp(
49
                <<<'EOF'
50 7
The <info>%command.name%</info> command clears the whole cache or, if that is not supported, invalidates all cache entries in the configured caching proxies.
51
52
Example:
53
54
    <info>php %command.full_name%</info>
55
EOF
56
            )
57
        ;
58 7
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 6
    protected function execute(InputInterface $input, OutputInterface $output): int
64
    {
65 6
        $cacheManager = $this->getCacheManager();
66
67 6
        if ($cacheManager->supports(CacheInvalidator::CLEAR)) {
68 2
            $this->getCacheManager()->clearCache();
69
70 2
            return 0;
71
        }
72
73 4
        if ($cacheManager->supports(CacheInvalidator::INVALIDATE)) {
74 2
            $this->getCacheManager()->invalidateRegex('.*');
75
76 2
            return 0;
77
        }
78
79 2
        $output->writeln(
80 2
            '<error>The configured HTTP cache does not support "clear" or "invalidate".</error>'
81
        );
82
83 2
        return 1;
84
    }
85
}
86