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