Completed
Push — master ( db4923...0a5701 )
by Mokhlas
03:33
created

MultiAuthPrepare::getPublicFolderPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
            $this->line(" installing admin panel files under public folder...");
137
            $this->installPublicFilesIfNeeded($admin_theme);
138
            $this->progressBar->advance();
139
140
            $this->line(" installing prologue alert...");
141
            $this->installPrologueAlert();
142
            $this->progressBar->advance();
143
144
            $this->line(" dump autoload...");
145
            $this->composer->dumpAutoloads();
146
            $this->progressBar->advance();
147
148
            $this->progressBar->finish();
149
            $this->info(" finished ".$name." setup with Backpack panel.");
150
        } else {
151
            $this->progressBar->advance();
152
            $this->progressBar->finish();
153
            $this->line(" failed: ".$admin_theme." theme not found");
154
        }
155
        return true;
156
    }
157
158
159
    /**
160
     * @param $admin_theme
161
     * @return bool
162
     */
163
    private function checkIfThemeFileExistsOrNot($admin_theme) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $admin_theme is not named in camelCase.

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.

Loading history...
164
        return (file_exists(__DIR__ . '/../Stubs/Views/'.$admin_theme.'/dashboard.blade.stub'));
165
    }
166
167
    /**
168
     * @return bool
169
     */
170
    public function isAlreadySetup() {
171
        $name = ucfirst($this->getParsedNameInput());
172
173
        $routeServicesContent = file_get_contents($this->getRouteServicesPath());
174
175
        if (str_contains($routeServicesContent,'$this->map'.$name.'Routes();')) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return str_contains($rou.... $name . 'Routes();');.
Loading history...
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
176
            return true;
177
        }
178
        return false;
179
    }
180
181
    /**
182
     * Install Migration.
183
     *
184
     * @return boolean
185
     */
186
    public function installMigration()
187
    {
188
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
189
        $name = ucfirst($this->getParsedNameInput());
190
        $namePlural = str_plural($name);
0 ignored issues
show
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
191
192
193
194
        $modelTableContent = file_get_contents(__DIR__ . '/../Stubs/Migration/modelTable.stub');
195
        $modelTableContentNew = str_replace([
196
            '{{$namePlural}}',
197
            '{{$nameSmallPlural}}',
198
        ], [
199
            $namePlural,
200
            $nameSmallPlural
201
        ], $modelTableContent);
202
203
204
        $modelResetPasswordTableContent = file_get_contents(__DIR__ . '/../Stubs/Migration/passwordResetsTable.stub');
205
        $modelResetPasswordTableContentNew = str_replace([
206
            '{{$namePlural}}',
207
            '{{$nameSmallPlural}}',
208
        ], [
209
            $namePlural,
210
            $nameSmallPlural
211
        ], $modelResetPasswordTableContent);
212
213
214
        $migrationName = date('Y_m_d_His') . '_'.'create_' . str_plural(snake_case($name)) .'_table.php';
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
215
        $migrationModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationName;
216
        file_put_contents($migrationModelPath, $modelTableContentNew);
217
218
        $migrationResetName = date('Y_m_d_His') . '_'
219
            .'create_' . str_plural(snake_case($name))
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
220
            .'_password_resets_table.php';
221
        $migrationResetModelPath = $this->getMigrationPath().DIRECTORY_SEPARATOR.$migrationResetName;
222
        file_put_contents($migrationResetModelPath, $modelResetPasswordTableContentNew);
223
224
        return true;
225
226
    }
227
228
    /**
229
     * Install Model.
230
     *
231
     * @return boolean
232
     */
233
    public function installModel()
234
    {
235
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
236
        $name = ucfirst($this->getParsedNameInput());
237
238
239
        $arrayToChange = [
240
            '{{$name}}',
241
        ];
242
243
        $newChanges = [
244
            $name,
245
        ];
246
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
247
        array_push($arrayToChange, '{{$nameSmallPlural}}');
248
        array_push($arrayToChange, '{{$nameSmall}}');
249
        array_push($newChanges, $nameSmallPlural);
250
        array_push($newChanges, $nameSmall);
251
252
        $modelContent = file_get_contents(__DIR__ . '/../Stubs/Model/model.stub');
253
        $modelContentNew = str_replace($arrayToChange, $newChanges, $modelContent);
254
255
        $createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Models";
256
        if (!file_exists($createFolder)) {
257
            mkdir($createFolder);
258
        }
259
260
        $modelPath = $createFolder.DIRECTORY_SEPARATOR.$name.".php";
261
        file_put_contents($modelPath, $modelContentNew);
262
263
264
265
        $resetNotificationContent = file_get_contents(__DIR__ . '/../Stubs/Notification/resetPasswordNotification.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
266
        $resetNotificationContentNew = str_replace([
267
            '{{$name}}',
268
            '{{$nameSmall}}',
269
        ], [
270
            $name,
271
            $nameSmall
272
        ], $resetNotificationContent);
273
274
        $verifyEmailContent = file_get_contents(__DIR__ . '/../Stubs/Notification/verifyEmailNotification.stub');
275
        $verifyEmailContentNew = str_replace([
276
            '{{$name}}',
277
            '{{$nameSmall}}',
278
        ], [
279
            $name,
280
            $nameSmall
281
        ], $verifyEmailContent);
282
283
        $createFolder = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Notifications";
284
        if (!file_exists($createFolder)) {
285
            mkdir($createFolder);
286
        }
287
288
        $resetNotificationPath = $createFolder.DIRECTORY_SEPARATOR.$name."ResetPasswordNotification.php";
289
        file_put_contents($resetNotificationPath, $resetNotificationContentNew);
290
291
        $verifyEmailPath = $createFolder.DIRECTORY_SEPARATOR.$name."VerifyEmailNotification.php";
292
        file_put_contents($verifyEmailPath, $verifyEmailContentNew);
293
294
        return true;
295
296
    }
297
298
    /**
299
     * Install RouteMaps.
300
     *
301
     * @return boolean
302
     */
303
304
    public function installRouteMaps()
305
    {
306
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
307
        $name = ucfirst($this->getParsedNameInput());
308
        $mapCallFunction = file_get_contents(__DIR__ . '/../Stubs/Route/mapRoute.stub');
309
        $mapCallFunctionNew = str_replace('{{$name}}', "$name", $mapCallFunction);
310
        $this->insert($this->getRouteServicesPath(), '$this->mapWebRoutes();', $mapCallFunctionNew, true);
311
        $mapFunction = file_get_contents(__DIR__ . '/../Stubs/Route/mapRouteFunction.stub');
312
        $mapFunctionNew = str_replace([
313
            '{{$name}}',
314
            '{{$nameSmall}}'
315
        ], [
316
            "$name",
317
            "$nameSmall"
318
        ], $mapFunction);
319
        $this->insert($this->getRouteServicesPath(), '        //
320
    }', $mapFunctionNew, true);
321
        return true;
322
    }
323
324
    /**
325
     * Install RouteFile.
326
     *
327
     * @return boolean
328
     */
329
330
    public function installRouteFiles()
331
    {
332
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
333
        $name = ucfirst($this->getParsedNameInput());
334
        $createFolder = $this->getRoutesFolderPath().DIRECTORY_SEPARATOR.$nameSmall;
335
        if (!file_exists($createFolder)) {
336
            mkdir($createFolder);
337
        }
338
        $routeFileContent = file_get_contents(__DIR__ . '/../Stubs/Route/routeFile.stub');
339
        $routeFileContentNew = str_replace([
340
            '{{$name}}',
341
            '{{$nameSmall}}'
342
        ], [
343
            "$name",
344
            "$nameSmall"
345
        ], $routeFileContent);
346
        $routeFile = $createFolder.DIRECTORY_SEPARATOR.$nameSmall.".php";
347
        file_put_contents($routeFile, $routeFileContentNew);
348
        return true;
349
    }
350
351
    /**
352
     * Install Controller.
353
     *
354
     * @return boolean
355
     */
356
357
    public function installControllers()
358
    {
359
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
360
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
361
        $name = ucfirst($this->getParsedNameInput());
362
363
        $nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name;
364
        if (!file_exists($nameFolder)) {
365
            mkdir($nameFolder);
366
        }
367
368
        $authFolder = $nameFolder.DIRECTORY_SEPARATOR."Auth";
369
        if (!file_exists($authFolder)) {
370
            mkdir($authFolder);
371
        }
372
373
        $controllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Controller.stub');
374
        $homeControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/DashboardController.stub');
375
        $loginControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/LoginController.stub');
376
        $forgotControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/ForgotPasswordController.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
377
        $registerControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/RegisterController.stub');
378
        $resetControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/ResetPasswordController.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
379
        $myAccountControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/MyAccountController.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 121 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
380
        $verificationControllerContent = file_get_contents(__DIR__ . '/../Stubs/Controllers/Auth/VerificationController.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
381
382
        $controllerFileContentNew = str_replace('{{$name}}', "$name", $controllerContent);
383
384
        $homeFileContentNew = str_replace([
385
            '{{$name}}',
386
            '{{$nameSmall}}'
387
        ], [
388
            "$name",
389
            "$nameSmall"
390
        ], $homeControllerContent);
391
392
        $loginFileContentNew = str_replace([
393
            '{{$name}}',
394
            '{{$nameSmall}}'
395
        ], [
396
            "$name",
397
            "$nameSmall"
398
        ], $loginControllerContent);
399
400
        $forgotFileContentNew = str_replace([
401
            '{{$name}}',
402
            '{{$nameSmall}}',
403
            '{{$nameSmallPlural}}'
404
        ], [
405
            "$name",
406
            "$nameSmall",
407
            "$nameSmallPlural"
408
        ], $forgotControllerContent);
409
410
        $registerFileContentNew = str_replace([
411
            '{{$name}}',
412
            '{{$nameSmall}}',
413
            '{{$nameSmallPlural}}'
414
        ], [
415
            "$name",
416
            "$nameSmall",
417
            "$nameSmallPlural"
418
        ], $registerControllerContent);
419
420
        $resetFileContentNew = str_replace([
421
            '{{$name}}',
422
            '{{$nameSmall}}',
423
            '{{$nameSmallPlural}}'
424
        ], [
425
            "$name",
426
            "$nameSmall",
427
            "$nameSmallPlural"
428
        ], $resetControllerContent);
429
430
        $myAccountFileContentNew = str_replace([
431
            '{{$name}}',
432
            '{{$nameSmall}}'
433
        ], [
434
            "$name",
435
            "$nameSmall"
436
        ], $myAccountControllerContent);
437
438
        $verificationControllerContentNew = str_replace([
439
            '{{$name}}',
440
            '{{$nameSmall}}'
441
        ], [
442
            "$name",
443
            "$nameSmall"
444
        ], $verificationControllerContent);
445
446
        $controllerFile = $nameFolder.DIRECTORY_SEPARATOR."Controller.php";
447
        $homeFile = $nameFolder.DIRECTORY_SEPARATOR."DashboardController.php";
448
        $loginFile = $authFolder.DIRECTORY_SEPARATOR."LoginController.php";
449
        $forgotFile = $authFolder.DIRECTORY_SEPARATOR."ForgotPasswordController.php";
450
        $registerFile = $authFolder.DIRECTORY_SEPARATOR."RegisterController.php";
451
        $resetFile = $authFolder.DIRECTORY_SEPARATOR."ResetPasswordController.php";
452
        $verificationFile = $authFolder.DIRECTORY_SEPARATOR."VerificationController.php";
453
454
        $myAccountFile = $authFolder.DIRECTORY_SEPARATOR."{$name}AccountController.php";
455
456
457
        file_put_contents($controllerFile, $controllerFileContentNew);
458
        file_put_contents($homeFile, $homeFileContentNew);
459
        file_put_contents($loginFile, $loginFileContentNew);
460
        file_put_contents($forgotFile, $forgotFileContentNew);
461
        file_put_contents($registerFile, $registerFileContentNew);
462
        file_put_contents($resetFile, $resetFileContentNew);
463
        file_put_contents($myAccountFile, $myAccountFileContentNew);
464
        file_put_contents($verificationFile, $verificationControllerContentNew);
465
466
        return true;
467
468
    }
469
470
    /**
471
     * Install Requests.
472
     *
473
     * @return boolean
474
     */
475
476
    public function installRequests()
477
    {
478
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
479
        $name = ucfirst($this->getParsedNameInput());
480
481
        $nameFolder = $this->getControllersPath().DIRECTORY_SEPARATOR.$name;
482
        if (!file_exists($nameFolder)) {
483
            mkdir($nameFolder);
484
        }
485
486
        $requestsFolder = $nameFolder.DIRECTORY_SEPARATOR."Requests";
487
        if (!file_exists($requestsFolder)) {
488
            mkdir($requestsFolder);
489
        }
490
        $accountInfoContent = file_get_contents(__DIR__ . '/../Stubs/Request/AccountInfoRequest.stub');
491
        $changePasswordContent = file_get_contents(__DIR__ . '/../Stubs/Request/ChangePasswordRequest.stub');
492
493
        $accountInfoContentNew = str_replace([
494
            '{{$name}}',
495
            '{{$nameSmall}}'
496
        ], [
497
            "$name",
498
            "$nameSmall"
499
        ], $accountInfoContent);
500
501
        $changePasswordContentNew = str_replace([
502
            '{{$name}}',
503
            '{{$nameSmall}}'
504
        ], [
505
            "$name",
506
            "$nameSmall"
507
        ], $changePasswordContent);
508
509
        $accountInfoFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}AccountInfoRequest.php";
510
        $changePasswordFile = $requestsFolder.DIRECTORY_SEPARATOR."{$name}ChangePasswordRequest.php";
511
512
        file_put_contents($accountInfoFile, $accountInfoContentNew);
513
        file_put_contents($changePasswordFile, $changePasswordContentNew);
514
515
        return true;
516
517
    }
518
519
    /**
520
     * Install Configs.
521
     *
522
     * @return boolean
523
     */
524
525
    public function installConfigs()
526
    {
527
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
528
        $nameSmallPlural = str_plural(snake_case($this->getParsedNameInput()));
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
Deprecated Code introduced by
The function str_plural() has been deprecated with message: Str::plural() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
529
        $name = ucfirst($this->getParsedNameInput());
530
531
        $authConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."auth.php";
532
533
        $guardContent = file_get_contents(__DIR__ . '/../Stubs/Config/guard.stub');
534
        $passwordContent = file_get_contents(__DIR__ . '/../Stubs/Config/password.stub');
535
        $providerContent = file_get_contents(__DIR__ . '/../Stubs/Config/provider.stub');
536
537
        $guardFileContentNew = str_replace([
538
            '{{$nameSmall}}',
539
            '{{$nameSmallPlural}}'
540
        ], [
541
            "$nameSmall",
542
            "$nameSmallPlural"
543
        ], $guardContent);
544
545
        $passwordFileContentNew = str_replace('{{$nameSmallPlural}}', "$nameSmallPlural", $passwordContent);
546
547
        $providerFileContentNew = str_replace([
548
            '{{$name}}',
549
            '{{$nameSmallPlural}}'
550
        ], [
551
            "$name",
552
            "$nameSmallPlural"
553
        ], $providerContent);
554
555
        $this->insert($authConfigFile, '    \'guards\' => [', $guardFileContentNew, true);
556
557
        $this->insert($authConfigFile, '    \'passwords\' => [', $passwordFileContentNew, true);
558
559
        $this->insert($authConfigFile, '    \'providers\' => [', $providerFileContentNew, true);
560
561
        return true;
562
563
    }
564
565
    /**
566
     * Install Middleware.
567
     *
568
     * @return boolean
569
     */
570
571
    public function installMiddleware()
572
    {
573
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
574
575
        $redirectIfMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."RedirectIfAuthenticated.php";
576
        $authenticateMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."Authenticate.php";
577
        $ensureEmailIsVerifiedMiddlewareFile = $this->getMiddlewarePath().DIRECTORY_SEPARATOR."EnsureEmailIsVerified.php";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
578
        $middlewareKernelFile = $this->getHttpPath().DIRECTORY_SEPARATOR."Kernel.php";
579
580
        $redirectIfMiddlewareFileContent = file_get_contents($redirectIfMiddlewareFile);
581
        $authenticateMiddlewareFileContent = file_get_contents($redirectIfMiddlewareFile);
582
583
        $ensureEmailIsVerifiedMiddlewareFileeContent = file_get_contents(__DIR__ . '/../Stubs/Middleware/ensureEmailIsVerified.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
584
        $redirectIfMiddlewareContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectIf.stub');
585
        $authenticateMiddlewareContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/authenticate.stub');
586
587
        if (!file_exists($ensureEmailIsVerifiedMiddlewareFile)) {
588
            file_put_contents($ensureEmailIsVerifiedMiddlewareFile, $ensureEmailIsVerifiedMiddlewareFileeContent);
589
        }
590
591
        if (!str_contains($redirectIfMiddlewareFileContent, 'MultiAuthGuards')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
592
            // replace old file
593
            $deleted = unlink($redirectIfMiddlewareFile);
594
            if ($deleted) {
595
                file_put_contents($redirectIfMiddlewareFile, $redirectIfMiddlewareContentNew);
596
            }
597
        }
598
599
        if (!str_contains($authenticateMiddlewareFileContent, 'MultiAuthGuards')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
600
            // replace old file
601
            $deleted = unlink($authenticateMiddlewareFile);
602
            if ($deleted) {
603
                file_put_contents($authenticateMiddlewareFile, $authenticateMiddlewareContentNew);
604
            }
605
        }
606
607
        $redirectIfMiddlewareGroupContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectMiddleware.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
608
        $redirectIfMiddlewareGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/redirectMiddlewareGuard.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
609
        $authenticateIfMiddlewareGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Middleware/authenticateIf.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
610
611
        $redirectIfMiddlewareGroupContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
612
            $redirectIfMiddlewareGroupContentNew);
613
        $redirectIfMiddlewareGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
614
            $redirectIfMiddlewareGuardContentNew);
615
        $authenticateIfMiddlewareGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
616
            $authenticateIfMiddlewareGuardContentNew);
617
618
        $this->insert($middlewareKernelFile, '    protected $middlewareGroups = [',
619
            $redirectIfMiddlewareGroupContentNew2, true);
620
621
        $this->insert($redirectIfMiddlewareFile, '        switch ($guard) {',
622
            $redirectIfMiddlewareGuardContentNew2, true);
623
624
        $this->insert($authenticateMiddlewareFile, '        // MultiAuthGuards',
625
            $authenticateIfMiddlewareGuardContentNew2, true);
626
627
        return true;
628
629
    }
630
631
    /**
632
     * Install Unauthenticated Handler.
633
     *
634
     * @return boolean
635
     */
636
    public function installUnauthenticated()
637
    {
638
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
639
        $exceptionHandlerFile = $this->getAppFolderPath().DIRECTORY_SEPARATOR."Exceptions".DIRECTORY_SEPARATOR
640
            ."Handler.php";
641
        $exceptionHandlerFileContent = file_get_contents($exceptionHandlerFile);
642
        $exceptionHandlerFileContentNew = file_get_contents(__DIR__ . '/../Stubs/Exceptions/handlerUnauthorized.stub');
643
644
645
        if (!str_contains($exceptionHandlerFileContent, 'MultiAuthUnAuthenticated')) {
0 ignored issues
show
Deprecated Code introduced by
The function str_contains() has been deprecated with message: Str::contains() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
646
            // replace old file
647
            $deleted = unlink($exceptionHandlerFile);
648
            if ($deleted) {
649
                file_put_contents($exceptionHandlerFile, $exceptionHandlerFileContentNew);
650
            }
651
        }
652
653
        $exceptionHandlerGuardContentNew = file_get_contents(__DIR__ . '/../Stubs/Exceptions/handlerGuard.stub');
654
        $exceptionHandlerGuardContentNew2 = str_replace('{{$nameSmall}}', "$nameSmall",
655
            $exceptionHandlerGuardContentNew);
656
657
        $this->insert($exceptionHandlerFile, '        switch(array_get($exception->guards(), 0)) {',
658
            $exceptionHandlerGuardContentNew2, true);
659
660
        return true;
661
662
    }
663
664
    /**
665
     * Install View.
666
     *
667
     * @param string $theme_name
668
     */
669
    public function installView($theme_name = 'adminlte2')
0 ignored issues
show
Coding Style Naming introduced by
The parameter $theme_name is not named in camelCase.

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.

Loading history...
670
    {
671
672
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
673
674
        // layouts
675
        $layoutBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/layouts/layout.blade.stub');
676
        $layoutGuestBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/layouts/layout_guest.blade.stub');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
677
678
        // dashboard
679
        $dashboardBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/dashboard.blade.stub');
680
681
        // auth
682
        $loginBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/login.blade.stub');
683
        $registerBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/register.blade.stub');
684
        $verifyEmailBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/verify.blade.stub');
685
686
        // auth/passwords
687
        $resetBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/passwords/reset.blade.stub');
688
        $emailBlade = file_get_contents(__DIR__ . '/../Stubs/Views/'.$theme_name.'/auth/passwords/email.blade.stub');
689
690
        // auth/account
691
        $update_infoBlade = file_get_contents(__DIR__
692
            . '/../Stubs/Views/'.$theme_name.'/auth/account/update_info.blade.stub');
693
        $right_boxBlade = file_get_contents(__DIR__
694
            . '/../Stubs/Views/'.$theme_name.'/auth/account/right_box.blade.stub');
695
        $left_boxBlade = file_get_contents(__DIR__
696
            . '/../Stubs/Views/'.$theme_name.'/auth/account/left_box.blade.stub');
697
        $change_passwordBlade = file_get_contents(__DIR__
698
            . '/../Stubs/Views/'.$theme_name.'/auth/account/change_password_tab.blade.stub');
699
        $account_infoBlade = file_get_contents(__DIR__
700
            . '/../Stubs/Views/'.$theme_name.'/auth/account/account_info_tab.blade.stub');
701
702
        // inc
703
        $alertsBlade = file_get_contents(__DIR__
704
            . '/../Stubs/Views/'.$theme_name.'/layouts/inc/alerts.blade.stub');
705
        $breadcrumbBlade = file_get_contents(__DIR__
706
            . '/../Stubs/Views/'.$theme_name.'/layouts/inc/breadcrumb.blade.stub');
707
        $headBlade = file_get_contents(__DIR__
708
            . '/../Stubs/Views/'.$theme_name.'/layouts/inc/head.blade.stub');
709
        $scriptsBlade = file_get_contents(__DIR__
710
            . '/../Stubs/Views/'.$theme_name.'/layouts/inc/scripts.blade.stub');
711
712
713
        // main_header
714
        $main_headerBlade = file_get_contents(__DIR__
715
            . '/../Stubs/Views/'.$theme_name.'/layouts/main_header/main_header.blade.stub');
716
        $languagesBlade = file_get_contents(__DIR__
717
            . '/../Stubs/Views/'.$theme_name.'/layouts/main_header/languages.blade.stub');
718
        $notificationsBlade = file_get_contents(__DIR__
719
            . '/../Stubs/Views/'.$theme_name.'/layouts/main_header/notifications.blade.stub');
720
        $userBlade = file_get_contents(__DIR__
721
            . '/../Stubs/Views/'.$theme_name.'/layouts/main_header/user.blade.stub');
722
723
        // sidemenu
724
        $itemsBlade = file_get_contents(__DIR__
725
            . '/../Stubs/Views/'.$theme_name.'/layouts/sidemenu/items.blade.stub');
726
        $listBlade = file_get_contents(__DIR__
727
            . '/../Stubs/Views/'.$theme_name.'/layouts/sidemenu/list.blade.stub');
728
729
730
        $createdFolders = $this->createViewsFolders($nameSmall);
731
732
733
        file_put_contents($createdFolders[4].'/layout.blade.php', str_replace([
734
            '{{$nameSmall}}',
735
        ], [
736
            $nameSmall
737
        ], $layoutBlade));
738
739
        file_put_contents($createdFolders[4].'/layout_guest.blade.php', str_replace([
740
            '{{$nameSmall}}',
741
        ], [
742
            $nameSmall
743
        ], $layoutGuestBlade));
744
745
        file_put_contents($createdFolders[0].'/dashboard.blade.php', str_replace([
746
            '{{$nameSmall}}',
747
        ], [
748
            $nameSmall
749
        ], $dashboardBlade));
750
751
        file_put_contents($createdFolders[1].'/login.blade.php', str_replace([
752
            '{{$nameSmall}}',
753
        ], [
754
            $nameSmall
755
        ], $loginBlade));
756
757
        file_put_contents($createdFolders[1].'/register.blade.php', str_replace([
758
            '{{$nameSmall}}',
759
        ], [
760
            $nameSmall
761
        ], $registerBlade));
762
763
        file_put_contents($createdFolders[1].'/verify.blade.php', str_replace([
764
            '{{$nameSmall}}',
765
        ], [
766
            $nameSmall
767
        ], $verifyEmailBlade));
768
769
        file_put_contents($createdFolders[2].'/reset.blade.php', str_replace([
770
            '{{$nameSmall}}',
771
        ], [
772
            $nameSmall
773
        ], $resetBlade));
774
775
        file_put_contents($createdFolders[2].'/email.blade.php', str_replace([
776
            '{{$nameSmall}}',
777
        ], [
778
            $nameSmall
779
        ], $emailBlade));
780
781
        file_put_contents($createdFolders[3].'/update_info.blade.php', str_replace([
782
            '{{$nameSmall}}',
783
        ], [
784
            $nameSmall
785
        ], $update_infoBlade));
786
787
        file_put_contents($createdFolders[3].'/right_box.blade.php', str_replace([
788
            '{{$nameSmall}}',
789
        ], [
790
            $nameSmall
791
        ], $right_boxBlade));
792
793
        file_put_contents($createdFolders[3].'/left_box.blade.php', str_replace([
794
            '{{$nameSmall}}',
795
        ], [
796
            $nameSmall
797
        ], $left_boxBlade));
798
799
        file_put_contents($createdFolders[3].'/change_password_tab.blade.php', str_replace([
800
            '{{$nameSmall}}',
801
        ], [
802
            $nameSmall
803
        ], $change_passwordBlade));
804
805
        file_put_contents($createdFolders[3].'/account_info_tab.blade.php', str_replace([
806
            '{{$nameSmall}}',
807
        ], [
808
            $nameSmall
809
        ], $account_infoBlade));
810
811
        file_put_contents($createdFolders[5].'/alerts.blade.php', str_replace([
812
            '{{$nameSmall}}',
813
        ], [
814
            $nameSmall
815
        ], $alertsBlade));
816
817
        file_put_contents($createdFolders[5].'/breadcrumb.blade.php', str_replace([
818
            '{{$nameSmall}}',
819
        ], [
820
            $nameSmall
821
        ], $breadcrumbBlade));
822
823
        file_put_contents($createdFolders[5].'/head.blade.php', str_replace([
824
            '{{$nameSmall}}',
825
        ], [
826
            $nameSmall
827
        ], $headBlade));
828
829
        file_put_contents($createdFolders[5].'/scripts.blade.php', str_replace([
830
            '{{$nameSmall}}',
831
        ], [
832
            $nameSmall
833
        ], $scriptsBlade));
834
835
        file_put_contents($createdFolders[6].'/languages.blade.php', str_replace([
836
            '{{$nameSmall}}',
837
        ], [
838
            $nameSmall
839
        ], $languagesBlade));
840
841
        file_put_contents($createdFolders[6].'/main_header.blade.php', str_replace([
842
            '{{$nameSmall}}',
843
        ], [
844
            $nameSmall
845
        ], $main_headerBlade));
846
847
        file_put_contents($createdFolders[6].'/notifications.blade.php', str_replace([
848
            '{{$nameSmall}}',
849
        ], [
850
            $nameSmall
851
        ], $notificationsBlade));
852
853
        file_put_contents($createdFolders[6].'/user.blade.php', str_replace([
854
            '{{$nameSmall}}',
855
        ], [
856
            $nameSmall
857
        ], $userBlade));
858
859
        file_put_contents($createdFolders[7].'/items.blade.php', str_replace([
860
            '{{$nameSmall}}',
861
        ], [
862
            $nameSmall
863
        ], $itemsBlade));
864
865
        file_put_contents($createdFolders[7].'/list.blade.php', str_replace([
866
            '{{$nameSmall}}',
867
        ], [
868
            $nameSmall
869
        ], $listBlade));
870
871
    }
872
873
    /**
874
     * @param string $nameSmall
875
     * @return string[]
876
     */
877
    protected function createViewsFolders($nameSmall) {
878
879
        // main guard folder
880
        $createFolder = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall";
881
        if (!file_exists($createFolder)) {
882
            mkdir($createFolder);
883
        }
884
885
        // Auth folder
886
        $createFolderAuth = $this->getViewsFolderPath().DIRECTORY_SEPARATOR."$nameSmall"
887
            .DIRECTORY_SEPARATOR."auth";
888
        if (!file_exists($createFolderAuth)) {
889
            mkdir($createFolderAuth);
890
        }
891
892
        $createFolderAuthPasswords = $createFolderAuth.DIRECTORY_SEPARATOR."passwords";
893
        if (!file_exists($createFolderAuthPasswords)) {
894
            mkdir($createFolderAuthPasswords);
895
        }
896
897
        $createFolderAuthAccount = $createFolderAuth.DIRECTORY_SEPARATOR."account";
898
        if (!file_exists($createFolderAuthAccount)) {
899
            mkdir($createFolderAuthAccount);
900
        }
901
902
        // Layout folder
903
        $createFolderLayouts = $this->getViewsFolderPath().DIRECTORY_SEPARATOR
904
            ."$nameSmall"
905
            .DIRECTORY_SEPARATOR."layouts";
906
        if (!file_exists($createFolderLayouts)) {
907
            mkdir($createFolderLayouts);
908
        }
909
910
        $createFolderLayoutsInc = $createFolderLayouts .DIRECTORY_SEPARATOR."inc";
911
        if (!file_exists($createFolderLayoutsInc)) {
912
            mkdir($createFolderLayoutsInc);
913
        }
914
915
        $createFolderLayoutsMainHeader = $createFolderLayouts .DIRECTORY_SEPARATOR."main_header";
916
        if (!file_exists($createFolderLayoutsMainHeader)) {
917
            mkdir($createFolderLayoutsMainHeader);
918
        }
919
920
        $createFolderLayoutsSideMenu = $createFolderLayouts .DIRECTORY_SEPARATOR."sidemenu";
921
        if (!file_exists($createFolderLayoutsSideMenu)) {
922
            mkdir($createFolderLayoutsSideMenu);
923
        }
924
925
        return [
926
            $createFolder,
927
            $createFolderAuth,
928
            $createFolderAuthPasswords,
929
            $createFolderAuthAccount,
930
931
            $createFolderLayouts,
932
            $createFolderLayoutsInc,
933
            $createFolderLayoutsMainHeader,
934
            $createFolderLayoutsSideMenu
935
        ];
936
937
    }
938
939
    /**
940
     * Install Lang.
941
     *
942
     * @return boolean
943
     */
944
945
    public function installLangs()
946
    {
947
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
948
949
        $dashboardLangFile = file_get_contents(__DIR__ . '/../Stubs/Languages/dashboard.stub');
950
        file_put_contents($this->getLangsFolderPath().'/'.$nameSmall.'_dashboard.php', $dashboardLangFile);
951
952
        return true;
953
954
    }
955
956
    /**
957
     * Install Project Config.
958
     *
959
     * @param string $theme_name
960
     * @return bool
961
     */
962
    public function installProjectConfig($theme_name = 'adminlte2')
0 ignored issues
show
Coding Style Naming introduced by
The parameter $theme_name is not named in camelCase.

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.

Loading history...
963
    {
964
        $nameSmall = snake_case($this->getParsedNameInput());
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated with message: Str::snake() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
965
966
        $projectConfigFile = file_get_contents(__DIR__ . '/../Stubs/Config/config.stub');
967
968
969
        file_put_contents($this->getConfigsFolderPath().'/'.$nameSmall.'_config.php', str_replace([
970
            '{{$theme_name}}'],
971
            [$theme_name],
972
            $projectConfigFile));
973
974
        return true;
975
976
    }
977
978
    /**
979
     * Install panel files under public folder
980
     * if developer requested free theme
981
     *
982
     * @param string $theme_name
983
     * @return bool
984
     */
985
    public function installPublicFilesIfNeeded($theme_name = 'adminlte2') {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $theme_name is not named in camelCase.

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.

Loading history...
986
987
        $githubLink = $this->getGitLinkForFreeTheme($theme_name);
988
        if (!is_null($githubLink) && is_string($githubLink)) {
989
            $zipFileName = basename($githubLink);
990
            $zipFile = file_get_contents($githubLink);
991
            $downloadZipPath = $this->getPublicFolderPath().DIRECTORY_SEPARATOR.$theme_name;
992
            if (!file_exists($downloadZipPath)) {
993
                mkdir($downloadZipPath);
994
            }
995
            $zipFilePath = $downloadZipPath.DIRECTORY_SEPARATOR.$zipFileName;
996
            file_put_contents($zipFilePath, $zipFile);
997
            return $this->unzipThemeFile($zipFilePath, $downloadZipPath);
998
        }
999
        return false;
1000
    }
1001
1002
    /**
1003
     * @param $zipFile
1004
     * @param $outputPath
1005
     * @return bool
1006
     */
1007
    public function unzipThemeFile($zipFile, $outputPath) {
1008
        $zip = new \ZipArchive();
1009
        $res = $zip->open($zipFile);
1010
        if ($res === TRUE) {
1011
            $extracted = $zip->extractTo($outputPath);
1012
            $zip->close();
1013
            return $extracted;
1014
        } else {
1015
            return false;
1016
        }
1017
    }
1018
    /**
1019
     * Publish Prologue Alert
1020
     *
1021
     * @return boolean
1022
     */
1023
    public function installPrologueAlert() {
1024
        $alertsConfigFile = $this->getConfigsFolderPath().DIRECTORY_SEPARATOR."prologue/alerts.php";
1025
        if (!file_exists($alertsConfigFile)) {
1026
            $this->executeProcess('php artisan vendor:publish --provider="Prologue\Alerts\AlertsServiceProvider"',
1027
                'publishing config for notifications - prologue/alerts');
1028
        }
1029
1030
        return true;
1031
    }
1032
1033
    /**
1034
     * Creating notifications table if not exists
1035
     */
1036
    public function installNotificationsDatabase() {
1037
        $notificationsTableFile = $this->getMigrationPath().DIRECTORY_SEPARATOR."*_create_notifications_table.php";
1038
        $globArray = glob($notificationsTableFile);
1039
        if (count($globArray) < 1) {
1040
            $this->executeProcess('php artisan notifications:table',
1041
                'creating notifications table');
1042
        }
1043
1044
    }
1045
1046
    /**
1047
     * Run a SSH command.
1048
     *
1049
     * @param string $command
1050
     * @param string $beforeNotice
1051
     * @param string $afterNotice
1052
     */
1053
    public function executeProcess($command, $beforeNotice = '', $afterNotice = '')
1054
    {
1055
        if (!is_null($beforeNotice)) {
1056
            $this->info('### '.$beforeNotice);
1057
        } else {
1058
            $this->info('### Running: '.$command);
1059
        }
1060
        $process = new Process($command);
0 ignored issues
show
Documentation introduced by
$command is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1061
        $process->run(function ($type, $buffer) {
1062
            if (Process::ERR === $type) {
1063
                echo '... > '.$buffer;
1064
            } else {
1065
                echo 'OUT > '.$buffer;
1066
            }
1067
        });
1068
        // executes after the command finishes
1069
        if (!$process->isSuccessful()) {
1070
            throw new ProcessFailedException($process);
1071
        }
1072
        if (!is_null($afterNotice)) {
1073
            $this->info('### '.$afterNotice);
1074
        }
1075
    }
1076
1077
    /**
1078
     * Get the desired class name from the input.
1079
     *
1080
     * @return string
1081
     */
1082
    protected function getParsedNameInput()
1083
    {
1084
        return mb_strtolower(str_singular($this->getNameInput()));
0 ignored issues
show
Deprecated Code introduced by
The function str_singular() has been deprecated with message: Str::singular() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
1085
    }
1086
    /**
1087
     * Get the desired class name from the input.
1088
     *
1089
     * @return string
1090
     */
1091
    protected function getNameInput()
1092
    {
1093
        $name = $this->argument('name');
1094
        return trim($name);
1095
    }
1096
1097
    /**
1098
     * Get github link for free theme
1099
     *
1100
     * @param string $theme_name
1101
     * @return mixed|null
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
1102
     */
1103
    protected function getGitLinkForFreeTheme($theme_name = 'adminlte2')
0 ignored issues
show
Coding Style Naming introduced by
The parameter $theme_name is not named in camelCase.

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.

Loading history...
1104
    {
1105
        $themes = MultiAuthListThemes::githubLinksForFreeThemes();
1106
        foreach ($themes as $theme => $link) {
1107
            if ($theme === $theme_name) {
1108
                return $link;
1109
            }
1110
        }
1111
        return null;
1112
    }
1113
1114
    /**
1115
     * Write the migration file to disk.
1116
     *
1117
     * @param $name
1118
     * @param $table
1119
     * @param $create
1120
     * @throws \Exception
1121
     */
1122
    protected function writeMigration($name, $table, $create)
1123
    {
1124
        $file = pathinfo($this->creator->create(
1125
            $name, $this->getMigrationPath(), $table, $create
1126
        ), PATHINFO_FILENAME);
1127
        $this->line("<info>Created Migration:</info> {$file}");
1128
    }
1129
1130
    /**
1131
     * Get migration path.
1132
     *
1133
     * @return string
1134
     */
1135
    protected function getMigrationPath()
1136
    {
1137
        return parent::getMigrationPath();
1138
    }
1139
1140
    /**
1141
     * Get Routes Provider Path.
1142
     *
1143
     * @return string
1144
     */
1145
    protected function getRouteServicesPath()
1146
    {
1147
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Providers'.DIRECTORY_SEPARATOR.'RouteServiceProvider.php';
1148
    }
1149
1150
    /**
1151
     * Get Routes Folder Path.
1152
     *
1153
     * @return string
1154
     */
1155
    protected function getAppFolderPath()
1156
    {
1157
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'app';
1158
    }
1159
1160
    /**
1161
     * Get Public Folder Path.
1162
     *
1163
     * @return string
1164
     */
1165
    protected function getPublicFolderPath()
1166
    {
1167
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'public';
1168
    }
1169
1170
    /**
1171
     * Get Routes Folder Path.
1172
     *
1173
     * @return string
1174
     */
1175
    protected function getRoutesFolderPath()
1176
    {
1177
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'routes';
1178
    }
1179
1180
    /**
1181
     * Get Config Folder Path.
1182
     *
1183
     * @return string
1184
     */
1185
    protected function getConfigsFolderPath()
1186
    {
1187
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'config';
1188
    }
1189
1190
    /**
1191
     * Get Lang Folder Path.
1192
     *
1193
     * @return string
1194
     */
1195
    protected function getLangsFolderPath()
1196
    {
1197
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'lang'.DIRECTORY_SEPARATOR.'en';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
1198
    }
1199
1200
    /**
1201
     * Get Views Folder Path.
1202
     *
1203
     * @return string
1204
     */
1205
    protected function getViewsFolderPath()
1206
    {
1207
        return $this->laravel->basePath().DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'views';
1208
    }
1209
1210
    /**
1211
     * Get Controllers Path.
1212
     *
1213
     * @return string
1214
     */
1215
    protected function getControllersPath()
1216
    {
1217
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Controllers';
1218
    }
1219
1220
    /**
1221
     * Get Http Path.
1222
     *
1223
     * @return string
1224
     */
1225
    protected function getHttpPath()
1226
    {
1227
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http';
1228
    }
1229
1230
    /**
1231
     * Get Middleware Path.
1232
     *
1233
     * @return string
1234
     */
1235
    protected function getMiddlewarePath()
1236
    {
1237
        return $this->getAppFolderPath().DIRECTORY_SEPARATOR.'Http'.DIRECTORY_SEPARATOR.'Middleware';
1238
    }
1239
1240
    /**
1241
     * insert text into file
1242
     *
1243
     * @param string $filePath
1244
     * @param string $insertMarker
1245
     * @param string $text
1246
     * @param boolean $after
1247
     *
1248
     * @return integer
1249
     */
1250
    public function insertIntoFile($filePath, $insertMarker, $text, $after = true) {
1251
        $contents = file_get_contents($filePath);
1252
        $new_contents = preg_replace($insertMarker,($after) ? '$0' . $text : $text . '$0', $contents);
1253
        return file_put_contents($filePath, $new_contents);
1254
    }
1255
1256
    /**
1257
     * insert text into file
1258
     *
1259
     * @param string $filePath
1260
     * @param string $keyword
1261
     * @param string $body
1262
     * @param boolean $after
1263
     *
1264
     * @return integer
1265
     */
1266
    public function insert($filePath, $keyword, $body, $after = true) {
1267
1268
        $contents = file_get_contents($filePath);
1269
        $new_contents = substr_replace($contents, PHP_EOL . $body,
1270
            ($after) ? strpos($contents, $keyword) + strlen($keyword) : strpos($contents, $keyword)
1271
            , 0);
1272
        return file_put_contents($filePath, $new_contents);
1273
    }
1274
}
1275