|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpCollective\MenuMaker\Console; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Illuminate\Console\Command; |
|
7
|
|
|
|
|
8
|
|
|
class InstallCommand extends Command |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The name and signature of the console command. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $signature = 'menu:install'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Install all of the Menu Maker resources'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Execute the console command. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
29
|
|
|
*/ |
|
30
|
|
|
public function handle() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->comment('Publishing Menu Assets...'); |
|
33
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'menu-assets']); |
|
34
|
|
|
|
|
35
|
|
|
$this->comment('Publishing Menu Configuration...'); |
|
36
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'menu-config']); |
|
37
|
|
|
|
|
38
|
|
|
$this->comment('Menu Database Files Migrating...'); |
|
39
|
|
|
$this->call('migrate', [ |
|
40
|
|
|
'--force' => true |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
$this->registerMenuAuthorizationMiddleware(); |
|
44
|
|
|
|
|
45
|
|
|
$this->info('Menu scaffolding installed successfully.'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Register the Menu authorization middleware in the application Kernel file. |
|
50
|
|
|
* |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function registerMenuAuthorizationMiddleware() |
|
54
|
|
|
{ |
|
55
|
|
|
$kernelFile = file_get_contents(app_path('Http/Kernel.php')); |
|
56
|
|
|
if (Str::contains($kernelFile, '\\PhpCollective\\MenuMaker\\Http\\Middleware\\VerifyMenuAuthorization::class')) { |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
file_put_contents(app_path('Http/Kernel.php'), str_replace( |
|
61
|
|
|
"\\Illuminate\Auth\Middleware\Authorize::class,".PHP_EOL, |
|
62
|
|
|
"\\Illuminate\Auth\Middleware\Authorize::class,".PHP_EOL." 'menu' => \\PhpCollective\MenuMaker\Http\Middleware\VerifyMenuAuthorization::class,".PHP_EOL, |
|
63
|
|
|
$kernelFile |
|
64
|
|
|
)); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|