1 | <?php |
||
8 | class EventProjectionist |
||
9 | { |
||
10 | /** @var \Illuminate\Support\Collection */ |
||
11 | public $projectors; |
||
12 | |||
13 | /** @var \Illuminate\Support\Collection */ |
||
14 | public $reactors; |
||
15 | |||
16 | public function __construct() |
||
22 | |||
23 | public function addProjector(string $projector): self |
||
24 | { |
||
25 | if (! class_exists($projector)) { |
||
26 | throw InvalidEventHandler::doesNotExist($projector); |
||
27 | } |
||
28 | |||
29 | $this->projectors->push($projector); |
||
30 | |||
31 | return $this; |
||
32 | } |
||
33 | |||
34 | public function registerProjectors(array $projectors): self |
||
35 | { |
||
36 | collect($projectors)->each(function ($projector) { |
||
37 | $this->addProjector($projector); |
||
38 | }); |
||
39 | |||
40 | return $this; |
||
41 | } |
||
42 | |||
43 | public function addReactor(string $reactor): self |
||
53 | |||
54 | public function registerReactors(array $reactors): self |
||
62 | |||
63 | public function callEventHandlers(Collection $eventHandlers, ShouldBeStored $event): self |
||
75 | |||
76 | protected function callEventHandler(object $eventHandler, ShouldBeStored $event) |
||
92 | } |
||
93 |