/** * @param TakeSnapshot $command * @throws Exception\RuntimeException */ public function __invoke(TakeSnapshot $command) { $aggregateType = $command->aggregateType(); if (!isset($this->aggregateRepositories[$aggregateType])) { throw new Exception\RuntimeException(sprintf('No repository for aggregate type %s configured', $command->aggregateType())); } $repository = $this->aggregateRepositories[$aggregateType]; $aggregateRoot = $repository->getAggregateRoot($command->aggregateId()); if (null === $aggregateRoot) { throw new RuntimeException(sprintf('Could not find aggregate root %s with id %s', $aggregateType, $command->aggregateId())); } $this->snapshotStore->save(new Snapshot(AggregateType::fromAggregateRootClass($aggregateType), $command->aggregateId(), $aggregateRoot, $repository->extractAggregateVersion($aggregateRoot), $command->createdAt())); }
/** * @param TakeSnapshot $command */ public function __invoke(TakeSnapshot $command) { $repository = $this->aggregateRepositories[$command->aggregateType()]; $aggregateRoot = $repository->getAggregateRoot($command->aggregateId()); $this->snapshotAdapter->add(new Snapshot(AggregateType::fromAggregateRootClass($command->aggregateType()), $command->aggregateId(), $aggregateRoot, $command->version(), $command->createdAt())); }