1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\EventProjector; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Event; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use Spatie\EventProjector\Console\MakeProjectorCommand; |
8
|
|
|
use Spatie\EventProjector\Console\MakeReactorCommand; |
9
|
|
|
use Spatie\EventProjector\Console\ReplayEventsCommand; |
10
|
|
|
|
11
|
|
|
class EventProjectorServiceProvider extends ServiceProvider |
12
|
|
|
{ |
13
|
|
|
public function boot() |
14
|
|
|
{ |
15
|
|
|
if ($this->app->runningInConsole()) { |
16
|
|
|
$this->publishes([ |
17
|
|
|
__DIR__.'/../config/event-projector.php' => config_path('event-projector.php'), |
18
|
|
|
], 'config'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if (! class_exists('CreateStoredEventsTable')) { |
22
|
|
|
$this->publishes([ |
23
|
|
|
__DIR__ . '/../stubs/create_stored_events_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_stored_events_table.php'), |
24
|
|
|
], 'migrations'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$this->app->bind('command.event-projector:replay-events', ReplayEventsCommand::class); |
28
|
|
|
$this->app->bind('command.make:projector', MakeProjectorCommand::class); |
29
|
|
|
$this->app->bind('command.make:reactor', MakeReactorCommand::class); |
30
|
|
|
|
31
|
|
|
$this->commands([ |
32
|
|
|
'command.event-projector:replay-events', |
33
|
|
|
'command.make:projector', |
34
|
|
|
'command.make:reactor', |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function register() |
39
|
|
|
{ |
40
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/event-projector.php', 'event-projector'); |
41
|
|
|
|
42
|
|
|
$this->app |
43
|
|
|
->when(EventSubscriber::class) |
44
|
|
|
->needs('$storedEventModelClass') |
45
|
|
|
->give(config('event-projector.stored_event_model')); |
46
|
|
|
|
47
|
|
|
$this->app |
48
|
|
|
->when(ReplayEventsCommand::class) |
49
|
|
|
->needs('$storedEventModelClass') |
50
|
|
|
->give(config('event-projector.stored_event_model')); |
51
|
|
|
|
52
|
|
|
Event::subscribe(EventSubscriber::class); |
53
|
|
|
|
54
|
|
|
$this->app->singleton(EventProjectionist::class, function () { |
55
|
|
|
return new EventProjectionist(); |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
$this->app->alias(EventProjectionist::class, 'event-projector'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|