1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
11
|
|
|
* THE SOFTWARE. |
12
|
|
|
* |
13
|
|
|
* This software consists of voluntary contributions made by many individuals |
14
|
|
|
* and is licensed under the MIT license. |
15
|
|
|
* |
16
|
|
|
* Copyright (c) 2014-2019 Yuuki Takezawa |
17
|
|
|
* |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Ytake\LaravelSmarty\Console; |
21
|
|
|
|
22
|
|
|
use Ytake\LaravelSmarty\Smarty; |
23
|
|
|
use Illuminate\Console\Command; |
24
|
|
|
use Symfony\Component\Console\Input\InputOption; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class CacheClearCommand |
28
|
|
|
* |
29
|
|
|
* @author yuuki.takezawa<[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
31
|
|
|
*/ |
32
|
|
|
class CacheClearCommand extends Command |
33
|
|
|
{ |
34
|
|
|
/** @var Smarty */ |
35
|
|
|
protected $smarty; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Smarty $smarty |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Smarty $smarty) |
41
|
|
|
{ |
42
|
|
|
parent::__construct(); |
43
|
|
|
$this->smarty = $smarty; |
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() |
65
|
|
|
{ |
66
|
|
|
// clear all cache |
67
|
|
|
if (is_null($this->option('file'))) { |
68
|
|
|
$this->smarty->clearAllCache($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, $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() |
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
|
|
|
} |
98
|
|
|
|