/** * {@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); }
/** * Test CreatedAt method. */ public function testCreatedAt() { $this->given($post = PostEventSourcedFactory::create($this->faker->sentence, $this->faker->paragraph))->and($createdAt = new \DateTime())->and($snapshot = new Snapshot('posts', $post, $createdAt))->then()->object($snapshot->createdAt())->isEqualTo($createdAt); }
/** * @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; }