Exemple #1
0
 /**
  * @param Message $message
  * @throws Exception\Story
  */
 public function __invoke(Message $message)
 {
     if ($this->isStartMessage($message)) {
         $story = Story::start($this->storyName, $message, $this->chapterTemplates, $this->messageConverter);
         $this->storyLog->add($story);
     } else {
         $chapterNumber = ChapterNumber::fromString($message->metadata()[Metadata::STORY_CHAPTER]);
         $story = $this->storyLog->get($chapterNumber->storyId());
         if (null === $story) {
             throw Exception\Story::withIdCannotBeFound($chapterNumber->storyId());
         }
         $story->continueWith($message, $this->chapterTemplates, $this->messageConverter, $this->messageFactory);
     }
     foreach ($story->getNextCommands() as $command) {
         $this->commandBus->delayDispatch($command);
     }
 }
Exemple #2
0
 /**
  * @param ChapterNumber $chapterNumber
  * @param MessageFactory $messageFactory
  * @return Message
  * @throws Exception\Story
  */
 private function getOriginalStartMessageForChapterNumber(ChapterNumber $chapterNumber, MessageFactory $messageFactory)
 {
     if (!isset($this->chapterNumberStartMessageMap[$chapterNumber->toString()])) {
         throw Exception\Story::hasNoStartMessageLoggedForChapterNumber($chapterNumber);
     }
     $messageData = $this->chapterNumberStartMessageMap[$chapterNumber->toString()];
     return $messageFactory->createMessageFromArray($messageData['message_name'], $messageData);
 }