示例#1
0
文件: Story.php 项目: bweston92/done
 /**
  * @param StoryName $storyName
  * @param Message $startMessage
  * @param ChapterTemplate[] $chapterTemplates
  * @param MessageConverter $messageConverter
  * @throws Exception\Story
  * @return Story
  */
 public static function start(StoryName $storyName, Message $startMessage, array $chapterTemplates, MessageConverter $messageConverter)
 {
     self::assertChapterTemplates($chapterTemplates, $storyName);
     $storyId = StoryId::fromString($startMessage->uuid()->toString());
     $self = new self();
     $self->recordThat(StoryWasStarted::withStoryIdAndName($storyId, $storyName));
     $nextCommands = $self->startNextChapters($storyName, $startMessage, $chapterTemplates, $storyId, $messageConverter);
     if (empty($nextCommands)) {
         throw Exception\Story::cannotBeStartedForMessage($startMessage);
     }
     $self->nextCommands = $nextCommands;
     return $self;
 }
 /**
  * Resolves the deferred for a given message.
  * If an error occurs, the deferred is rejected and a reason will be given.
  *
  * If a message is parallel message (instance of \Prooph\ServiceBus\Message\HumusAmqp\ParallelMessage)
  * and instance of \Humus\Amqp\JsonRpc\JsonRpcResponseCollection, which can be queried for given
  * message ids.
  *
  * @param Message $message
  * @param Deferred|null $deferred
  * @throws RuntimeException If a $deferred is not passed
  * @return void
  */
 public function __invoke(Message $message, Deferred $deferred = null)
 {
     if (null === $deferred) {
         throw new RuntimeException('Deferred expected, null given');
     }
     if ($message instanceof ParallelMessage) {
         foreach ($message->messages() as $parallelMessage) {
             $data = $this->arrayFromMessage($parallelMessage);
             $this->client->addRequest(new JsonRpcRequest('server', $message->messageName(), $data, $message->uuid()->toString(), $message->messageName(), 0, $message->createdAt()->getTimestamp()));
         }
     } else {
         $data = $this->arrayFromMessage($message);
         $messageId = $message->uuid()->toString();
         $this->client->addRequest(new JsonRpcRequest('server', $message->messageName(), $data, $messageId, $message->messageName(), 0, $message->createdAt()->getTimestamp()));
         $results = $this->client->getResponseCollection($this->timeout);
         if ($results instanceof Error) {
             $deferred->reject($results->message());
         }
         $response = $results->getResponse($messageId);
         $deferred->resolve($response->result());
     }
     $deferred->resolve($this->client->getResponseCollection($this->timeout));
 }
示例#3
0
文件: Story.php 项目: bweston92/done
 /**
  * @param Message $message
  * @param StoryId $ownStoryId
  * @param StoryId $otherStoryId
  * @return Story
  */
 public static function receivedMessageForDifferentStory(Message $message, StoryId $ownStoryId, StoryId $otherStoryId)
 {
     return new self(sprintf('Story %s received message %s (%s) for different story %s', $ownStoryId->toString(), $message->messageName(), $message->uuid()->toString(), $otherStoryId->toString()));
 }