|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acacha\AdminLTETemplateLaravel\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
7
|
|
|
use League\Flysystem\Adapter\Local as LocalAdapter; |
|
8
|
|
|
use League\Flysystem\Filesystem as Flysystem; |
|
9
|
|
|
use League\Flysystem\MountManager; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class PublishAdminLTE. |
|
13
|
|
|
*/ |
|
14
|
|
|
class PublishAdminLTE extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The filesystem instance. |
|
18
|
|
|
* |
|
19
|
|
|
* @var \Illuminate\Filesystem\Filesystem |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $files; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The name and signature of the console command. |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $signature = 'adminlte-laravel:publish {--f|force : Force overwrite of files}'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* The console command description. |
|
30
|
|
|
* |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $description = 'Publish Acacha AdminLTE Template files into laravel project'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Force overwrite of files. |
|
37
|
|
|
* |
|
38
|
|
|
* @var boolean |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $force = false; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Create a new command instance. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Illuminate\Filesystem\Filesystem $files |
|
46
|
|
|
* |
|
47
|
|
|
* @return void |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct(Filesystem $files) |
|
50
|
|
|
{ |
|
51
|
|
|
|
|
52
|
|
|
parent::__construct(); |
|
53
|
|
|
$this->files = $files; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Execute the console command. |
|
58
|
|
|
*/ |
|
59
|
|
View Code Duplication |
public function handle() |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$this->processOptions(); |
|
62
|
|
|
$this->publishHomeController(); |
|
63
|
|
|
$this->changeRegisterController(); |
|
64
|
|
|
$this->publishPublicAssets(); |
|
65
|
|
|
$this->publishViews(); |
|
66
|
|
|
$this->publishResourceAssets(); |
|
67
|
|
|
$this->publishTests(); |
|
68
|
|
|
$this->publishLanguages(); |
|
69
|
|
|
$this->publishGravatar(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Install Home Controller. |
|
74
|
|
|
*/ |
|
75
|
|
|
private function publishHomeController() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::homeController()); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Install Auth controller. |
|
82
|
|
|
*/ |
|
83
|
|
|
private function changeRegisterController() |
|
84
|
|
|
{ |
|
85
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::registerController()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Install public assets. |
|
90
|
|
|
*/ |
|
91
|
|
|
private function publishPublicAssets() |
|
92
|
|
|
{ |
|
93
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::publicAssets()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Install views. |
|
98
|
|
|
*/ |
|
99
|
|
|
private function publishViews() |
|
100
|
|
|
{ |
|
101
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::views()); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Install resource assets. |
|
106
|
|
|
*/ |
|
107
|
|
|
private function publishResourceAssets() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::resourceAssets()); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Install resource assets. |
|
114
|
|
|
*/ |
|
115
|
|
|
private function publishTests() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::tests()); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Install language assets. |
|
122
|
|
|
*/ |
|
123
|
|
|
private function publishLanguages() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::languages()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Install gravatar config file. |
|
130
|
|
|
*/ |
|
131
|
|
|
private function publishGravatar() |
|
132
|
|
|
{ |
|
133
|
|
|
$this->install(\Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::gravatar()); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Install files from array. |
|
138
|
|
|
* |
|
139
|
|
|
* @param $files |
|
140
|
|
|
*/ |
|
141
|
|
|
private function install($files) |
|
142
|
|
|
{ |
|
143
|
|
|
foreach ($files as $fileSrc => $fileDst) { |
|
144
|
|
|
if (file_exists($fileDst) && !$this->force && !$this->confirmOverwrite(basename($fileDst))) { |
|
145
|
|
|
return; |
|
146
|
|
|
} |
|
147
|
|
|
if ($this->files->isFile($fileSrc)) { |
|
148
|
|
|
$this->publishFile($fileSrc, $fileDst); |
|
149
|
|
|
} elseif ($this->files->isDirectory($fileSrc)) { |
|
150
|
|
|
$this->publishDirectory($fileSrc, $fileSrc); |
|
151
|
|
|
} else { |
|
152
|
|
|
$this->error("Can't locate path: <{$fileSrc}>"); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param $fileName |
|
159
|
|
|
* @param string $prompt |
|
160
|
|
|
* |
|
161
|
|
|
* @return bool |
|
162
|
|
|
*/ |
|
163
|
|
|
protected function confirmOverwrite($fileName, $prompt = '') |
|
164
|
|
|
{ |
|
165
|
|
|
$prompt = (empty($prompt)) |
|
166
|
|
|
? $fileName.' already exists. Do you want to overwrite it? [y|N]' |
|
167
|
|
|
: $prompt; |
|
168
|
|
|
|
|
169
|
|
|
return $this->confirm($prompt, false); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Create the directory to house the published files if needed. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $directory |
|
176
|
|
|
* |
|
177
|
|
|
* @return void |
|
178
|
|
|
*/ |
|
179
|
|
|
protected function createParentDirectory($directory) |
|
180
|
|
|
{ |
|
181
|
|
|
if (!$this->files->isDirectory($directory)) { |
|
182
|
|
|
$this->files->makeDirectory($directory, 0755, true); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Publish the file to the given path. |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $from |
|
190
|
|
|
* @param string $to |
|
191
|
|
|
* |
|
192
|
|
|
* @return void |
|
193
|
|
|
*/ |
|
194
|
|
|
protected function publishFile($from, $to) |
|
195
|
|
|
{ |
|
196
|
|
|
$this->createParentDirectory(dirname($to)); |
|
197
|
|
|
$this->files->copy($from, $to); |
|
198
|
|
|
$this->status($from, $to, 'File'); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Publish the directory to the given directory. |
|
203
|
|
|
* |
|
204
|
|
|
* @param string $from |
|
205
|
|
|
* @param string $to |
|
206
|
|
|
* |
|
207
|
|
|
* @return void |
|
208
|
|
|
*/ |
|
209
|
|
|
protected function publishDirectory($from, $to) |
|
210
|
|
|
{ |
|
211
|
|
|
$manager = new MountManager([ |
|
212
|
|
|
'from' => new Flysystem(new LocalAdapter($from)), |
|
213
|
|
|
'to' => new Flysystem(new LocalAdapter($to)), |
|
214
|
|
|
]); |
|
215
|
|
|
foreach ($manager->listContents('from://', true) as $file) { |
|
216
|
|
|
if ($file['type'] === 'file' && (!$manager->has('to://'.$file['path']))) { |
|
217
|
|
|
$manager->put('to://'.$file['path'], $manager->read('from://'.$file['path'])); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
$this->status($from, $to, 'Directory'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Write a status message to the console. |
|
225
|
|
|
* |
|
226
|
|
|
* @param string $from |
|
227
|
|
|
* @param string $to |
|
228
|
|
|
* @param string $type |
|
229
|
|
|
* |
|
230
|
|
|
* @return void |
|
231
|
|
|
*/ |
|
232
|
|
|
protected function status($from, $to, $type) |
|
233
|
|
|
{ |
|
234
|
|
|
$from = str_replace(base_path(), '', realpath($from)); |
|
235
|
|
|
$to = str_replace(base_path(), '', realpath($to)); |
|
236
|
|
|
$this->line('<info>Copied '.$type.'</info> <comment>['.$from.']</comment> <info>To</info> <comment>['.$to.']</comment>'); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Process options before running command |
|
241
|
|
|
*/ |
|
242
|
|
|
private function processOptions() |
|
243
|
|
|
{ |
|
244
|
|
|
$this->force = $this->option('force'); |
|
|
|
|
|
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.