/**
* @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()));
}