1 | <?php |
||
2 | |||
3 | namespace OwenIt\Auditing\Console; |
||
4 | |||
5 | use Illuminate\Console\Command; |
||
6 | use Illuminate\Support\Str; |
||
7 | |||
8 | class InstallCommand extends Command |
||
9 | { |
||
10 | /** |
||
11 | * {@inheritdoc} |
||
12 | */ |
||
13 | protected $signature = 'auditing:install'; |
||
14 | |||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | protected $description = 'Install all of the Auditing resources'; |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | public function handle(): void |
||
24 | { |
||
25 | $this->comment('Publishing Auditing Configuration...'); |
||
26 | $this->callSilent('vendor:publish', ['--tag' => 'config']); |
||
27 | |||
28 | $this->comment('Publishing Auditing Migrations...'); |
||
29 | $this->callSilent('vendor:publish', ['--tag' => 'migrations']); |
||
30 | |||
31 | $this->registerAuditingServiceProvider(); |
||
32 | |||
33 | $this->info('Auditing installed successfully.'); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Register the Auditing service provider in the application configuration file. |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | protected function registerAuditingServiceProvider() |
||
42 | { |
||
43 | $namespace = Str::replaceLast('\\', '', app()->getNamespace()); |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
44 | |||
45 | $appConfig = file_get_contents(config_path('app.php')); |
||
46 | |||
47 | if (! $appConfig || Str::contains($appConfig, 'OwenIt\\Auditing\\AuditingServiceProvider::class')) { |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | file_put_contents(config_path('app.php'), str_replace( |
||
52 | "{$namespace}\\Providers\EventServiceProvider::class," . PHP_EOL, |
||
53 | "{$namespace}\\Providers\EventServiceProvider::class," . PHP_EOL . " OwenIt\Auditing\AuditingServiceProvider::class," . PHP_EOL, |
||
54 | $appConfig |
||
55 | )); |
||
56 | } |
||
57 | } |
||
58 |