1 | <?php |
||
18 | abstract class BaseAggregateRepository implements AggregateRepository |
||
19 | { |
||
20 | /** |
||
21 | * @var EventStore |
||
22 | */ |
||
23 | private $eventStore; |
||
24 | |||
25 | /** |
||
26 | * @var EventBus |
||
27 | */ |
||
28 | private $eventBus; |
||
29 | |||
30 | /** |
||
31 | * @var SnapshotStore |
||
32 | */ |
||
33 | private $snapshotStore; |
||
34 | |||
35 | /** |
||
36 | * @var SnapshottingPolicy |
||
37 | */ |
||
38 | private $snapshottingPolicy; |
||
39 | |||
40 | /** |
||
41 | * @param EventStore $eventStore |
||
42 | * @param EventBus $eventBus |
||
43 | * @param SnapshotStore $snapshotStore |
||
44 | * @param SnapshottingPolicy $policy |
||
45 | */ |
||
46 | public function __construct( |
||
63 | |||
64 | /** |
||
65 | * To store the updates made to an Aggregate, we only need to |
||
66 | * commit the latest recorded events to the EventStore. |
||
67 | * |
||
68 | * An eventbus can handle eventual or direct consistency. |
||
69 | * |
||
70 | * Snapsnots could be made if the policy allows it and this repo is |
||
71 | * constructed with a storage for storing snapshots. |
||
72 | * |
||
73 | * @param AggregateRoot $aggregate |
||
74 | * @return CommittedEvents |
||
75 | */ |
||
76 | public function save(AggregateRoot $aggregate) |
||
96 | |||
97 | /** |
||
98 | * Fetching a single Aggregate is extremely easy: all we need to do is |
||
99 | * reconstitute it from its history! Compare that to the complexity |
||
100 | * of traditional ORMs. |
||
101 | * |
||
102 | * @param Identity $aggregateId |
||
103 | * @return AggregateRoot |
||
104 | */ |
||
105 | public function get(Identity $aggregateId) |
||
124 | |||
125 | /** |
||
126 | * Concrete repositories should define the Aggregate's FQCN |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | abstract protected function getAggregateRootFqcn(); |
||
131 | |||
132 | /** |
||
133 | * Load a aggregate snapshot from the storage |
||
134 | * |
||
135 | * @param \Domain\Identity\Identity $id |
||
136 | * @return Snapshot |
||
137 | * @throws \Exception when no snapshotStore was attached |
||
138 | */ |
||
139 | public function loadSnapshot(Identity $id) |
||
147 | |||
148 | /** |
||
149 | * Save the aggregate state as single snapshot instead of multiple history events |
||
150 | * |
||
151 | * @param \Domain\Aggregates\AggregateRoot $aggregate |
||
152 | * @return type |
||
153 | * @throws \Exception when no snapshotStore was attached |
||
154 | */ |
||
155 | public function saveSnapshot(AggregateRoot $aggregate) |
||
172 | } |
||
173 |