|
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 LogicException; |
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Base class for commands to trigger cache invalidation from the command line. |
|
22
|
|
|
* |
|
23
|
|
|
* @author David Buchmann <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class BaseInvalidateCommand extends Command |
|
26
|
|
|
{ |
|
27
|
|
|
use ContainerAwareTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var CacheManager |
|
31
|
|
|
*/ |
|
32
|
|
|
private $cacheManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* If no cache manager is specified explicitly, fos_http_cache.cache_manager |
|
36
|
|
|
* is automatically loaded. |
|
37
|
|
|
* |
|
38
|
|
|
* @param CacheManager|null $cacheManager The cache manager to talk to |
|
39
|
|
|
*/ |
|
40
|
14 |
|
public function __construct(CacheManager $cacheManager = null) |
|
41
|
|
|
{ |
|
42
|
14 |
|
if (!$cacheManager) { |
|
43
|
1 |
|
@trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
14 |
|
$this->cacheManager = $cacheManager; |
|
46
|
14 |
|
parent::__construct(); |
|
47
|
14 |
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get the configured cache manager, loading fos_http_cache.cache_manager |
|
51
|
|
|
* from the container if none was specified. |
|
52
|
|
|
* |
|
53
|
|
|
* @return CacheManager |
|
|
|
|
|
|
54
|
|
|
*/ |
|
55
|
9 |
|
protected function getCacheManager() |
|
56
|
|
|
{ |
|
57
|
9 |
|
if (!$this->cacheManager) { |
|
58
|
1 |
|
$this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
9 |
|
return $this->cacheManager; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return ContainerInterface |
|
66
|
|
|
* |
|
67
|
|
|
* @throws \LogicException |
|
68
|
|
|
*/ |
|
69
|
1 |
|
protected function getContainer() |
|
70
|
|
|
{ |
|
71
|
1 |
|
if (null === $this->container) { |
|
72
|
|
|
$application = $this->getApplication(); |
|
73
|
|
|
if (null === $application) { |
|
74
|
|
|
throw new LogicException('The container cannot be retrieved as the application instance is not yet set.'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$this->container = $application->getKernel()->getContainer(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
return $this->container; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: