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