1 | <?php |
||
2 | |||
3 | namespace Matecat\SimpleS3\Console; |
||
4 | |||
5 | use Matecat\SimpleS3\Client; |
||
6 | use Symfony\Component\Console\Command\Command; |
||
7 | use Symfony\Component\Console\Input\InputInterface; |
||
8 | use Symfony\Component\Console\Output\OutputInterface; |
||
9 | |||
10 | class CacheFlushCommand extends Command |
||
11 | { |
||
12 | /** |
||
13 | * @var Client |
||
14 | */ |
||
15 | private $s3Client; |
||
16 | |||
17 | /** |
||
18 | * CacheFlushCommand constructor. |
||
19 | * |
||
20 | * @param Client $s3Client |
||
21 | * @param null $name |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
22 | */ |
||
23 | public function __construct(Client $s3Client, $name = null) |
||
24 | { |
||
25 | parent::__construct($name); |
||
26 | |||
27 | $this->s3Client = $s3Client; |
||
28 | } |
||
29 | |||
30 | protected function configure() |
||
31 | { |
||
32 | $this |
||
33 | ->setName('ss3:cache:flush') |
||
34 | ->setDescription('Flush all data stored in cache.') |
||
35 | ->setHelp('This command flushes all data stored in cache.') |
||
36 | ; |
||
37 | } |
||
38 | |||
39 | protected function execute(InputInterface $input, OutputInterface $output) |
||
40 | { |
||
41 | if (false === $this->s3Client->hasCache()) { |
||
42 | throw new \Exception('Cache in not enabled. You have to enable caching to use this command'); |
||
43 | } |
||
44 | |||
45 | if (true === $this->s3Client->getCache()->flushAll()) { |
||
46 | $output->writeln('<fg=green>Cache was successful flushed.</>'); |
||
47 | } else { |
||
48 | $output->writeln('<fg=red>Error during cache flushing.</>'); |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 |