1 | <?php |
||
26 | abstract class AbstractAggregateRoot implements AggregateRoot |
||
27 | { |
||
28 | use AggregateBehaviour, EventBehaviour; |
||
29 | |||
30 | /** |
||
31 | * @var AggregateEvent[] |
||
32 | */ |
||
33 | private $recordedAggregateEvents = []; |
||
34 | |||
35 | /** |
||
36 | * Prevent aggregate root direct instantiation. |
||
37 | */ |
||
38 | final protected function __construct() |
||
42 | |||
43 | /** |
||
44 | * Set aggregate identity. |
||
45 | * |
||
46 | * @param Identity $identity |
||
47 | */ |
||
48 | final protected function setIdentity(Identity $identity): void |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | final public static function reconstituteFromAggregateEvents(AggregateEventCollection $events): self |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | * |
||
67 | * @throws AggregateException |
||
68 | */ |
||
69 | final public function replayAggregateEvents(AggregateEventCollection $events): void |
||
77 | |||
78 | /** |
||
79 | * Record aggregate event. |
||
80 | * |
||
81 | * @param AggregateEvent $event |
||
82 | * |
||
83 | * @throws AggregateException |
||
84 | */ |
||
85 | final protected function recordAggregateEvent(AggregateEvent $event): void |
||
93 | |||
94 | /** |
||
95 | * Apply aggregate event. |
||
96 | * |
||
97 | * @param AggregateEvent $event |
||
98 | * |
||
99 | * @throws AggregateException |
||
100 | */ |
||
101 | final protected function applyAggregateEvent(AggregateEvent $event): void |
||
115 | |||
116 | /** |
||
117 | * Get event apply method name. |
||
118 | * |
||
119 | * @param AggregateEvent $event |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function getAggregateEventApplyMethodName(AggregateEvent $event): string |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | final public function getRecordedAggregateEvents(): AggregateEventCollection |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | final public function clearRecordedAggregateEvents(): void |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | final public function collectRecordedAggregateEvents(): AggregateEventCollection |
||
159 | } |
||
160 |