示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function migrateAggregateRoot($aggregateClassName, EventStream $eventStream, Version $aggregateVersion, Version $applicationVersion)
 {
     parent::migrateAggregateRoot($aggregateClassName, $eventStream, $aggregateVersion, $applicationVersion);
     // reconstruct the new aggregate root
     $aggregateRoot = call_user_func(array($aggregateClassName, 'loadFromHistory'), $eventStream);
     // create the snapshot
     $snapshot = new Snapshot($this->streamName($aggregateClassName), $aggregateRoot, new \DateTime());
     // pserist the new snapshot
     $this->snapshotStore->persist($snapshot, $applicationVersion);
 }
 /**
  * Load a aggregate snapshot from the storage.
  *
  * @param IdInterface $id
  *
  * @return Snapshot
  */
 protected function loadSnapshot(IdInterface $id)
 {
     $applicationVersion = VersionManager::currentApplicationVersion();
     $aggregateVersion = VersionManager::versionOfClass($this->aggregateClassName, $applicationVersion);
     return $this->snapshotStore->load($this->streamName(), $id, $aggregateVersion, $applicationVersion);
 }
 /**
  * Save the aggregate snapshot.
  *
  * @param EventSourcedAggregateRootInterface $aggregateRoot
  */
 protected function saveSnapshot(EventSourcedAggregateRootInterface $aggregateRoot)
 {
     $applicationVersion = VersionManager::currentApplicationVersion();
     $snapshot = new Snapshot($this->streamName(), $aggregateRoot, new \DateTime());
     $this->snapshotStore->persist($snapshot, $applicationVersion);
 }