Esempio n. 1
0
 /**
  * Should a snapshot be created?
  *
  * @param AggregateRoot $root
  * @return bool
  */
 public function shouldCreateSnapshot(AggregateRoot $root)
 {
     if ($root->hasChanges()) {
         $lastSnapshot = $this->store->get($root->getIdentity());
         $threshold = new \DateTime(date('c', strtotime('-' . $this->threshold)));
         if ($lastSnapshot->getCreationDate() > $threshold) {
             return true;
         }
     }
     return false;
 }
 /**
  * Load a aggregate snapshot from the storage
  *
  * @param \Domain\Identity\Identity $id
  * @return Snapshot
  * @throws \Exception when no snapshotStore was attached
  */
 public function loadSnapshot(Identity $id)
 {
     if (is_null($this->snapshotStore)) {
         throw new \Exception('Unable to get snapshot; No store attached');
     }
     return $this->snapshotStore->get($id);
 }