示例#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
 public function shouldCreateSnapshot(AggregateRoot $root)
 {
     if ($root->hasChanges()) {
         $lastEvent = $root->getChanges()[count($root->getChanges()) - 1];
         $lastVersion = $lastEvent->getVersion();
         for ($i = $root->getVersion(); $i <= $lastVersion; $i++) {
             if ($i % $this->interval == 0) {
                 return true;
             }
         }
     }
     return false;
 }
 /**
  * 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;
 }