1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleDIC\Console; |
4
|
|
|
|
5
|
|
|
use SimpleDIC\DIC; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Symfony\Component\Console\Helper\Table; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
12
|
|
|
|
13
|
|
|
class CacheDestroyCommand extends Command |
14
|
|
|
{ |
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
$this |
18
|
|
|
->setName('dic:cache-destroy') |
19
|
|
|
->setDescription('Destroy the cache created by DIC.') |
20
|
|
|
->setHelp('This command try to destroy cache files created by DIC and clear apcu cache.') |
21
|
|
|
->addArgument('cache_dir', InputArgument::OPTIONAL) |
22
|
|
|
; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
26
|
|
|
{ |
27
|
|
|
$cacheDir = !empty($input->getArgument('cache_dir')) ? $input->getArgument('cache_dir') : __DIR__.'/../../_cache'; |
28
|
|
|
|
29
|
|
|
if (false === is_dir($cacheDir)) { |
|
|
|
|
30
|
|
|
throw new \InvalidArgumentException($cacheDir . ' is not a valid dir'); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
foreach (scandir($cacheDir) as $file) { |
|
|
|
|
34
|
|
|
if (!in_array($file, ['.', '..'])) { |
35
|
|
|
|
36
|
|
|
// destroy apcu |
37
|
|
|
if (extension_loaded('apc') && ini_get('apc.enabled')) { |
38
|
|
|
$filePath = $cacheDir . DIRECTORY_SEPARATOR . $file; |
39
|
|
|
$array = include($filePath); |
40
|
|
|
|
41
|
|
|
foreach ($array as $id => $entry) { |
42
|
|
|
apcu_delete(md5(sha1_file($filePath). DIRECTORY_SEPARATOR .$id)); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// delete file |
47
|
|
|
unlink($filePath); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$output->writeln('<fg=green>Cache was successfully cleared.</>'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|