/** * @param AggregateType $repositoryAggregateType * @param string $aggregateId * @param Message[] $streamEvents * @param object $aggregateRoot * @throws Exception\InvalidArgumentException * @return void */ public function appendEvents(AggregateType $repositoryAggregateType, $aggregateId, array $streamEvents, $aggregateRoot) { $arType = AggregateType::fromAggregateRoot($aggregateRoot); if (!$repositoryAggregateType->equals($arType)) { throw new Exception\InvalidArgumentException(sprintf('aggregate root mismatch between repository type %s and object type %s', $repositoryAggregateType->toString(), $arType->toString())); } $this->eventStore->appendTo($this->buildStreamName($repositoryAggregateType, $aggregateId), $streamEvents); }
/** * @param AggregateType $repositoryAggregateType * @param string $aggregateId * @param Message[] $streamEvents * @param object $aggregateRoot * @throws Exception\InvalidArgumentException * @return void */ public function appendEvents(AggregateType $repositoryAggregateType, $aggregateId, array $streamEvents, $aggregateRoot) { $arType = AggregateType::fromAggregateRoot($aggregateRoot); if (!$repositoryAggregateType->equals($arType)) { throw new Exception\InvalidArgumentException(sprintf('aggregate root mismatch between repository type %s and object type %s', $repositoryAggregateType->toString(), $arType->toString())); } $streamName = $this->buildStreamName($repositoryAggregateType); Assertion::string($aggregateId, 'AggregateId needs to be string'); foreach ($streamEvents as &$streamEvent) { $streamEvent = $streamEvent->withAddedMetadata('aggregate_id', $aggregateId); } $this->eventStore->appendTo($streamName, $streamEvents); }