Completed
Push — master ( d2f8aa...3f97e5 )
by David de
66:53 queued 64:48
created

BaseInvalidateCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
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\HttpCacheBundle\CacheManager;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
17
/**
18
 * Base class for commands to trigger cache invalidation from the command line.
19
 *
20
 * @author David Buchmann <[email protected]>
21
 */
22
abstract class BaseInvalidateCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * @var CacheManager
26
     */
27
    private $cacheManager;
28
29
    /**
30
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
31
     * is automatically loaded.
32
     *
33
     * @param CacheManager|null $cacheManager The cache manager to talk to
34
     */
35 15
    public function __construct(CacheManager $cacheManager = null)
36
    {
37 15
        $this->cacheManager = $cacheManager;
38 15
        parent::__construct();
39 15
    }
40
41
    /**
42
     * Get the configured cache manager, loading fos_http_cache.cache_manager
43
     * from the container if none was specified.
44
     *
45
     * @return CacheManager
46
     */
47 10
    protected function getCacheManager()
48
    {
49 10
        if (!$this->cacheManager) {
50 1
            $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager');
51
        }
52
53 10
        return $this->cacheManager;
54
    }
55
}
56