|
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 Illuminate\Console\Command; |
|
23
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
24
|
|
|
use Ytake\LaravelSmarty\SmartyFactory; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class ClearCompiledCommand |
|
28
|
|
|
* |
|
29
|
|
|
* @author yuuki.takezawa<[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
31
|
|
|
*/ |
|
32
|
|
|
class ClearCompiledCommand extends Command |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var SmartyFactory */ |
|
35
|
|
|
protected $smartyFactory; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param SmartyFactory $smartyFactory |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct(SmartyFactory $smartyFactory) |
|
41
|
|
|
{ |
|
42
|
|
|
parent::__construct(); |
|
43
|
|
|
$this->smartyFactory = $smartyFactory; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* The console command name. |
|
48
|
|
|
* |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $name = 'ytake:smarty-clear-compiled'; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* The console command description. |
|
55
|
|
|
* |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $description = 'Remove the compiled Smarty files.'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Execute the console command. |
|
62
|
|
|
* |
|
63
|
|
|
* @return int |
|
64
|
|
|
*/ |
|
65
|
|
|
public function handle() |
|
66
|
|
|
{ |
|
67
|
|
|
$removedFiles = $this->smartyFactory |
|
68
|
|
|
->getSmarty() |
|
69
|
|
|
->clearCompiledTemplate($this->option('file'), $this->option('compile_id')); |
|
70
|
|
|
|
|
71
|
|
|
if ($removedFiles > 0) { |
|
72
|
|
|
$this->info("Removed $removedFiles compiled Smarty file" . ($removedFiles > 1 ? 's' : '') . '.'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return 0; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Get the console command options. |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getOptions() |
|
84
|
|
|
{ |
|
85
|
|
|
return [ |
|
86
|
|
|
['file', 'f', InputOption::VALUE_OPTIONAL, 'Specify file'], |
|
87
|
|
|
['compile_id', 'compile', InputOption::VALUE_OPTIONAL, 'Specified compile_id'], |
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|