1 | <?php |
||
32 | class OptimizeCommand extends Command |
||
33 | { |
||
34 | /** @var Smarty */ |
||
35 | protected $smarty; |
||
36 | |||
37 | /** @var ConfigContract */ |
||
38 | protected $config; |
||
39 | |||
40 | /** |
||
41 | * @param Smarty $smarty |
||
42 | * @param ConfigContract $config |
||
43 | */ |
||
44 | public function __construct(Smarty $smarty, ConfigContract $config) |
||
45 | { |
||
46 | parent::__construct(); |
||
47 | $this->smarty = $smarty; |
||
48 | $this->config = $config; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * The console command name. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $name = 'ytake:smarty-optimize'; |
||
57 | |||
58 | /** |
||
59 | * The console command description. |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $description = 'Compile all known templates.'; |
||
64 | |||
65 | /** |
||
66 | * Execute the console command. |
||
67 | * |
||
68 | */ |
||
69 | public function handle() |
||
70 | { |
||
71 | $configureFileExtension = $this->config->get('ytake-laravel-smarty.extension', 'tpl'); |
||
72 | $fileExtension = (is_null($this->option('extension'))) |
||
73 | ? $configureFileExtension : $this->option('extension'); |
||
74 | ob_start(); |
||
75 | $compileFiles = $this->smarty->compileAllTemplates( |
||
76 | $fileExtension, $this->forceCompile() |
||
77 | ); |
||
78 | $contents = ob_get_contents(); |
||
79 | ob_get_clean(); |
||
80 | $this->comment(str_replace("<br>", "", trim($contents))); |
||
81 | $this->info("{$compileFiles} template files recompiled"); |
||
82 | return 0; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Get the console command options. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | protected function getOptions() |
||
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | protected function forceCompile() |
||
108 | } |
||
109 |