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