예제 #1
0
 /**
  * @param IncomingLogicalMessageContext $context
  * @param callable                      $next
  */
 public function invoke($context, callable $next)
 {
     $messageTypes = $context->getMessage()->getMessageTypes();
     $handlerIdsToInvoke = $this->messageHandlerRegistry->getHandlerIdsFor($messageTypes);
     if (!$context->isMessageHandled() && !count($handlerIdsToInvoke)) {
         $messageTypes = implode(',', $messageTypes);
         throw new UnexpectedValueException("No message handlers could be found for message types '{$messageTypes}'.");
     }
     foreach ($handlerIdsToInvoke as $handlerId) {
         /** @var MessageHandlerInterface $handler */
         $handler = $context->getBuilder()->build($handlerId);
         $handlingContext = $this->incomingContextFactory->createInvokeHandlerContext($handler, $context);
         $next($handlingContext);
         if ($handlingContext->isHandlerInvocationAborted()) {
             //if the chain was aborted skip the other handlers
             break;
         }
     }
     $context->markMessageAsHandled();
 }
예제 #2
0
 /**
  * @param string $commandFqcn
  * @param string $handlerContainerId
  */
 public function registerCommandHandler($commandFqcn, $handlerContainerId)
 {
     $this->messageHandlerRegistry->registerCommandHandler($commandFqcn, $handlerContainerId);
 }