|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Cecil. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Arnaud Ligny <[email protected]> |
|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Cecil\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Cecil\Util; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* CacheClearTemplates command. |
|
24
|
|
|
* |
|
25
|
|
|
* This command removes cached templates files from the templates cache directory. |
|
26
|
|
|
* It can clear the entire templates cache or just the fragments cache, depending on the options provided. |
|
27
|
|
|
*/ |
|
28
|
|
|
class CacheClearTemplates extends AbstractCommand |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function configure() |
|
34
|
|
|
{ |
|
35
|
|
|
$this |
|
36
|
|
|
->setName('cache:clear:templates') |
|
37
|
|
|
->setDescription('Removes templates cache') |
|
38
|
|
|
->setDefinition([ |
|
39
|
|
|
new InputArgument('path', InputArgument::OPTIONAL, 'Use the given path as working directory'), |
|
40
|
|
|
new InputOption('fragments', null, InputOption::VALUE_NONE, 'Remove fragments cache only'), |
|
41
|
|
|
]) |
|
42
|
|
|
->setHelp( |
|
43
|
|
|
<<<'EOF' |
|
44
|
|
|
The <info>%command.name%</> command removes cached templates files. |
|
45
|
|
|
|
|
46
|
|
|
<info>%command.full_name%</> |
|
47
|
|
|
|
|
48
|
|
|
To remove templates <comment>fragments</comment> cache only, run: |
|
49
|
|
|
|
|
50
|
|
|
<info>%command.full_name% --fragments</> |
|
51
|
|
|
EOF |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
59
|
|
|
{ |
|
60
|
|
|
$cacheTemplatesPath = $this->getBuilder()->getConfig()->getCacheTemplatesPath(); |
|
61
|
|
|
if (!Util\File::getFS()->exists($cacheTemplatesPath)) { |
|
62
|
|
|
$output->writeln('<info>No templates cache.</info>'); |
|
63
|
|
|
|
|
64
|
|
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
if ($input->getOption('fragments')) { |
|
67
|
|
|
$output->writeln('Removing templates fragments cache directory...'); |
|
68
|
|
|
$cacheFragmentsPath = Util::joinFile($cacheTemplatesPath, '_fragments'); |
|
69
|
|
|
$output->writeln(\sprintf('<comment>Path: %s</comment>', $cacheFragmentsPath), OutputInterface::VERBOSITY_VERBOSE); |
|
70
|
|
|
Util\File::getFS()->remove($cacheFragmentsPath); |
|
71
|
|
|
$output->writeln('<info>Templates fragments cache is clear.</info>'); |
|
72
|
|
|
|
|
73
|
|
|
return 0; |
|
74
|
|
|
} |
|
75
|
|
|
$output->writeln('Removing templates cache directory...'); |
|
76
|
|
|
$output->writeln(\sprintf('<comment>Path: %s</comment>', $cacheTemplatesPath), OutputInterface::VERBOSITY_VERBOSE); |
|
77
|
|
|
Util\File::getFS()->remove($cacheTemplatesPath); |
|
78
|
|
|
$output->writeln('<info>Templates cache is clear.</info>'); |
|
79
|
|
|
|
|
80
|
|
|
return 0; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|