/** * Takes a snapshot * @param StreamName $streamName * @param AggregateRootInterface $aggregate * @param DomainMessage $message - The domain message * @return bool */ public function take(StreamName $streamName, AggregateRootInterface $aggregate, DomainMessage $message) { $id = $aggregate->getAggregateRootId(); if (!$this->strategy->isFulfilled($streamName, $aggregate)) { return false; } if (!$this->snapshotStore->has($id, $message->getVersion())) { $this->snapshotStore->save(Snapshot::take($id, $aggregate, $message->getVersion())); } return true; }
private function createEventData(DomainMessage $event) { return ['aggregate_id' => (string) $event->getId(), 'version' => $event->getVersion(), 'type' => $event->getType(), 'payload' => $this->serializer->serialize($event->getPayload(), 'json'), 'recorded_on' => $event->getRecordedOn()->format('Y-m-d\\TH:i:s.u')]; }