Completed
Push — master ( 0ba1f3...e49bb9 )
by Freek
03:02
created

EventProjectorServiceProvider::boot()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 15
nc 4
nop 0
1
<?php
2
3
namespace Spatie\EventProjector;
4
5
use Illuminate\Support\Facades\Event;
6
use Illuminate\Support\ServiceProvider;
7
use Spatie\EventProjector\Console\ReplayEventsCommand;
8
9
class EventProjectorServiceProvider extends ServiceProvider
10
{
11
    public function boot()
12
    {
13
        if ($this->app->runningInConsole()) {
14
            $this->publishes([
15
                __DIR__.'/../config/event-projector.php' => config_path('event-projector.php'),
16
            ], 'config');
17
        }
18
19
        if (! class_exists('CreateStoredEventsTable')) {
20
            $this->publishes([
21
                __DIR__.'/../database/migrations/create_stored_events_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_stored_events_table.php'),
22
            ], 'migrations');
23
        }
24
25
        $this->app->bind('command.event-projector:replay-events', ReplayEventsCommand::class);
26
27
        $this->commands([
28
            'command.event-projector:replay-events',
29
        ]);
30
31
        $this->app->singleton(EventProjectionist::class, function () {
32
            return new EventProjectionist();
33
        });
34
35
        $this->app->alias(EventProjectionist::class, 'event-projector');
36
    }
37
38
    public function register()
39
    {
40
        $this->mergeConfigFrom(__DIR__.'/../config/event-projector.php', 'event-projector');
41
42
        Event::subscribe(EventSubscriber::class);
43
    }
44
}
45