Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }