Beispiel #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);
     }
 }