/**
  * {@inheritdoc}
  */
 public function persist(Snapshot $snapshot, Version $applicationVersion)
 {
     $applicationKey = $this->getApplicationKey($applicationVersion);
     if (!$this->store->containsKey($applicationKey)) {
         $this->store->set($applicationKey, new ArrayHashMap());
     }
     /** @var ArrayHashMap $applicationCollection */
     $applicationCollection = $this->store->get($applicationKey);
     $aggregateKey = $this->getAggregateKey($snapshot->aggregateType(), $snapshot->version());
     if (!$applicationCollection->containsKey($aggregateKey)) {
         $applicationCollection->set($aggregateKey, new ArrayHashMap());
     }
     /** @var ArrayHashMap $aggregateCollection */
     $aggregateCollection = $applicationCollection->get($aggregateKey);
     $aggregateCollection->set($snapshot->aggregateId()->toNative(), $snapshot);
 }
Example #2
0
 /**
  * Test Version method.
  */
 public function testVersion()
 {
     $this->given($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($version = new Version(0, 5, 345))->and($post->setVersion($version))->and($snapshot = new Snapshot('posts', $post, new \DateTime()))->then()->object($snapshot->version())->isEqualTo($post->version());
 }
 /**
  * @param Snapshot $snapshot
  *
  * @return EventSourcedAggregateRootInterface
  */
 protected function snapshotToAggregateRoot(Snapshot $snapshot)
 {
     $applicationVersion = VersionManager::currentApplicationVersion();
     $history = $this->eventStore->load($this->streamName(), $snapshot->aggregateId(), $snapshot->version(), $applicationVersion);
     $aggregateRoot = $snapshot->aggregate();
     $aggregateRoot->setVersion($snapshot->version());
     $aggregateRoot->replay($history);
     return $aggregateRoot;
 }