IdeHelperServiceProvider::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Staudenmeir\EloquentHasManyDeep;
4
5
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
6
use Illuminate\Contracts\Support\DeferrableProvider;
7
use Illuminate\Support\ServiceProvider;
8
use Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook;
9
10
class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProvider
11
{
12
    public function boot(): void
13
    {
14
        $this->publishConfig();
15
    }
16
17
    public function register(): void
18
    {
19
        $this->registerConfig();
20
21
        $this->registerIdeHelperHook();
22
    }
23
24
    public function provides(): array
25
    {
26
        return [
27
            ModelsCommand::class,
28
        ];
29
    }
30
31
    protected function registerIdeHelperHook(): void
32
    {
33
        /** @var \Illuminate\Contracts\Config\Repository $config */
34
        $config = $this->app->get('config');
35
36
        if (!$config->get('eloquent-has-many-deep.ide_helper_enabled')) {
37
            return;
38
        }
39
40
        $config->set(
41
            'ide-helper.model_hooks',
42
            array_merge(
43
                [DeepRelationsHook::class],
44
                $config->get('ide-helper.model_hooks', [])
45
            )
46
        );
47
    }
48
49
    protected function publishConfig(): void
50
    {
51
        $this->publishes([
52
            __DIR__ . '/../config/eloquent-has-many-deep.php' => config_path('eloquent-has-many-deep.php'),
53
        ], 'eloquent-has-many-deep');
54
    }
55
56
    protected function registerConfig(): void
57
    {
58
        $this->mergeConfigFrom(
59
            __DIR__ . '/../config/eloquent-has-many-deep.php',
60
            'eloquent-has-many-deep',
61
        );
62
    }
63
}
64