示例#1
0
 public function save(AggregateRoot $root)
 {
     $aggregateId = (string) $root->getIdentity();
     $versionFile = $aggregateId . '-' . $root->getVersion();
     if (file_exists($this->dataPath . '/' . $versionFile)) {
         throw new IdenticalSnapshot();
     }
     $stream = fopen($this->dataPath . '/' . $versionFile, 'w');
     fwrite($stream, serialize($root));
     fclose($stream);
 }
示例#2
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;
 }
示例#3
0
 public function save(AggregateRoot $root)
 {
     return $this->mongo->aggregate_snapshots->insert(['identity' => (string) $root->getIdentity(), 'aggregate' => serialize($root), 'version' => $root->getVersion(), 'creation_date' => new \MongoDate()]);
 }
 /**
  * Save given snapshot
  *
  * @param AggregateRoot $root
  */
 public function save(AggregateRoot $root)
 {
     $snapshot = new Snapshot($root, $root->getVersion(), new \DateTime());
     $this->snapshots[(string) $root->getIdentity()][] = $snapshot;
 }