1 | <?php |
||
11 | trait ReplaysEvents |
||
12 | { |
||
13 | public function replay(Collection $projectors) |
||
14 | { |
||
15 | $afterEventId = $this->determineAfterEventId($projectors); |
||
16 | |||
17 | if ($afterEventId === StoredEvent::getMaxId()) { |
||
18 | $this->warn('There are no events to replay.'); |
||
|
|||
19 | } |
||
20 | |||
21 | $replayCount = StoredEvent::after($afterEventId)->count(); |
||
22 | |||
23 | if ($replayCount === 0) { |
||
24 | $this->warn('There are no events to replay'); |
||
25 | |||
26 | return; |
||
27 | } |
||
28 | |||
29 | $afterEventId === 0 |
||
30 | ? $this->comment('Replaying all events...') |
||
31 | : $this->comment("Replaying events after stored event id {$afterEventId}..."); |
||
32 | $this->emptyLine(); |
||
33 | |||
34 | $bar = $this->output->createProgressBar(StoredEvent::after($afterEventId)->count()); |
||
35 | $onEventReplayed = function () use ($bar) { |
||
36 | $bar->advance(); |
||
37 | }; |
||
38 | |||
39 | $this->Projectionist->replay($projectors, $afterEventId, $onEventReplayed); |
||
40 | |||
41 | $bar->finish(); |
||
42 | |||
43 | $this->emptyLine(2); |
||
44 | $this->comment('All done!'); |
||
45 | } |
||
46 | |||
47 | protected function determineAfterEventId(Collection $projectors): int |
||
78 | |||
79 | protected function emptyLine(int $amount = 1) |
||
85 | } |
||
86 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.