1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace iMokhles\MultiAuthCommand\Command; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Database\Console\Migrations\BaseCommand; |
7
|
|
|
use Illuminate\Database\Migrations\MigrationCreator; |
8
|
|
|
use Illuminate\Support\Composer; |
9
|
|
|
use Illuminate\Support\Facades\Artisan; |
10
|
|
|
use Illuminate\Support\Str; |
11
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
12
|
|
|
use Symfony\Component\Process\Process; |
13
|
|
|
|
14
|
|
|
class MultiAuthPrepare extends BaseCommand |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $signature = 'make:multi_auth {name} {--admin_theme= : chose the theme you want}'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'create multi authentication guards with dashboard panel'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var |
32
|
|
|
*/ |
33
|
|
|
protected $progressBar; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The migration creator instance. |
37
|
|
|
* |
38
|
|
|
* @var \Illuminate\Database\Migrations\MigrationCreator |
39
|
|
|
*/ |
40
|
|
|
protected $creator; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The Composer instance. |
44
|
|
|
* |
45
|
|
|
* @var \Illuminate\Support\Composer |
46
|
|
|
*/ |
47
|
|
|
protected $composer; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create a new migration install command instance. |
51
|
|
|
* |
52
|
|
|
* @param \Illuminate\Database\Migrations\MigrationCreator $creator |
53
|
|
|
* @param \Illuminate\Support\Composer $composer |
54
|
|
|
*/ |
55
|
|
|
public function __construct(MigrationCreator $creator, Composer $composer) |
56
|
|
|
{ |
57
|
|
|
parent::__construct(); |
58
|
|
|
$this->creator = $creator; |
59
|
|
|
$this->composer = $composer; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Execute the console command. |
64
|
|
|
* |
65
|
|
|
* @return boolean |
66
|
|
|
*/ |
67
|
|
|
public function handle() |
68
|
|
|
{ |
69
|
|
|
$this->progressBar = $this->output->createProgressBar(15); |
70
|
|
|
$this->progressBar->start(); |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->line(" Preparing For MultiAuth. Please wait..."); |
74
|
|
|
$this->progressBar->advance(); |
75
|
|
|
|
76
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
77
|
|
|
|
78
|
|
|
$admin_theme = $this->option('admin_theme'); |
79
|
|
|
if (is_null($admin_theme)) { |
80
|
|
|
$admin_theme = 'adminlte2'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
if ($this->checkIfThemeFileExistsOrNot($admin_theme)) { |
86
|
|
|
$this->line(" installing migrations..."); |
87
|
|
|
$this->installMigration(); |
88
|
|
|
$this->progressBar->advance(); |
89
|
|
|
|
90
|
|
|
$this->line(" installing notifications database table..."); |
91
|
|
|
$this->installNotificationsDatabase(); |
92
|
|
|
$this->progressBar->advance(); |
93
|
|
|
|
94
|
|
|
$this->line(" installing models..."); |
95
|
|
|
$this->installModel(); |
96
|
|
|
$this->progressBar->advance(); |
97
|
|
|
|
98
|
|
|
$this->line(" installing route maps..."); |
99
|
|
|
$this->installRouteMaps(); |
100
|
|
|
$this->progressBar->advance(); |
101
|
|
|
|
102
|
|
|
$this->line(" installing route files..."); |
103
|
|
|
$this->installRouteFiles(); |
104
|
|
|
$this->progressBar->advance(); |
105
|
|
|
|
106
|
|
|
$this->line(" installing controllers..."); |
107
|
|
|
$this->installControllers(); |
108
|
|
|
$this->progressBar->advance(); |
109
|
|
|
|
110
|
|
|
$this->line(" installing requests..."); |
111
|
|
|
$this->installRequests(); |
112
|
|
|
$this->progressBar->advance(); |
113
|
|
|
|
114
|
|
|
$this->line(" installing configs..."); |
115
|
|
|
$this->installConfigs(); |
116
|
|
|
$this->progressBar->advance(); |
117
|
|
|
|
118
|
|
|
$this->line(" installing middleware..."); |
119
|
|
|
$this->installMiddleware(); |
120
|
|
|
$this->progressBar->advance(); |
121
|
|
|
|
122
|
|
|
$this->line(" installing unauthenticated function..."); |
123
|
|
|
$this->installUnauthenticated(); |
124
|
|
|
$this->progressBar->advance(); |
125
|
|
|
|
126
|
|
|
$this->line(" installing views..."); |
127
|
|
|
$this->installView($admin_theme); |
128
|
|
|
$this->progressBar->advance(); |
129
|
|
|
|
130
|
|
|
$this->line(" installing languages files..."); |
131
|
|
|
$this->installLangs(); |
132
|
|
|
$this->progressBar->advance(); |
133
|
|
|
|
134
|
|
|
$this->line(" installing project config file..."); |
135
|
|
|
$this->installProjectConfig($admin_theme); |
136
|
|
|
$this->progressBar->advance(); |
137
|
|
|
|
138
|
|
|
if (array_key_exists($admin_theme, MultiAuthListThemes::listFreeThemes())) { |
139
|
|
|
$this->line(" installing admin panel files under public folder..."); |
140
|
|
|
$this->installPublicFilesIfNeeded($admin_theme); |
141
|
|
|
$this->progressBar->advance(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
$this->line(" installing prologue alert..."); |
146
|
|
|
$this->installPrologueAlert(); |
147
|
|
|
$this->progressBar->advance(); |
148
|
|
|
|
149
|
|
|
$this->line(" dump autoload..."); |
150
|
|
|
$this->composer->dumpAutoloads(); |
151
|
|
|
$this->progressBar->advance(); |
152
|
|
|
|
153
|
|
|
$this->progressBar->finish(); |
154
|
|
|
$this->info(" finished ".$name." setup with Backpack panel."); |
155
|
|
|
} else { |
156
|
|
|
$this->progressBar->advance(); |
157
|
|
|
$this->progressBar->finish(); |
158
|
|
|
$this->line(" failed: ".$admin_theme." theme not found"); |
159
|
|
|
} |
160
|
|
|
return true; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param $admin_theme |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
private function checkIfThemeFileExistsOrNot($admin_theme) { |
169
|
|
|
return (file_exists(__DIR__ . '/../Stubs/Views/'.$admin_theme.'/dashboard.blade.stub')); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return bool |
174
|
|
|
*/ |
175
|
|
|
public function isAlreadySetup() { |
176
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
177
|
|
|
|
178
|
|
|
$routeServicesContent = file_get_contents($this->getRouteServicesPath()); |
179
|
|
|
|
180
|
|
|
if (Str::contains($routeServicesContent,'$this->map'.$name.'Routes();')) { |
|
|
|
|
181
|
|
|
return true; |
182
|
|
|
} |
183
|
|
|
return false; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Install Migration. |
188
|
|
|
* |
189
|
|
|
* @return boolean |
190
|
|
|
*/ |
191
|
|
|
public function installMigration() |
192
|
|
|
{ |
193
|
|
|
$nameSmallPlural = Str::plural(Str::snake($this->getParsedNameInput())); |
194
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
195
|
|
|
$namePlural = Str::plural($name); |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
|
199
|
|
|
$modelTableContent = file_get_contents(__DIR__ . '/../Stubs/Migration/modelTable.stub'); |
200
|
|
|
$modelTableContentNew = str_replace([ |
201
|
|
|
'{{$namePlural}}', |
202
|
|
|
'{{$nameSmallPlural}}', |
203
|
|
|
], [ |
204
|
|
|
$namePlural, |
205
|
|
|
$nameSmallPlural |
206
|
|
|
], $modelTableContent); |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
$modelResetPasswordTableContent = file_get_contents(__DIR__ . '/../Stubs/Migration/passwordResetsTable.stub'); |
210
|
|
|
$modelResetPasswordTableContentNew = str_replace([ |
211
|
|
|
'{{$namePlural}}', |
212
|
|
|
'{{$nameSmallPlural}}', |
213
|
|
|
], [ |
214
|
|
|
$namePlural, |
215
|
|
|
$nameSmallPlural |
216
|
|
|
], $modelResetPasswordTableContent); |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
$migrationName = date('Y_m_d_His') . '_'.'create_' . Str::plural( Str::snake($name)) .'_table.php'; |
220
|
|
|
$migrationModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationName; |
221
|
|
|
file_put_contents($migrationModelPath, $modelTableContentNew); |
222
|
|
|
|
223
|
|
|
$migrationResetName = date('Y_m_d_His') . '_' |
224
|
|
|
.'create_' . Str::plural( Str::snake($name)) |
225
|
|
|
.'_password_resets_table.php'; |
226
|
|
|
$migrationResetModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationResetName; |
227
|
|
|
file_put_contents($migrationResetModelPath, $modelResetPasswordTableContentNew); |
228
|
|
|
|
229
|
|
|
return true; |
230
|
|
|
|
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Install Model. |
235
|
|
|
* |
236
|
|
|
* @return boolean |
237
|
|
|
*/ |
238
|
|
|
public function installModel() |
239
|
|
|
{ |
240
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
241
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
242
|
|
|
|
243
|
|
|
|
244
|
|
|
$arrayToChange = [ |
245
|
|
|
'{{$name}}', |
246
|
|
|
]; |
247
|
|
|
|
248
|
|
|
$newChanges = [ |
249
|
|
|
$name, |
250
|
|
|
]; |
251
|
|
|
$nameSmallPlural = Str::plural( Str::snake($this->getParsedNameInput())); |
252
|
|
|
array_push($arrayToChange, '{{$nameSmallPlural}}'); |
253
|
|
|
array_push($arrayToChange, '{{$nameSmall}}'); |
254
|
|
|
array_push($newChanges, $nameSmallPlural); |
255
|
|
|
array_push($newChanges, $nameSmall); |
256
|
|
|
|
257
|
|
|
$modelContent = file_get_contents(__DIR__ . '/../Stubs/Model/model.stub'); |
258
|
|
|
$modelContentNew = str_replace($arrayToChange, $newChanges, $modelContent); |
259
|
|
|
|
260
|
|
|
$createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Models"; |
261
|
|
|
if (!file_exists($createFolder)) { |
262
|
|
|
mkdir($createFolder); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
$modelPath = $createFolder.DIRECTORY_SEPARATOR.$name.".php"; |
266
|
|
|
file_put_contents($modelPath, $modelContentNew); |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
|
270
|
|
|
$resetNotificationContent = file_get_contents(__DIR__ . '/../Stubs/Notification/resetPasswordNotification.stub'); |
271
|
|
|
$resetNotificationContentNew = str_replace([ |
272
|
|
|
'{{$name}}', |
273
|
|
|
'{{$nameSmall}}', |
274
|
|
|
], [ |
275
|
|
|
$name, |
276
|
|
|
$nameSmall |
277
|
|
|
], $resetNotificationContent); |
278
|
|
|
|
279
|
|
|
$verifyEmailContent = file_get_contents(__DIR__ . '/../Stubs/Notification/verifyEmailNotification.stub'); |
280
|
|
|
$verifyEmailContentNew = str_replace([ |
281
|
|
|
'{{$name}}', |
282
|
|
|
'{{$nameSmall}}', |
283
|
|
|
], [ |
284
|
|
|
$name, |
285
|
|
|
$nameSmall |
286
|
|
|
], $verifyEmailContent); |
287
|
|
|
|
288
|
|
|
$createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Notifications"; |
289
|
|
|
if (!file_exists($createFolder)) { |
290
|
|
|
mkdir($createFolder); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$resetNotificationPath = $createFolder.DIRECTORY_SEPARATOR.$name."ResetPasswordNotification.php"; |
294
|
|
|
file_put_contents($resetNotificationPath, $resetNotificationContentNew); |
295
|
|
|
|
296
|
|
|
$verifyEmailPath = $createFolder.DIRECTORY_SEPARATOR.$name."VerifyEmailNotification.php"; |
297
|
|
|
file_put_contents($verifyEmailPath, $verifyEmailContentNew); |
298
|
|
|
|
299
|
|
|
return true; |
300
|
|
|
|
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Install RouteMaps. |
305
|
|
|
* |
306
|
|
|
* @return boolean |
307
|
|
|
*/ |
308
|
|
|
|
309
|
|
|
public function installRouteMaps() |
310
|
|
|
{ |
311
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
312
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
313
|
|
|
$mapCallFunction = file_get_contents(__DIR__ . '/../Stubs/Route/mapRoute.stub'); |
314
|
|
|
$mapCallFunctionNew = str_replace('{{$name}}', "$name", $mapCallFunction); |
315
|
|
|
$this->insert($this->getRouteServicesPath(), '$this->mapWebRoutes();', $mapCallFunctionNew, true); |
316
|
|
|
$mapFunction = file_get_contents(__DIR__ . '/../Stubs/Route/mapRouteFunction.stub'); |
317
|
|
|
$mapFunctionNew = str_replace([ |
318
|
|
|
'{{$name}}', |
319
|
|
|
'{{$nameSmall}}' |
320
|
|
|
], [ |
321
|
|
|
"$name", |
322
|
|
|
"$nameSmall" |
323
|
|
|
], $mapFunction); |
324
|
|
|
$this->insert($this->getRouteServicesPath(), ' // |
325
|
|
|
}', $mapFunctionNew, true); |
326
|
|
|
return true; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Install RouteFile. |
331
|
|
|
* |
332
|
|
|
* @return boolean |
333
|
|
|
*/ |
334
|
|
|
|
335
|
|
|
public function installRouteFiles() |
336
|
|
|
{ |
337
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
338
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
339
|
|
|
$createFolder = $this->getRoutesFolderPath().DIRECTORY_SEPARATOR.$nameSmall; |
340
|
|
|
if (!file_exists($createFolder)) { |
341
|
|
|
mkdir($createFolder); |
342
|
|
|
} |
343
|
|
|
$routeFileContent = file_get_contents(__DIR__ . '/../Stubs/Route/routeFile.stub'); |
344
|
|
|
$routeFileContentNew = str_replace([ |
345
|
|
|
'{{$name}}', |
346
|
|
|
'{{$nameSmall}}' |
347
|
|
|
], [ |
348
|
|
|
"$name", |
349
|
|
|
"$nameSmall" |
350
|
|
|
], $routeFileContent); |
351
|
|
|
$routeFile = $createFolder.DIRECTORY_SEPARATOR.$nameSmall.".php"; |
352
|
|
|
file_put_contents($routeFile, $routeFileContentNew); |
353
|
|
|
return true; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Install Controller. |
358
|
|
|
* |
359
|
|
|
* @return boolean |
360
|
|
|
*/ |
361
|
|
|
|
362
|
|
|
public function installControllers() |
363
|
|
|
{ |
364
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
365
|
|
|
$nameSmallPlural = Str::plural( Str::snake($this->getParsedNameInput())); |
366
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
367
|
|
|
|
368
|
|
|
$nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name; |
369
|
|
|
if (!file_exists($nameFolder)) { |
370
|
|
|
mkdir($nameFolder); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$authFolder = $nameFolder.DIRECTORY_SEPARATOR."Auth"; |
374
|
|
|
if (!file_exists($authFolder)) { |
375
|
|
|
mkdir($authFolder); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
$controllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Controller.stub'); |
379
|
|
|
$homeControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/DashboardController.stub'); |
380
|
|
|
$loginControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/LoginController.stub'); |
381
|
|
|
$forgotControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/ForgotPasswordController.stub'); |
382
|
|
|
$registerControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/RegisterController.stub'); |
383
|
|
|
$resetControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/ResetPasswordController.stub'); |
384
|
|
|
$myAccountControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/MyAccountController.stub'); |
385
|
|
|
$verificationControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/VerificationController.stub'); |
386
|
|
|
|
387
|
|
|
$controllerFileContentNew = str_replace('{{$name}}', "$name", $controllerContent); |
388
|
|
|
|
389
|
|
|
$homeFileContentNew = str_replace([ |
390
|
|
|
'{{$name}}', |
391
|
|
|
'{{$nameSmall}}' |
392
|
|
|
], [ |
393
|
|
|
"$name", |
394
|
|
|
"$nameSmall" |
395
|
|
|
], $homeControllerContent); |
396
|
|
|
|
397
|
|
|
$loginFileContentNew = str_replace([ |
398
|
|
|
'{{$name}}', |
399
|
|
|
'{{$nameSmall}}' |
400
|
|
|
], [ |
401
|
|
|
"$name", |
402
|
|
|
"$nameSmall" |
403
|
|
|
], $loginControllerContent); |
404
|
|
|
|
405
|
|
|
$forgotFileContentNew = str_replace([ |
406
|
|
|
'{{$name}}', |
407
|
|
|
'{{$nameSmall}}', |
408
|
|
|
'{{$nameSmallPlural}}' |
409
|
|
|
], [ |
410
|
|
|
"$name", |
411
|
|
|
"$nameSmall", |
412
|
|
|
"$nameSmallPlural" |
413
|
|
|
], $forgotControllerContent); |
414
|
|
|
|
415
|
|
|
$registerFileContentNew = str_replace([ |
416
|
|
|
'{{$name}}', |
417
|
|
|
'{{$nameSmall}}', |
418
|
|
|
'{{$nameSmallPlural}}' |
419
|
|
|
], [ |
420
|
|
|
"$name", |
421
|
|
|
"$nameSmall", |
422
|
|
|
"$nameSmallPlural" |
423
|
|
|
], $registerControllerContent); |
424
|
|
|
|
425
|
|
|
$resetFileContentNew = str_replace([ |
426
|
|
|
'{{$name}}', |
427
|
|
|
'{{$nameSmall}}', |
428
|
|
|
'{{$nameSmallPlural}}' |
429
|
|
|
], [ |
430
|
|
|
"$name", |
431
|
|
|
"$nameSmall", |
432
|
|
|
"$nameSmallPlural" |
433
|
|
|
], $resetControllerContent); |
434
|
|
|
|
435
|
|
|
$myAccountFileContentNew = str_replace([ |
436
|
|
|
'{{$name}}', |
437
|
|
|
'{{$nameSmall}}' |
438
|
|
|
], [ |
439
|
|
|
"$name", |
440
|
|
|
"$nameSmall" |
441
|
|
|
], $myAccountControllerContent); |
442
|
|
|
|
443
|
|
|
$verificationControllerContentNew = str_replace([ |
444
|
|
|
'{{$name}}', |
445
|
|
|
'{{$nameSmall}}' |
446
|
|
|
], [ |
447
|
|
|
"$name", |
448
|
|
|
"$nameSmall" |
449
|
|
|
], $verificationControllerContent); |
450
|
|
|
|
451
|
|
|
$controllerFile = $nameFolder.DIRECTORY_SEPARATOR."Controller.php"; |
452
|
|
|
$homeFile = $nameFolder.DIRECTORY_SEPARATOR."DashboardController.php"; |
453
|
|
|
$loginFile = $authFolder.DIRECTORY_SEPARATOR."LoginController.php"; |
454
|
|
|
$forgotFile = $authFolder.DIRECTORY_SEPARATOR."ForgotPasswordController.php"; |
455
|
|
|
$registerFile = $authFolder.DIRECTORY_SEPARATOR."RegisterController.php"; |
456
|
|
|
$resetFile = $authFolder.DIRECTORY_SEPARATOR."ResetPasswordController.php"; |
457
|
|
|
$verificationFile = $authFolder.DIRECTORY_SEPARATOR."VerificationController.php"; |
458
|
|
|
|
459
|
|
|
$myAccountFile = $authFolder.DIRECTORY_SEPARATOR."{$name}AccountController.php"; |
460
|
|
|
|
461
|
|
|
|
462
|
|
|
file_put_contents($controllerFile, $controllerFileContentNew); |
463
|
|
|
file_put_contents($homeFile, $homeFileContentNew); |
464
|
|
|
file_put_contents($loginFile, $loginFileContentNew); |
465
|
|
|
file_put_contents($forgotFile, $forgotFileContentNew); |
466
|
|
|
file_put_contents($registerFile, $registerFileContentNew); |
467
|
|
|
file_put_contents($resetFile, $resetFileContentNew); |
468
|
|
|
file_put_contents($myAccountFile, $myAccountFileContentNew); |
469
|
|
|
file_put_contents($verificationFile, $verificationControllerContentNew); |
470
|
|
|
|
471
|
|
|
return true; |
472
|
|
|
|
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Install Requests. |
477
|
|
|
* |
478
|
|
|
* @return boolean |
479
|
|
|
*/ |
480
|
|
|
|
481
|
|
|
public function installRequests() |
482
|
|
|
{ |
483
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
484
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
485
|
|
|
|
486
|
|
|
$nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name; |
487
|
|
|
if (!file_exists($nameFolder)) { |
488
|
|
|
mkdir($nameFolder); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
$requestsFolder = $nameFolder.DIRECTORY_SEPARATOR."Requests"; |
492
|
|
|
if (!file_exists($requestsFolder)) { |
493
|
|
|
mkdir($requestsFolder); |
494
|
|
|
} |
495
|
|
|
$accountInfoContent = file_get_contents(__DIR__ . '/../Stubs/Request/AccountInfoRequest.stub'); |
496
|
|
|
$changePasswordContent = file_get_contents(__DIR__ . '/../Stubs/Request/ChangePasswordRequest.stub'); |
497
|
|
|
|
498
|
|
|
$accountInfoContentNew = str_replace([ |
499
|
|
|
'{{$name}}', |
500
|
|
|
'{{$nameSmall}}' |
501
|
|
|
], [ |
502
|
|
|
"$name", |
503
|
|
|
"$nameSmall" |
504
|
|
|
], $accountInfoContent); |
505
|
|
|
|
506
|
|
|
$changePasswordContentNew = str_replace([ |
507
|
|
|
'{{$name}}', |
508
|
|
|
'{{$nameSmall}}' |
509
|
|
|
], [ |
510
|
|
|
"$name", |
511
|
|
|
"$nameSmall" |
512
|
|
|
], $changePasswordContent); |
513
|
|
|
|
514
|
|
|
$accountInfoFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}AccountInfoRequest.php"; |
515
|
|
|
$changePasswordFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}ChangePasswordRequest.php"; |
516
|
|
|
|
517
|
|
|
file_put_contents($accountInfoFile, $accountInfoContentNew); |
518
|
|
|
file_put_contents($changePasswordFile, $changePasswordContentNew); |
519
|
|
|
|
520
|
|
|
return true; |
521
|
|
|
|
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* Install Configs. |
526
|
|
|
* |
527
|
|
|
* @return boolean |
528
|
|
|
*/ |
529
|
|
|
|
530
|
|
|
public function installConfigs() |
531
|
|
|
{ |
532
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
533
|
|
|
$nameSmallPlural = Str::plural( Str::snake($this->getParsedNameInput())); |
534
|
|
|
$name = ucfirst($this->getParsedNameInput()); |
535
|
|
|
|
536
|
|
|
$authConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."auth.php"; |
537
|
|
|
|
538
|
|
|
$guardContent = file_get_contents(__DIR__ . '/../Stubs/Config/guard.stub'); |
539
|
|
|
$passwordContent = file_get_contents(__DIR__ . '/../Stubs/Config/password.stub'); |
540
|
|
|
$providerContent = file_get_contents(__DIR__ . '/../Stubs/Config/provider.stub'); |
541
|
|
|
|
542
|
|
|
$guardFileContentNew = str_replace([ |
543
|
|
|
'{{$nameSmall}}', |
544
|
|
|
'{{$nameSmallPlural}}' |
545
|
|
|
], [ |
546
|
|
|
"$nameSmall", |
547
|
|
|
"$nameSmallPlural" |
548
|
|
|
], $guardContent); |
549
|
|
|
|
550
|
|
|
$passwordFileContentNew = str_replace('{{$nameSmallPlural}}', "$nameSmallPlural", $passwordContent); |
551
|
|
|
|
552
|
|
|
$providerFileContentNew = str_replace([ |
553
|
|
|
'{{$name}}', |
554
|
|
|
'{{$nameSmallPlural}}' |
555
|
|
|
], [ |
556
|
|
|
"$name", |
557
|
|
|
"$nameSmallPlural" |
558
|
|
|
], $providerContent); |
559
|
|
|
|
560
|
|
|
$this->insert($authConfigFile, ' \'guards\' => [', $guardFileContentNew, true); |
561
|
|
|
|
562
|
|
|
$this->insert($authConfigFile, ' \'passwords\' => [', $passwordFileContentNew, true); |
563
|
|
|
|
564
|
|
|
$this->insert($authConfigFile, ' \'providers\' => [', $providerFileContentNew, true); |
565
|
|
|
|
566
|
|
|
return true; |
567
|
|
|
|
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Install Middleware. |
572
|
|
|
* |
573
|
|
|
* @return boolean |
574
|
|
|
*/ |
575
|
|
|
|
576
|
|
|
public function installMiddleware() |
577
|
|
|
{ |
578
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
579
|
|
|
|
580
|
|
|
$redirectIfMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."RedirectIfAuthenticated.php"; |
581
|
|
|
$authenticateMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."Authenticate.php"; |
582
|
|
|
$ensureEmailIsVerifiedMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."EnsureEmailIsVerified.php"; |
583
|
|
|
$middlewareKernelFile = $this->getHttpPath().DIRECTORY_SEPARATOR."Kernel.php"; |
584
|
|
|
|
585
|
|
|
$redirectIfMiddlewareFileContent = file_get_contents($redirectIfMiddlewareFile); |
586
|
|
|
$authenticateMiddlewareFileContent = file_get_contents($redirectIfMiddlewareFile); |
587
|
|
|
|
588
|
|
|
$ensureEmailIsVerifiedMiddlewareFileeContent = file_get_contents(__DIR__ . '/../Stubs/Middleware/ensureEmailIsVerified.stub'); |
589
|
|
|
$redirectIfMiddlewareContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectIf.stub'); |
590
|
|
|
$authenticateMiddlewareContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/authenticate.stub'); |
591
|
|
|
|
592
|
|
|
if (!file_exists($ensureEmailIsVerifiedMiddlewareFile)) { |
593
|
|
|
file_put_contents($ensureEmailIsVerifiedMiddlewareFile, $ensureEmailIsVerifiedMiddlewareFileeContent); |
594
|
|
|
} |
595
|
|
|
|
596
|
|
View Code Duplication |
if (! Str::contains($redirectIfMiddlewareFileContent, 'MultiAuthGuards')) { |
|
|
|
|
597
|
|
|
// replace old file |
598
|
|
|
$deleted = unlink($redirectIfMiddlewareFile); |
599
|
|
|
if ($deleted) { |
600
|
|
|
file_put_contents($redirectIfMiddlewareFile, $redirectIfMiddlewareContentNew); |
601
|
|
|
} |
602
|
|
|
} |
603
|
|
|
|
604
|
|
View Code Duplication |
if (! Str::contains($authenticateMiddlewareFileContent, 'MultiAuthGuards')) { |
|
|
|
|
605
|
|
|
// replace old file |
606
|
|
|
$deleted = unlink($authenticateMiddlewareFile); |
607
|
|
|
if ($deleted) { |
608
|
|
|
file_put_contents($authenticateMiddlewareFile, $authenticateMiddlewareContentNew); |
609
|
|
|
} |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
$redirectIfMiddlewareGroupContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectMiddleware.stub'); |
613
|
|
|
$redirectIfMiddlewareGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectMiddlewareGuard.stub'); |
614
|
|
|
$authenticateIfMiddlewareGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/authenticateIf.stub'); |
615
|
|
|
|
616
|
|
|
$redirectIfMiddlewareGroupContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall", |
617
|
|
|
$redirectIfMiddlewareGroupContentNew); |
618
|
|
|
$redirectIfMiddlewareGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall", |
619
|
|
|
$redirectIfMiddlewareGuardContentNew); |
620
|
|
|
$authenticateIfMiddlewareGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall", |
621
|
|
|
$authenticateIfMiddlewareGuardContentNew); |
622
|
|
|
|
623
|
|
|
$this->insert($middlewareKernelFile, ' protected $middlewareGroups = [', |
624
|
|
|
$redirectIfMiddlewareGroupContentNew2, true); |
625
|
|
|
|
626
|
|
|
$this->insert($redirectIfMiddlewareFile, ' switch ($guard) {', |
627
|
|
|
$redirectIfMiddlewareGuardContentNew2, true); |
628
|
|
|
|
629
|
|
|
$this->insert($authenticateMiddlewareFile, ' // MultiAuthGuards', |
630
|
|
|
$authenticateIfMiddlewareGuardContentNew2, true); |
631
|
|
|
|
632
|
|
|
return true; |
633
|
|
|
|
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* Install Unauthenticated Handler. |
638
|
|
|
* |
639
|
|
|
* @return boolean |
640
|
|
|
*/ |
641
|
|
|
public function installUnauthenticated() |
642
|
|
|
{ |
643
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
644
|
|
|
$exceptionHandlerFile = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Exceptions".DIRECTORY_SEPARATOR |
645
|
|
|
."Handler.php"; |
646
|
|
|
$exceptionHandlerFileContent = file_get_contents($exceptionHandlerFile); |
647
|
|
|
$exceptionHandlerFileContentNew = file_get_contents(__DIR__ . '/../Stubs/Exceptions/handlerUnauthorized.stub'); |
648
|
|
|
|
649
|
|
|
|
650
|
|
View Code Duplication |
if (! Str::contains($exceptionHandlerFileContent, 'MultiAuthUnAuthenticated')) { |
|
|
|
|
651
|
|
|
// replace old file |
652
|
|
|
$deleted = unlink($exceptionHandlerFile); |
653
|
|
|
if ($deleted) { |
654
|
|
|
file_put_contents($exceptionHandlerFile, $exceptionHandlerFileContentNew); |
655
|
|
|
} |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
$exceptionHandlerGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Exceptions/handlerGuard.stub'); |
659
|
|
|
$exceptionHandlerGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall", |
660
|
|
|
$exceptionHandlerGuardContentNew); |
661
|
|
|
|
662
|
|
|
$this->insert($exceptionHandlerFile, ' switch(array_get($exception->guards(), 0)) {', |
663
|
|
|
$exceptionHandlerGuardContentNew2, true); |
664
|
|
|
|
665
|
|
|
return true; |
666
|
|
|
|
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* Install View. |
671
|
|
|
* |
672
|
|
|
* @param string $theme_name |
673
|
|
|
*/ |
674
|
|
|
public function installView($theme_name = 'adminlte2') |
675
|
|
|
{ |
676
|
|
|
|
677
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
678
|
|
|
|
679
|
|
|
// layouts |
680
|
|
|
$layoutBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/layouts/layout.blade.stub'); |
681
|
|
|
$layoutGuestBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/layouts/layout_guest.blade.stub'); |
682
|
|
|
|
683
|
|
|
// dashboard |
684
|
|
|
$dashboardBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/dashboard.blade.stub'); |
685
|
|
|
|
686
|
|
|
// auth |
687
|
|
|
$loginBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/login.blade.stub'); |
688
|
|
|
$registerBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/register.blade.stub'); |
689
|
|
|
$verifyEmailBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/verify.blade.stub'); |
690
|
|
|
|
691
|
|
|
// auth/passwords |
692
|
|
|
$resetBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/passwords/reset.blade.stub'); |
693
|
|
|
$emailBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/passwords/email.blade.stub'); |
694
|
|
|
|
695
|
|
|
// auth/account |
696
|
|
|
$update_infoBlade = file_get_contents(__DIR__ |
697
|
|
|
. '/../Stubs/Views/'.$theme_name.'/auth/account/update_info.blade.stub'); |
698
|
|
|
$right_boxBlade = file_get_contents(__DIR__ |
699
|
|
|
. '/../Stubs/Views/'.$theme_name.'/auth/account/right_box.blade.stub'); |
700
|
|
|
$left_boxBlade = file_get_contents(__DIR__ |
701
|
|
|
. '/../Stubs/Views/'.$theme_name.'/auth/account/left_box.blade.stub'); |
702
|
|
|
$change_passwordBlade = file_get_contents(__DIR__ |
703
|
|
|
. '/../Stubs/Views/'.$theme_name.'/auth/account/change_password_tab.blade.stub'); |
704
|
|
|
$account_infoBlade = file_get_contents(__DIR__ |
705
|
|
|
. '/../Stubs/Views/'.$theme_name.'/auth/account/account_info_tab.blade.stub'); |
706
|
|
|
|
707
|
|
|
// inc |
708
|
|
|
$alertsBlade = file_get_contents(__DIR__ |
709
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/inc/alerts.blade.stub'); |
710
|
|
|
$breadcrumbBlade = file_get_contents(__DIR__ |
711
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/inc/breadcrumb.blade.stub'); |
712
|
|
|
$headBlade = file_get_contents(__DIR__ |
713
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/inc/head.blade.stub'); |
714
|
|
|
$scriptsBlade = file_get_contents(__DIR__ |
715
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/inc/scripts.blade.stub'); |
716
|
|
|
|
717
|
|
|
|
718
|
|
|
// main_header |
719
|
|
|
$main_headerBlade = file_get_contents(__DIR__ |
720
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/main_header/main_header.blade.stub'); |
721
|
|
|
$languagesBlade = file_get_contents(__DIR__ |
722
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/main_header/languages.blade.stub'); |
723
|
|
|
$notificationsBlade = file_get_contents(__DIR__ |
724
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/main_header/notifications.blade.stub'); |
725
|
|
|
$userBlade = file_get_contents(__DIR__ |
726
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/main_header/user.blade.stub'); |
727
|
|
|
|
728
|
|
|
// sidemenu |
729
|
|
|
$itemsBlade = file_get_contents(__DIR__ |
730
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/sidemenu/items.blade.stub'); |
731
|
|
|
$listBlade = file_get_contents(__DIR__ |
732
|
|
|
. '/../Stubs/Views/'.$theme_name.'/layouts/sidemenu/list.blade.stub'); |
733
|
|
|
|
734
|
|
|
|
735
|
|
|
$createdFolders = $this->createViewsFolders($nameSmall); |
736
|
|
|
|
737
|
|
|
|
738
|
|
|
file_put_contents($createdFolders[4].'/layout.blade.php', str_replace([ |
739
|
|
|
'{{$nameSmall}}', |
740
|
|
|
], [ |
741
|
|
|
$nameSmall |
742
|
|
|
], $layoutBlade)); |
743
|
|
|
|
744
|
|
|
file_put_contents($createdFolders[4].'/layout_guest.blade.php', str_replace([ |
745
|
|
|
'{{$nameSmall}}', |
746
|
|
|
], [ |
747
|
|
|
$nameSmall |
748
|
|
|
], $layoutGuestBlade)); |
749
|
|
|
|
750
|
|
|
file_put_contents($createdFolders[0].'/dashboard.blade.php', str_replace([ |
751
|
|
|
'{{$nameSmall}}', |
752
|
|
|
], [ |
753
|
|
|
$nameSmall |
754
|
|
|
], $dashboardBlade)); |
755
|
|
|
|
756
|
|
|
file_put_contents($createdFolders[1].'/login.blade.php', str_replace([ |
757
|
|
|
'{{$nameSmall}}', |
758
|
|
|
], [ |
759
|
|
|
$nameSmall |
760
|
|
|
], $loginBlade)); |
761
|
|
|
|
762
|
|
|
file_put_contents($createdFolders[1].'/register.blade.php', str_replace([ |
763
|
|
|
'{{$nameSmall}}', |
764
|
|
|
], [ |
765
|
|
|
$nameSmall |
766
|
|
|
], $registerBlade)); |
767
|
|
|
|
768
|
|
|
file_put_contents($createdFolders[1].'/verify.blade.php', str_replace([ |
769
|
|
|
'{{$nameSmall}}', |
770
|
|
|
], [ |
771
|
|
|
$nameSmall |
772
|
|
|
], $verifyEmailBlade)); |
773
|
|
|
|
774
|
|
|
file_put_contents($createdFolders[2].'/reset.blade.php', str_replace([ |
775
|
|
|
'{{$nameSmall}}', |
776
|
|
|
], [ |
777
|
|
|
$nameSmall |
778
|
|
|
], $resetBlade)); |
779
|
|
|
|
780
|
|
|
file_put_contents($createdFolders[2].'/email.blade.php', str_replace([ |
781
|
|
|
'{{$nameSmall}}', |
782
|
|
|
], [ |
783
|
|
|
$nameSmall |
784
|
|
|
], $emailBlade)); |
785
|
|
|
|
786
|
|
|
file_put_contents($createdFolders[3].'/update_info.blade.php', str_replace([ |
787
|
|
|
'{{$nameSmall}}', |
788
|
|
|
], [ |
789
|
|
|
$nameSmall |
790
|
|
|
], $update_infoBlade)); |
791
|
|
|
|
792
|
|
|
file_put_contents($createdFolders[3].'/right_box.blade.php', str_replace([ |
793
|
|
|
'{{$nameSmall}}', |
794
|
|
|
], [ |
795
|
|
|
$nameSmall |
796
|
|
|
], $right_boxBlade)); |
797
|
|
|
|
798
|
|
|
file_put_contents($createdFolders[3].'/left_box.blade.php', str_replace([ |
799
|
|
|
'{{$nameSmall}}', |
800
|
|
|
], [ |
801
|
|
|
$nameSmall |
802
|
|
|
], $left_boxBlade)); |
803
|
|
|
|
804
|
|
|
file_put_contents($createdFolders[3].'/change_password_tab.blade.php', str_replace([ |
805
|
|
|
'{{$nameSmall}}', |
806
|
|
|
], [ |
807
|
|
|
$nameSmall |
808
|
|
|
], $change_passwordBlade)); |
809
|
|
|
|
810
|
|
|
file_put_contents($createdFolders[3].'/account_info_tab.blade.php', str_replace([ |
811
|
|
|
'{{$nameSmall}}', |
812
|
|
|
], [ |
813
|
|
|
$nameSmall |
814
|
|
|
], $account_infoBlade)); |
815
|
|
|
|
816
|
|
|
file_put_contents($createdFolders[5].'/alerts.blade.php', str_replace([ |
817
|
|
|
'{{$nameSmall}}', |
818
|
|
|
], [ |
819
|
|
|
$nameSmall |
820
|
|
|
], $alertsBlade)); |
821
|
|
|
|
822
|
|
|
file_put_contents($createdFolders[5].'/breadcrumb.blade.php', str_replace([ |
823
|
|
|
'{{$nameSmall}}', |
824
|
|
|
], [ |
825
|
|
|
$nameSmall |
826
|
|
|
], $breadcrumbBlade)); |
827
|
|
|
|
828
|
|
|
file_put_contents($createdFolders[5].'/head.blade.php', str_replace([ |
829
|
|
|
'{{$nameSmall}}', |
830
|
|
|
], [ |
831
|
|
|
$nameSmall |
832
|
|
|
], $headBlade)); |
833
|
|
|
|
834
|
|
|
file_put_contents($createdFolders[5].'/scripts.blade.php', str_replace([ |
835
|
|
|
'{{$nameSmall}}', |
836
|
|
|
], [ |
837
|
|
|
$nameSmall |
838
|
|
|
], $scriptsBlade)); |
839
|
|
|
|
840
|
|
|
file_put_contents($createdFolders[6].'/languages.blade.php', str_replace([ |
841
|
|
|
'{{$nameSmall}}', |
842
|
|
|
], [ |
843
|
|
|
$nameSmall |
844
|
|
|
], $languagesBlade)); |
845
|
|
|
|
846
|
|
|
file_put_contents($createdFolders[6].'/main_header.blade.php', str_replace([ |
847
|
|
|
'{{$nameSmall}}', |
848
|
|
|
], [ |
849
|
|
|
$nameSmall |
850
|
|
|
], $main_headerBlade)); |
851
|
|
|
|
852
|
|
|
file_put_contents($createdFolders[6].'/notifications.blade.php', str_replace([ |
853
|
|
|
'{{$nameSmall}}', |
854
|
|
|
], [ |
855
|
|
|
$nameSmall |
856
|
|
|
], $notificationsBlade)); |
857
|
|
|
|
858
|
|
|
file_put_contents($createdFolders[6].'/user.blade.php', str_replace([ |
859
|
|
|
'{{$nameSmall}}', |
860
|
|
|
], [ |
861
|
|
|
$nameSmall |
862
|
|
|
], $userBlade)); |
863
|
|
|
|
864
|
|
|
file_put_contents($createdFolders[7].'/items.blade.php', str_replace([ |
865
|
|
|
'{{$nameSmall}}', |
866
|
|
|
], [ |
867
|
|
|
$nameSmall |
868
|
|
|
], $itemsBlade)); |
869
|
|
|
|
870
|
|
|
file_put_contents($createdFolders[7].'/list.blade.php', str_replace([ |
871
|
|
|
'{{$nameSmall}}', |
872
|
|
|
], [ |
873
|
|
|
$nameSmall |
874
|
|
|
], $listBlade)); |
875
|
|
|
|
876
|
|
|
} |
877
|
|
|
|
878
|
|
|
/** |
879
|
|
|
* @param string $nameSmall |
880
|
|
|
* @return string[] |
881
|
|
|
*/ |
882
|
|
|
protected function createViewsFolders($nameSmall) { |
883
|
|
|
|
884
|
|
|
// main guard folder |
885
|
|
|
$createFolder = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall"; |
886
|
|
|
if (!file_exists($createFolder)) { |
887
|
|
|
mkdir($createFolder); |
888
|
|
|
} |
889
|
|
|
|
890
|
|
|
// Auth folder |
891
|
|
|
$createFolderAuth = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall" |
892
|
|
|
.DIRECTORY_SEPARATOR."auth"; |
893
|
|
|
if (!file_exists($createFolderAuth)) { |
894
|
|
|
mkdir($createFolderAuth); |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
$createFolderAuthPasswords = $createFolderAuth.DIRECTORY_SEPARATOR."passwords"; |
898
|
|
|
if (!file_exists($createFolderAuthPasswords)) { |
899
|
|
|
mkdir($createFolderAuthPasswords); |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
$createFolderAuthAccount = $createFolderAuth.DIRECTORY_SEPARATOR."account"; |
903
|
|
|
if (!file_exists($createFolderAuthAccount)) { |
904
|
|
|
mkdir($createFolderAuthAccount); |
905
|
|
|
} |
906
|
|
|
|
907
|
|
|
// Layout folder |
908
|
|
|
$createFolderLayouts = $this->getViewsFolderPath().DIRECTORY_SEPARATOR |
909
|
|
|
."$nameSmall" |
910
|
|
|
.DIRECTORY_SEPARATOR."layouts"; |
911
|
|
|
if (!file_exists($createFolderLayouts)) { |
912
|
|
|
mkdir($createFolderLayouts); |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
$createFolderLayoutsInc = $createFolderLayouts .DIRECTORY_SEPARATOR."inc"; |
916
|
|
|
if (!file_exists($createFolderLayoutsInc)) { |
917
|
|
|
mkdir($createFolderLayoutsInc); |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
$createFolderLayoutsMainHeader = $createFolderLayouts .DIRECTORY_SEPARATOR."main_header"; |
921
|
|
|
if (!file_exists($createFolderLayoutsMainHeader)) { |
922
|
|
|
mkdir($createFolderLayoutsMainHeader); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
$createFolderLayoutsSideMenu = $createFolderLayouts .DIRECTORY_SEPARATOR."sidemenu"; |
926
|
|
|
if (!file_exists($createFolderLayoutsSideMenu)) { |
927
|
|
|
mkdir($createFolderLayoutsSideMenu); |
928
|
|
|
} |
929
|
|
|
|
930
|
|
|
return [ |
931
|
|
|
$createFolder, |
932
|
|
|
$createFolderAuth, |
933
|
|
|
$createFolderAuthPasswords, |
934
|
|
|
$createFolderAuthAccount, |
935
|
|
|
|
936
|
|
|
$createFolderLayouts, |
937
|
|
|
$createFolderLayoutsInc, |
938
|
|
|
$createFolderLayoutsMainHeader, |
939
|
|
|
$createFolderLayoutsSideMenu |
940
|
|
|
]; |
941
|
|
|
|
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* Install Lang. |
946
|
|
|
* |
947
|
|
|
* @return boolean |
948
|
|
|
*/ |
949
|
|
|
|
950
|
|
|
public function installLangs() |
951
|
|
|
{ |
952
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
953
|
|
|
|
954
|
|
|
$dashboardLangFile = file_get_contents(__DIR__ . '/../Stubs/Languages/dashboard.stub'); |
955
|
|
|
file_put_contents($this->getLangsFolderPath().'/'.$nameSmall.'_dashboard.php', $dashboardLangFile); |
956
|
|
|
|
957
|
|
|
return true; |
958
|
|
|
|
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* Install Project Config. |
963
|
|
|
* |
964
|
|
|
* @param string $theme_name |
965
|
|
|
* @return bool |
966
|
|
|
*/ |
967
|
|
|
public function installProjectConfig($theme_name = 'adminlte2') |
968
|
|
|
{ |
969
|
|
|
$nameSmall = Str::snake($this->getParsedNameInput()); |
970
|
|
|
|
971
|
|
|
$projectConfigFile = file_get_contents(__DIR__ . '/../Stubs/Config/config.stub'); |
972
|
|
|
|
973
|
|
|
|
974
|
|
|
file_put_contents($this->getConfigsFolderPath().'/'.$nameSmall.'_config.php', str_replace([ |
975
|
|
|
'{{$theme_name}}'], |
976
|
|
|
[$theme_name], |
977
|
|
|
$projectConfigFile)); |
978
|
|
|
|
979
|
|
|
return true; |
980
|
|
|
|
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Install panel files under public folder |
985
|
|
|
* if developer requested free theme |
986
|
|
|
* |
987
|
|
|
* @param string $theme_name |
988
|
|
|
* @return bool |
989
|
|
|
*/ |
990
|
|
|
public function installPublicFilesIfNeeded($theme_name = 'adminlte2') { |
991
|
|
|
|
992
|
|
|
$publicPath = $this->getPublicFolderPath(); |
993
|
|
|
$themePublicPath = $publicPath.DIRECTORY_SEPARATOR.$theme_name; |
994
|
|
|
if (!file_exists($themePublicPath)) { |
995
|
|
|
$githubLink = $this->getGitLinkForFreeTheme($theme_name); |
996
|
|
|
if (!is_null($githubLink) && is_string($githubLink)) { |
997
|
|
|
$zipFileName = basename($githubLink); |
998
|
|
|
$zipFile = file_get_contents($githubLink); |
999
|
|
|
$publicPath = $this->getPublicFolderPath(); |
1000
|
|
|
$zipFilePath = $publicPath.DIRECTORY_SEPARATOR.$zipFileName; |
1001
|
|
|
file_put_contents($zipFilePath, $zipFile); |
1002
|
|
|
$extracted = $this->unzipThemeFile($zipFilePath, $publicPath); |
1003
|
|
|
if ($extracted) { |
1004
|
|
|
$renamed = false; |
1005
|
|
|
if ($theme_name === 'adminlte2') { |
1006
|
|
|
$adminLte2Path = $publicPath.DIRECTORY_SEPARATOR."AdminLTE-master"; |
1007
|
|
|
$renamed = rename($adminLte2Path, $themePublicPath); |
1008
|
|
|
} else if ($theme_name === 'tabler') { |
1009
|
|
|
$tablerPath = $publicPath.DIRECTORY_SEPARATOR."tabler-master"; |
1010
|
|
|
$renamed = rename($tablerPath, $themePublicPath); |
1011
|
|
|
} |
1012
|
|
|
return $renamed; |
1013
|
|
|
} |
1014
|
|
|
} |
1015
|
|
|
} |
1016
|
|
|
return false; |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* @param $zipFile |
1021
|
|
|
* @param $outputPath |
1022
|
|
|
* @return bool |
1023
|
|
|
*/ |
1024
|
|
|
public function unzipThemeFile($zipFile, $outputPath) { |
1025
|
|
|
$zip = new \ZipArchive(); |
1026
|
|
|
$res = $zip->open($zipFile); |
1027
|
|
|
if ($res === TRUE) { |
1028
|
|
|
$extracted = $zip->extractTo($outputPath); |
1029
|
|
|
$zip->close(); |
1030
|
|
|
return $extracted; |
1031
|
|
|
} else { |
1032
|
|
|
return false; |
1033
|
|
|
} |
1034
|
|
|
} |
1035
|
|
|
/** |
1036
|
|
|
* Publish Prologue Alert |
1037
|
|
|
* |
1038
|
|
|
* @return boolean |
1039
|
|
|
*/ |
1040
|
|
|
public function installPrologueAlert() { |
1041
|
|
|
$alertsConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."prologue/alerts.php"; |
1042
|
|
|
if (!file_exists($alertsConfigFile)) { |
1043
|
|
|
$this->executeProcess('php artisan vendor:publish --provider="Prologue\Alerts\AlertsServiceProvider"', |
1044
|
|
|
'publishing config for notifications - prologue/alerts'); |
|
|
|
|
1045
|
|
|
} |
1046
|
|
|
|
1047
|
|
|
return true; |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/** |
1051
|
|
|
* Creating notifications table if not exists |
1052
|
|
|
*/ |
1053
|
|
|
public function installNotificationsDatabase() { |
1054
|
|
|
$notificationsTableFile = $this->getMigrationPath().DIRECTORY_SEPARATOR."*_create_notifications_table.php"; |
1055
|
|
|
$globArray = glob($notificationsTableFile); |
1056
|
|
|
if (count($globArray) < 1) { |
1057
|
|
|
$this->executeProcess('php artisan notifications:table', |
1058
|
|
|
'creating notifications table'); |
|
|
|
|
1059
|
|
|
} |
1060
|
|
|
|
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
/** |
1064
|
|
|
* Run a SSH command. |
1065
|
|
|
* |
1066
|
|
|
* @param mixed $command |
1067
|
|
|
* @param string $beforeNotice |
|
|
|
|
1068
|
|
|
* @param string $afterNotice |
|
|
|
|
1069
|
|
|
*/ |
1070
|
|
|
public function executeProcess($command, $arguments = [], $beforeNotice = false, $afterNotice = false) |
1071
|
|
|
{ |
1072
|
|
|
$beforeNotice = $beforeNotice ? ' '.$beforeNotice : 'php artisan '.implode(' ', (array) $command).' '.implode(' ', $arguments); |
1073
|
|
|
|
1074
|
|
|
if (!is_null($beforeNotice)) { |
1075
|
|
|
$this->info('### '.$beforeNotice); |
1076
|
|
|
} else { |
1077
|
|
|
$this->info('### Running: '.$command); |
1078
|
|
|
} |
1079
|
|
|
|
1080
|
|
|
try { |
1081
|
|
|
Artisan::call($command, $arguments); |
1082
|
|
|
} catch (\Exception $e) { |
1083
|
|
|
throw new ProcessFailedException($e); |
1084
|
|
|
} |
1085
|
|
|
|
1086
|
|
|
if ($this->progressBar) { |
1087
|
|
|
$this->progressBar->advance(); |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
if (!is_null($afterNotice)) { |
1091
|
|
|
$this->info('### '.$afterNotice); |
1092
|
|
|
} |
1093
|
|
|
} |
1094
|
|
|
|
1095
|
|
|
/** |
1096
|
|
|
* Get the desired class name from the input. |
1097
|
|
|
* |
1098
|
|
|
* @return string |
1099
|
|
|
*/ |
1100
|
|
|
protected function getParsedNameInput() |
1101
|
|
|
{ |
1102
|
|
|
return mb_strtolower( Str::singular($this->getNameInput())); |
1103
|
|
|
} |
1104
|
|
|
/** |
1105
|
|
|
* Get the desired class name from the input. |
1106
|
|
|
* |
1107
|
|
|
* @return string |
1108
|
|
|
*/ |
1109
|
|
|
protected function getNameInput() |
1110
|
|
|
{ |
1111
|
|
|
$name = $this->argument('name'); |
1112
|
|
|
return trim($name); |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
/** |
1116
|
|
|
* Get github link for free theme |
1117
|
|
|
* |
1118
|
|
|
* @param string $theme_name |
1119
|
|
|
* @return mixed|null |
|
|
|
|
1120
|
|
|
*/ |
1121
|
|
|
protected function getGitLinkForFreeTheme($theme_name = 'adminlte2') |
1122
|
|
|
{ |
1123
|
|
|
$themes = MultiAuthListThemes::githubLinksForFreeThemes(); |
1124
|
|
|
foreach ($themes as $theme => $link) { |
1125
|
|
|
if ($theme === $theme_name) { |
1126
|
|
|
return $link; |
1127
|
|
|
} |
1128
|
|
|
} |
1129
|
|
|
return null; |
1130
|
|
|
} |
1131
|
|
|
|
1132
|
|
|
/** |
1133
|
|
|
* Write the migration file to disk. |
1134
|
|
|
* |
1135
|
|
|
* @param $name |
1136
|
|
|
* @param $table |
1137
|
|
|
* @param $create |
1138
|
|
|
* @throws \Exception |
1139
|
|
|
*/ |
1140
|
|
|
protected function writeMigration($name, $table, $create) |
1141
|
|
|
{ |
1142
|
|
|
$file = pathinfo($this->creator->create( |
1143
|
|
|
$name, $this->getMigrationPath(), $table, $create |
1144
|
|
|
), PATHINFO_FILENAME); |
1145
|
|
|
$this->line("<info>Created Migration:</info> {$file}"); |
1146
|
|
|
} |
1147
|
|
|
|
1148
|
|
|
/** |
1149
|
|
|
* Get migration path. |
1150
|
|
|
* |
1151
|
|
|
* @return string |
1152
|
|
|
*/ |
1153
|
|
|
protected function getMigrationPath() |
1154
|
|
|
{ |
1155
|
|
|
return parent::getMigrationPath(); |
1156
|
|
|
} |
1157
|
|
|
|
1158
|
|
|
/** |
1159
|
|
|
* Get Routes Provider Path. |
1160
|
|
|
* |
1161
|
|
|
* @return string |
1162
|
|
|
*/ |
1163
|
|
|
protected function getRouteServicesPath() |
1164
|
|
|
{ |
1165
|
|
|
return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Providers'.DIRECTORY_SEPARATOR.'RouteServiceProvider.php'; |
1166
|
|
|
} |
1167
|
|
|
|
1168
|
|
|
/** |
1169
|
|
|
* Get Routes Folder Path. |
1170
|
|
|
* |
1171
|
|
|
* @return string |
1172
|
|
|
*/ |
1173
|
|
|
protected function getAppFolderPath() |
1174
|
|
|
{ |
1175
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'app'; |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
|
/** |
1179
|
|
|
* Get Public Folder Path. |
1180
|
|
|
* |
1181
|
|
|
* @return string |
1182
|
|
|
*/ |
1183
|
|
|
protected function getPublicFolderPath() |
1184
|
|
|
{ |
1185
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'public'; |
1186
|
|
|
} |
1187
|
|
|
|
1188
|
|
|
/** |
1189
|
|
|
* Get Routes Folder Path. |
1190
|
|
|
* |
1191
|
|
|
* @return string |
1192
|
|
|
*/ |
1193
|
|
|
protected function getRoutesFolderPath() |
1194
|
|
|
{ |
1195
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'routes'; |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
/** |
1199
|
|
|
* Get Config Folder Path. |
1200
|
|
|
* |
1201
|
|
|
* @return string |
1202
|
|
|
*/ |
1203
|
|
|
protected function getConfigsFolderPath() |
1204
|
|
|
{ |
1205
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'config'; |
1206
|
|
|
} |
1207
|
|
|
|
1208
|
|
|
/** |
1209
|
|
|
* Get Lang Folder Path. |
1210
|
|
|
* |
1211
|
|
|
* @return string |
1212
|
|
|
*/ |
1213
|
|
|
protected function getLangsFolderPath() |
1214
|
|
|
{ |
1215
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'en'; |
1216
|
|
|
} |
1217
|
|
|
|
1218
|
|
|
/** |
1219
|
|
|
* Get Views Folder Path. |
1220
|
|
|
* |
1221
|
|
|
* @return string |
1222
|
|
|
*/ |
1223
|
|
|
protected function getViewsFolderPath() |
1224
|
|
|
{ |
1225
|
|
|
return $this->laravel->basePath().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'views'; |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
/** |
1229
|
|
|
* Get Controllers Path. |
1230
|
|
|
* |
1231
|
|
|
* @return string |
1232
|
|
|
*/ |
1233
|
|
|
protected function getControllersPath() |
1234
|
|
|
{ |
1235
|
|
|
return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Controllers'; |
1236
|
|
|
} |
1237
|
|
|
|
1238
|
|
|
/** |
1239
|
|
|
* Get Http Path. |
1240
|
|
|
* |
1241
|
|
|
* @return string |
1242
|
|
|
*/ |
1243
|
|
|
protected function getHttpPath() |
1244
|
|
|
{ |
1245
|
|
|
return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'; |
1246
|
|
|
} |
1247
|
|
|
|
1248
|
|
|
/** |
1249
|
|
|
* Get Middleware Path. |
1250
|
|
|
* |
1251
|
|
|
* @return string |
1252
|
|
|
*/ |
1253
|
|
|
protected function getMiddlewarePath() |
1254
|
|
|
{ |
1255
|
|
|
return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Middleware'; |
1256
|
|
|
} |
1257
|
|
|
|
1258
|
|
|
/** |
1259
|
|
|
* insert text into file |
1260
|
|
|
* |
1261
|
|
|
* @param string $filePath |
1262
|
|
|
* @param string $insertMarker |
1263
|
|
|
* @param string $text |
1264
|
|
|
* @param boolean $after |
1265
|
|
|
* |
1266
|
|
|
* @return integer |
1267
|
|
|
*/ |
1268
|
|
|
public function insertIntoFile($filePath, $insertMarker, $text, $after = true) { |
1269
|
|
|
$contents = file_get_contents($filePath); |
1270
|
|
|
$new_contents = preg_replace($insertMarker,($after) ? '$0' . $text : $text . '$0', $contents); |
1271
|
|
|
return file_put_contents($filePath, $new_contents); |
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
/** |
1275
|
|
|
* insert text into file |
1276
|
|
|
* |
1277
|
|
|
* @param string $filePath |
1278
|
|
|
* @param string $keyword |
1279
|
|
|
* @param string $body |
1280
|
|
|
* @param boolean $after |
1281
|
|
|
* |
1282
|
|
|
* @return integer |
1283
|
|
|
*/ |
1284
|
|
|
public function insert($filePath, $keyword, $body, $after = true) { |
1285
|
|
|
|
1286
|
|
|
$contents = file_get_contents($filePath); |
1287
|
|
|
$new_contents = substr_replace($contents, PHP_EOL . $body, |
1288
|
|
|
($after) ? strpos($contents, $keyword) + strlen($keyword) : strpos($contents, $keyword) |
1289
|
|
|
, 0); |
1290
|
|
|
return file_put_contents($filePath, $new_contents); |
1291
|
|
|
} |
1292
|
|
|
} |
1293
|
|
|
|