/** * @param DomainEventInterface $event * * @throws \InvalidArgumentException */ protected function addEvent(DomainEventInterface $event) { if (!$event->aggregateId()->equals($this->aggregateId)) { throw new \InvalidArgumentException(sprintf('Event-stream can only contain events for identifier %s, but got %s', $this->aggregateId->toNative(), $event->aggregateId()->toNative())); } $this->events[] = $event; }
/** * {@inheritdoc} */ public function remove($aggregateType, IdInterface $aggregateId, Version $aggregateVersion, Version $applicationVersion) { $applicationKey = $this->getApplicationKey($applicationVersion); if (!$this->store->containsKey($applicationKey)) { return; } /** @var ArrayHashMap $applicationCollection */ $applicationCollection = $this->store->get($applicationKey); $aggregateKey = $this->getAggregateKey($aggregateType, $aggregateVersion); if (!$applicationCollection->containsKey($aggregateKey)) { return; } /** @var ArrayHashMap $aggregateCollection */ $aggregateCollection = $applicationCollection->get($aggregateKey); $aggregateCollection->removeAt($aggregateId->toNative()); }
/** * {@inheritdoc} */ public function remove($streamName, IdInterface $aggregateId, Version $aggregateVersion, Version $applicationVersion) { $applicationKey = $this->getApplicationKey($applicationVersion); if (!$this->store->containsKey($applicationKey)) { throw new \RuntimeException(sprintf('The application %s not found in the event store.', $applicationKey)); } /** @var ArrayHashMap $applicationCollection */ $applicationCollection = $this->store->get($applicationKey); $streamKey = $this->getStreamKey($streamName, $aggregateVersion); if (!$applicationCollection->containsKey($streamKey)) { throw new \RuntimeException(sprintf('The stream name %s of application %s not found in the event store.', $streamKey, $applicationKey)); } /** @var ArrayHashMap $streamCollection */ $streamCollection = $applicationCollection->get($streamKey); $streamCollection->removeAt($aggregateId->toNative()); }
/** * {@inheritdoc} */ public function get(IdInterface $id) { return $this->repository->find($id->toNative()); }