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
|
|
|
|