/** * Save a Chapter event to the chapter history. * * @param Message $domainMessage * @throws \Prooph\Done\Shared\Exception\StoryName * @throws \Exception */ public function logChapterEvent(Message $domainMessage) { $storyName = Metadata::getStoryNameFromMessage($domainMessage); if (!isset($this->storyTellers[$storyName->toString()])) { throw Exception\StoryName::isNotLinkedWithStoryTeller($storyName); } $storyTeller = $this->storyTellers[$storyName->toString()]; try { $this->eventStore->beginTransaction(); $storyTeller($domainMessage); $this->eventStore->commit(); } catch (\Exception $ex) { $this->eventStore->rollback(); throw $ex; } }
/** * @param Message $message * @param Shared\StoryId $storyId * @throws Exception\Story * @return ChapterNumber */ private function assertAndGetChapterNumberFromMessage(Message $message, StoryId $storyId) { $chapterNumber = Metadata::getChapterNumberFromMessage($message); if (!$storyId->equals($chapterNumber->storyId())) { throw Exception\Story::receivedMessageForDifferentStory($message, $storyId, $chapterNumber->storyId()); } return $chapterNumber; }