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-2017 Yuuki Takezawa |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Ytake\LaravelSmarty\Console; |
20
|
|
|
|
21
|
|
|
use Ytake\LaravelSmarty\Smarty; |
22
|
|
|
use Illuminate\Console\Command; |
23
|
|
|
use Symfony\Component\Console\Input\InputOption; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class CacheClearCommand |
27
|
|
|
* |
28
|
|
|
* @author yuuki.takezawa<[email protected]> |
29
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
30
|
|
|
*/ |
31
|
|
|
class CacheClearCommand extends Command |
32
|
|
|
{ |
33
|
|
|
/** @var Smarty */ |
34
|
|
|
protected $smarty; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Smarty $smarty |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Smarty $smarty) |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
$this->smarty = $smarty; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The console command name. |
47
|
|
|
* |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
protected $name = 'ytake:smarty-clear-cache'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The console command description. |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $description = 'Flush the Smarty cache.'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Execute the console command. |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function handle() |
64
|
|
|
{ |
65
|
|
|
// clear all cache |
66
|
|
|
if (is_null($this->option('file'))) { |
67
|
|
|
$this->smarty->clearAllCache($this->option('time')); |
68
|
|
|
$this->info('Smarty cache cleared!'); |
69
|
|
|
|
70
|
|
|
return 0; |
71
|
|
|
} |
72
|
|
|
// file specified |
73
|
|
|
if (!$this->smarty->clearCache($this->option('file'), $this->option('cache_id'), null, $this->option('time'))) { |
|
|
|
|
74
|
|
|
$this->error('Specified file not found'); |
75
|
|
|
|
76
|
|
|
return 1; |
77
|
|
|
} |
78
|
|
|
$this->info('Specified file was cache cleared!'); |
79
|
|
|
|
80
|
|
|
return 0; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the console command options. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function getOptions() |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
['file', 'f', InputOption::VALUE_OPTIONAL, 'Specify file'], |
92
|
|
|
['time', 't', InputOption::VALUE_OPTIONAL, 'Clear all of the files that are specified duration time'], |
93
|
|
|
['cache_id', 'cache', InputOption::VALUE_OPTIONAL, 'Specified cache_id groups'], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: