Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function isFulfilled(StreamName $streamName, AggregateRootInterface $aggregate)
 {
     $countOfEvents = $this->eventStore->countEventsFor($streamName, $aggregate->getAggregateRootId());
     return $countOfEvents && $countOfEvents % $this->count === 0;
 }