/**
  * {@inheritdoc}
  */
 public function handle(EventMessageInterface $event)
 {
     $inspector = new MethodMessageHandlerInspector($this->annotationReaderFactory, new \ReflectionClass($this->annotatedEventListener), EventHandler::class);
     foreach ($inspector->getHandlerDefinitions() as $handlerDefinition) {
         if ($handlerDefinition->getPayloadType() === $event->getPayloadType()) {
             $listener = new AnnotatedEventListener($handlerDefinition->getPayloadType(), $handlerDefinition->getMethod()->name, $this->annotatedEventListener);
             $listener->handle($event);
         }
     }
 }
 public function getMessageHandlers(EventMessageInterface $event)
 {
     $found = array();
     $reflectionClass = ReflectionUtils::getClass($this->targetSaga);
     foreach (ReflectionUtils::getMethods($reflectionClass) as $method) {
         $annot = $this->reader->getMethodAnnotation($method, SagaEventHandler::class);
         if (null === $annot) {
             continue;
         }
         if (0 === count($method->getParameters())) {
             throw new \RuntimeException(sprintf("Invalid method signature detected of %s::%s. " . "Methods annotated with @SagaEventHandler must have exatly one parameter with the type of the message they handle. ", $reflectionClass->name, $method->name));
         }
         $parameter = current($method->getParameters());
         if (null !== $parameter->getClass() && $parameter->getClass()->name === $event->getPayloadType()) {
             $found[] = SagaMethodMessageHandler::getInstance($event, $method, $annot);
         }
     }
     return $found;
 }
 public static function getInstance(EventMessageInterface $event, \ReflectionMethod $handlerMethod)
 {
     $reader = new AnnotationReader();
     $handlerAnnotation = $reader->getMethodAnnotation($handlerMethod, SagaEventHandler::class);
     $associationProperty = PropertyAccessStrategy::getProperty($event->getPayload(), $handlerAnnotation->associationProperty);
     if (null === $associationProperty) {
         throw new \RuntimeException(sprintf("SagaEventHandler %s::%s defines a property %s that is not " . "defined on the Event it declares to handle (%s)", $handlerMethod->class, $handlerMethod->name, $handlerAnnotation->associationProperty, $event->getPayloadType()));
     }
     $associationKey = empty($handlerAnnotation->keyName) ? $handlerAnnotation->associationProperty : $handlerAnnotation->keyName;
     $startAnnotation = $reader->getMethodAnnotation($handlerMethod, StartSaga::class);
     if (null === $startAnnotation) {
         $sagaCreationPolicy = SagaCreationPolicy::NONE;
     } else {
         if ($startAnnotation->forceNew) {
             $sagaCreationPolicy = SagaCreationPolicy::ALWAYS;
         } else {
             $sagaCreationPolicy = SagaCreationPolicy::IF_NONE_FOUND;
         }
     }
     return new SagaMethodMessageHandler($sagaCreationPolicy, $associationKey, $associationProperty, $handlerMethod, $reader);
 }
 public function resolveRoutingKey(EventMessageInterface $eventMessage)
 {
     $reflClass = new \ReflectionClass($eventMessage->getPayloadType());
     return strtr($reflClass->getName(), '\\', '.');
 }
 protected function verifyEventMessage(EventMessageInterface $message)
 {
     if ($message->getPayloadType() !== $this->eventName) {
         throw new \BadMethodCallException(sprintf("Invalid event in listener %s, expected %s but got %s", get_class($this), $this->eventName, $message->getPayloadType()));
     }
 }
 private function handleInvokationException(\Exception $ex, EventMessageInterface $event, SagaInterface $saga)
 {
     if ($this->suppressExceptions) {
         $this->logger->error("An exception occurred while a Saga {name} was handling an Event {event}: {exception}", ['name' => get_class($saga), 'event' => $event->getPayloadType(), 'exception' => $ex->getMessage()]);
     } else {
         throw $ex;
     }
 }