1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of phpFastCache. |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For full copyright and license information, please see the docs/CREDITS.txt file. |
10
|
|
|
* |
11
|
|
|
* @author Georges.L (Geolim4) <[email protected]> |
12
|
|
|
* @author PastisD https://github.com/PastisD |
13
|
|
|
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com |
14
|
|
|
* |
15
|
|
|
*/ |
16
|
|
|
declare(strict_types=1); |
17
|
|
|
|
18
|
|
|
namespace Phpfastcache\Bundle\Command; |
19
|
|
|
|
20
|
|
|
use Phpfastcache\Bundle\Service\Phpfastcache; |
21
|
|
|
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; |
22
|
|
|
use Symfony\Component\Console\Command\Command; |
23
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
25
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
26
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
27
|
|
|
|
28
|
|
|
class PhpfastcacheDelCommand extends Command |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var \Phpfastcache\Bundle\Service\Phpfastcache |
32
|
|
|
*/ |
33
|
|
|
protected $phpfastcache; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var |
37
|
|
|
*/ |
38
|
|
|
protected $parameters; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* PhpfastcacheCommand constructor. |
42
|
|
|
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache |
43
|
|
|
* @param $parameters |
44
|
|
|
*/ |
45
|
|
|
public function __construct(Phpfastcache $phpfastcache, $parameters) |
46
|
|
|
{ |
47
|
|
|
$this->phpfastcache = $phpfastcache; |
48
|
|
|
$this->parameters = $parameters; |
49
|
|
|
|
50
|
|
|
parent::__construct(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
protected function configure() |
54
|
|
|
{ |
55
|
|
|
$this |
56
|
|
|
->setName('phpfastcache:del') |
57
|
|
|
->setAliases([ 'phpfastcache:delete', 'phpfastcache:rem', 'phpfastcache:remove']) |
58
|
|
|
->setDescription('Delete phpfastcache cache value') |
59
|
|
|
->addArgument( |
60
|
|
|
'driver', |
61
|
|
|
InputArgument::REQUIRED, |
62
|
|
|
'Cache name to clear' |
63
|
|
|
) |
64
|
|
|
->addArgument( |
65
|
|
|
'key', |
66
|
|
|
InputArgument::REQUIRED, |
67
|
|
|
'Cache key' |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
73
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
74
|
|
|
* @return int|null|void |
75
|
|
|
*/ |
76
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
77
|
|
|
{ |
78
|
|
|
$io = new SymfonyStyle($input, $output); |
79
|
|
|
$caches = $this->parameters; |
80
|
|
|
|
81
|
|
|
$driver = $input->getArgument('driver'); |
82
|
|
|
$cacheKey = $input->getArgument('key'); |
83
|
|
|
|
84
|
|
|
if (\array_key_exists($driver, $caches[ 'drivers' ])) { |
85
|
|
|
$io->section($driver); |
86
|
|
|
$driverInstance = $this->phpfastcache->get($driver); |
87
|
|
|
$cacheItem = $driverInstance->getItem($cacheKey); |
88
|
|
|
|
89
|
|
|
if(!$cacheItem->isHit()){ |
90
|
|
|
$io->note(\sprintf('Cache item "%s" does not exists in the cache', $cacheKey)); |
91
|
|
|
}else{ |
92
|
|
|
$driverInstance->deleteItem($cacheItem->getKey()); |
93
|
|
|
$io->success(\sprintf('Cache item "%s" has been deleted from cache', $cacheKey)); |
94
|
|
|
} |
95
|
|
|
} else { |
96
|
|
|
$io->error("Cache instance {$driver} does not exists"); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |