LaravelServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
4
namespace Sco\ActionLog;
5
6
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
7
use Sco\ActionLog\Listeners\SaveActionLog;
8
9
class LaravelServiceProvider extends ServiceProvider
10
{
11
    protected $events = [
12
        \Sco\ActionLog\Events\ModelWillCreating::class,
13
        \Sco\ActionLog\Events\ModelWasCreated::class,
14
        \Sco\ActionLog\Events\ModelWillUpdating::class,
15
        \Sco\ActionLog\Events\ModelWasUpdated::class,
16
        \Sco\ActionLog\Events\ModelWillSaving::class,
17
        \Sco\ActionLog\Events\ModelWasSaved::class,
18
        \Sco\ActionLog\Events\ModelWillDeleting::class,
19
        \Sco\ActionLog\Events\ModelWasDeleted::class,
20
        \Sco\ActionLog\Events\ModelWillRestoring::class,
21
        \Sco\ActionLog\Events\ModelWasRestored::class,
22
        \Sco\ActionLog\Events\ManualEvent::class,
23
    ];
24
25
    public function boot()
26
    {
27
        $this->listen = $this->parseEvents();
28
29
        parent::boot();
30
31
        if ($this->app->runningInConsole()) {
32
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
33
            $this->publishConfig();
34
        }
35
    }
36
37
    private function parseEvents()
38
    {
39
        $listens = [];
40
        foreach ($this->events as $event) {
41
            $listens[$event] = [
42
                SaveActionLog::class,
43
            ];
44
        }
45
        return $listens;
46
    }
47
48
    public function register()
49
    {
50
        $this->mergeConfigFrom(
51
            __DIR__ . '/../config/actionlog.php',
52
            'actionlog'
53
        );
54
    }
55
56
    private function publishConfig()
57
    {
58
        $this->publishes([
59
            __DIR__ . '/../config/actionlog.php' => config_path('actionlog.php'),
60
        ], 'config');
61
    }
62
}
63