Completed
Push — master ( 5a190f...314952 )
by wen
01:50
created

LaravelServiceProvider::parseEvents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

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 7
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\ModelCreatingEvent::class,
13
        \Sco\ActionLog\Events\ModelCreatedEvent::class,
14
        \Sco\ActionLog\Events\ModelUpdatingEvent::class,
15
        \Sco\ActionLog\Events\ModelUpdatedEvent::class,
16
        \Sco\ActionLog\Events\ModelSavingEvent::class,
17
        \Sco\ActionLog\Events\ModelSavedEvent::class,
18
        \Sco\ActionLog\Events\ModelDeletingEvent::class,
19
        \Sco\ActionLog\Events\ModelDeletedEvent::class,
20
        \Sco\ActionLog\Events\ModelRestoringEvent::class,
21
        \Sco\ActionLog\Events\ModelRestoredEvent::class,
22
    ];
23
24
    public function boot()
25
    {
26
        $this->listen = $this->parseEvents();
27
28
        parent::boot();
29
30
        if ($this->app->runningInConsole()) {
31
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
32
            $this->publishConfig();
33
        }
34
    }
35
36
    private function parseEvents()
37
    {
38
        $listens = [];
39
        $events = array_merge($this->events, config('actionlog.events'));
40
        foreach ($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
        $this->app->singleton('ActionLog', function () {
56
            return new Factory();
57
        });
58
    }
59
60
    private function publishConfig()
61
    {
62
        $this->publishes([
63
            __DIR__ . '/../config/actionlog.php' => config_path('actionlog.php'),
64
        ], 'config');
65
    }
66
}
67