1 | <?php |
||
13 | trait AggregateRootTrait |
||
14 | { |
||
15 | /** @var AggregateIdInterface */ |
||
16 | private $identifier; |
||
17 | |||
18 | /** @var AggregateRevision */ |
||
19 | private $revision; |
||
20 | |||
21 | /** @var DomainEventSequence */ |
||
22 | private $trackedEvents; |
||
23 | |||
24 | 3 | public static function reconstituteFromHistory( |
|
25 | AggregateIdInterface $aggregateId, |
||
26 | DomainEventSequence $history |
||
27 | ): AggregateRootInterface { |
||
28 | 3 | $aggRoot = new static($aggregateId); |
|
29 | 3 | foreach ($history as $eventOccured) { |
|
30 | 3 | $aggRoot = $aggRoot->reflectThat($eventOccured, false); |
|
31 | } |
||
32 | 1 | return $aggRoot; |
|
33 | } |
||
34 | |||
35 | 6 | public function getIdentifier(): AggregateIdInterface |
|
39 | |||
40 | 3 | public function getRevision(): AggregateRevision |
|
44 | |||
45 | 2 | public function getTrackedEvents(): DomainEventSequence |
|
49 | |||
50 | public function markClean(): AggregateRootInterface |
||
56 | |||
57 | 6 | protected function __construct(AggregateIdInterface $aggregateId) |
|
63 | |||
64 | 6 | protected function reflectThat(DomainEventInterface $eventOccured, bool $track = true): self |
|
81 | |||
82 | 4 | private function invokeEventHandler(DomainEventInterface $event): void |
|
92 | |||
93 | 2 | private function assertExpectedRevision(DomainEventInterface $event, AggregateRevision $expectedRevision): void |
|
103 | |||
104 | 6 | private function assertExpectedIdentifier(DomainEventInterface $event, AggregateIdInterface $expectedId): void |
|
114 | } |
||
115 |