1 | <?php |
||
28 | abstract class Projector implements DomainEventSubscriberInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var QueryRepositoryInterface |
||
32 | */ |
||
33 | protected $repository; |
||
34 | |||
35 | /** |
||
36 | * @var EventStoreInterface |
||
37 | */ |
||
38 | protected $eventStore; |
||
39 | |||
40 | /** |
||
41 | * Projector constructor. |
||
42 | * |
||
43 | * @param QueryRepositoryInterface $repository |
||
44 | * @param EventStoreInterface $eventStore |
||
45 | */ |
||
46 | public function __construct(QueryRepositoryInterface $repository, EventStoreInterface $eventStore) |
||
51 | |||
52 | /** |
||
53 | * @param PostPersistEvent $event |
||
54 | */ |
||
55 | public function onPostPersist(PostPersistEvent $event) |
||
90 | |||
91 | /** |
||
92 | * @param EventStream $eventStream |
||
93 | * @param ReadModelInterface $readModel |
||
94 | */ |
||
95 | protected function projectAndPersistEvents(EventStream $eventStream, ReadModelInterface $readModel = null) |
||
103 | |||
104 | /** |
||
105 | * Projects all the events into the read model. |
||
106 | * |
||
107 | * @param EventStream $eventStream |
||
108 | * @param ReadModelInterface $readModel |
||
109 | * |
||
110 | * @return ReadModelInterface|null |
||
111 | */ |
||
112 | protected function projectEventStream(EventStream $eventStream, ReadModelInterface $readModel = null) |
||
128 | |||
129 | /** |
||
130 | * @param ReadModelInterface $readModel |
||
131 | */ |
||
132 | protected function persist(ReadModelInterface $readModel) |
||
136 | |||
137 | /** |
||
138 | * @param ReadModelInterface $readModel |
||
139 | */ |
||
140 | protected function remove(ReadModelInterface $readModel) |
||
144 | |||
145 | /** |
||
146 | * Load a aggregate history from the storage. |
||
147 | * |
||
148 | * @param IdInterface $id |
||
149 | * @param string $streamName |
||
150 | * @param string $aggregateClassName |
||
151 | * |
||
152 | * @return EventStream |
||
153 | */ |
||
154 | protected function loadHistory(IdInterface $id, $streamName, $aggregateClassName) |
||
161 | |||
162 | /** |
||
163 | * @return string |
||
164 | */ |
||
165 | abstract protected function writeModelClass(); |
||
166 | |||
167 | /** |
||
168 | * @param EventStream $eventStream |
||
169 | * |
||
170 | * @return bool |
||
171 | */ |
||
172 | abstract protected function shouldBeProjected(EventStream $eventStream); |
||
173 | |||
174 | /** |
||
175 | * @param EventStream $eventStream |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | abstract protected function shouldBeRemoved(EventStream $eventStream); |
||
180 | |||
181 | /** |
||
182 | * {@inheritdoc} |
||
183 | */ |
||
184 | public static function getSubscribedEvents() |
||
190 | } |
||
191 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: