| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
5 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
6 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
7 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
8 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
10 |
* THE SOFTWARE.
|
|
|
11 |
*
|
|
|
12 |
* This software consists of voluntary contributions made by many individuals
|
|
|
13 |
* and is licensed under the MIT license.
|
|
|
14 |
*
|
|
|
15 |
* Copyright (c) 2014-2022 Yuuki Takezawa
|
|
|
16 |
*
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
declare(strict_types=1);
|
|
|
20 |
|
|
|
21 |
namespace Ytake\LaravelSmarty\Console;
|
|
|
22 |
|
|
|
23 |
use Ytake\LaravelSmarty\Smarty;
|
|
|
24 |
use Illuminate\Console\Command;
|
|
|
25 |
use Symfony\Component\Console\Input\InputOption;
|
|
|
26 |
|
|
|
27 |
use function is_null;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Class CacheClearCommand
|
|
|
31 |
*
|
|
|
32 |
* @author yuuki.takezawa<yuuki.takezawa@comnect.jp.net>
|
|
|
33 |
* @license http://opensource.org/licenses/MIT MIT
|
|
|
34 |
*/
|
|
|
35 |
class CacheClearCommand extends Command
|
|
|
36 |
{
|
|
|
37 |
/**
|
|
|
38 |
* @param Smarty $smarty
|
|
|
39 |
*/
|
|
|
40 |
public function __construct(
|
|
|
41 |
protected Smarty $smarty
|
|
|
42 |
) {
|
|
|
43 |
parent::__construct();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* The console command name.
|
|
|
48 |
*
|
|
|
49 |
* @var string
|
|
|
50 |
*/
|
|
|
51 |
protected $name = 'ytake:smarty-clear-cache';
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* The console command description.
|
|
|
55 |
*
|
|
|
56 |
* @var string
|
|
|
57 |
*/
|
|
|
58 |
protected $description = 'Flush the Smarty cache.';
|
|
|
59 |
|
|
|
60 |
/**
|
|
|
61 |
* Execute the console command.
|
|
|
62 |
*
|
|
|
63 |
*/
|
|
|
64 |
public function handle(): int
|
|
|
65 |
{
|
|
|
66 |
// clear all cache
|
|
|
67 |
if (is_null($this->option('file'))) {
|
|
|
68 |
$this->smarty->clearAllCache((int) $this->option('time'));
|
|
|
69 |
$this->info('Smarty cache cleared!');
|
|
|
70 |
|
|
|
71 |
return 0;
|
|
|
72 |
}
|
|
|
73 |
// file specified
|
|
|
74 |
if (!$this->smarty->clearCache($this->option('file'), $this->option('cache_id'), null, (int) $this->option('time'))) {
|
|
|
75 |
$this->error('Specified file not found');
|
|
|
76 |
|
|
|
77 |
return 1;
|
|
|
78 |
}
|
|
|
79 |
$this->info('Specified file was cache cleared!');
|
|
|
80 |
|
|
|
81 |
return 0;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Get the console command options.
|
|
|
86 |
*
|
|
|
87 |
* @return array
|
|
|
88 |
*/
|
|
|
89 |
protected function getOptions(): array
|
|
|
90 |
{
|
|
|
91 |
return [
|
|
|
92 |
['file', 'f', InputOption::VALUE_OPTIONAL, 'Specify file'],
|
|
|
93 |
['time', 't', InputOption::VALUE_OPTIONAL, 'Clear all of the files that are specified duration time'],
|
|
|
94 |
['cache_id', 'cache', InputOption::VALUE_OPTIONAL, 'Specified cache_id groups'],
|
|
|
95 |
];
|
|
|
96 |
}
|
|
|
97 |
}
|