1 | <?php |
||
8 | abstract class AggregateRoot |
||
9 | { |
||
10 | /** @var string */ |
||
11 | private $aggregateUuid; |
||
12 | |||
13 | /** @var array */ |
||
14 | private $recordedEvents = []; |
||
15 | |||
16 | public static function retrieve(string $uuid, int $storedEventId = null): AggregateRoot |
||
17 | { |
||
18 | $aggregateRoot = (new static()); |
||
19 | |||
20 | $aggregateRoot->aggregateUuid = $uuid; |
||
21 | |||
22 | return $aggregateRoot->reconstituteFromEvents($storedEventId); |
||
23 | } |
||
24 | |||
25 | public function recordThat(ShouldBeStored $domainEvent): AggregateRoot |
||
33 | |||
34 | public function persist(): AggregateRoot |
||
44 | |||
45 | protected function getStoredEventModel(): string |
||
49 | |||
50 | private function getAndClearRecordedEvents(): array |
||
58 | |||
59 | private function reconstituteFromEvents(int $storedEventId = null): AggregateRoot |
||
69 | |||
70 | private function apply(ShouldBeStored $event): void |
||
82 | } |
||
83 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: