1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PavelMironchik\LaravelBackupPanel\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
class InstallCommand extends Command |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* The name and signature of the console command. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'laravel-backup-panel:install'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The console command description. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $description = 'Install all of the Laravel Backup Panel resources'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create a new command instance. |
26
|
|
|
* |
27
|
|
|
* @return void |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
parent::__construct(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Execute the console command. |
36
|
|
|
* |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function handle() |
40
|
|
|
{ |
41
|
|
|
$this->comment('Publishing Laravel Backup Panel service provider...'); |
42
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-provider']); |
43
|
|
|
|
44
|
|
|
$this->comment('Publishing Laravel Backup Panel assets...'); |
45
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-assets']); |
46
|
|
|
|
47
|
|
|
$this->comment('Publishing Laravel Backup Panel views...'); |
48
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-views']); |
49
|
|
|
|
50
|
|
|
$this->comment('Publishing Laravel Backup Panel configuration...'); |
51
|
|
|
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-config']); |
52
|
|
|
|
53
|
|
|
$this->registerServiceProvider(); |
54
|
|
|
|
55
|
|
|
$this->info('Laravel Backup Panel resources installed successfully.'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function registerServiceProvider() |
59
|
|
|
{ |
60
|
|
|
$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace()); |
61
|
|
|
|
62
|
|
|
$appConfig = file_get_contents(config_path('app.php')); |
63
|
|
|
|
64
|
|
|
if (Str::contains($appConfig, $namespace.'\\Providers\\LaravelBackupPanelServiceProvider::class')) { |
65
|
|
|
return; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
file_put_contents(config_path('app.php'), str_replace( |
69
|
|
|
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL, |
70
|
|
|
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$namespace}\Providers\LaravelBackupPanelServiceProvider::class,".PHP_EOL, |
71
|
|
|
$appConfig |
72
|
|
|
)); |
73
|
|
|
|
74
|
|
|
file_put_contents(app_path('Providers/LaravelBackupPanelServiceProvider.php'), str_replace( |
75
|
|
|
"namespace App\Providers;", |
76
|
|
|
"namespace {$namespace}\Providers;", |
77
|
|
|
file_get_contents(app_path('Providers/LaravelBackupPanelServiceProvider.php')) |
78
|
|
|
)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|