Total Complexity | 4 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | trait SnapshottingBehaviour |
||
12 | { |
||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | private $aggregateRootVersion = 0; |
||
17 | |||
18 | abstract public function aggregateRootVersion(): int; |
||
19 | |||
20 | abstract public function aggregateRootId(): AggregateRootId; |
||
21 | |||
22 | abstract protected function apply(object $event): void; |
||
23 | |||
24 | 1 | public function createSnapshot(): Snapshot |
|
25 | { |
||
26 | 1 | return new Snapshot($this->aggregateRootId(), $this->aggregateRootVersion(), $this->createSnapshotState()); |
|
27 | } |
||
28 | |||
29 | abstract protected function createSnapshotState(); |
||
30 | |||
31 | /** |
||
32 | * @param Snapshot $snapshot |
||
33 | * @param Generator $events |
||
34 | * |
||
35 | * @return static |
||
36 | */ |
||
37 | 1 | public static function reconstituteFromSnapshotAndEvents(Snapshot $snapshot, Generator $events): AggregateRoot |
|
51 | } |
||
52 | |||
53 | abstract protected static function reconstituteFromSnapshotState(AggregateRootId $id, $state): AggregateRootWithSnapshotting; |
||
54 | } |
||
55 |