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