/** * {@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 function resolveRoutingKey(EventMessageInterface $eventMessage) { $reflClass = new \ReflectionClass($eventMessage->getPayloadType()); return strtr($reflClass->getName(), '\\', '.'); }
/** * The AssociationValue to find the saga instance with, or <code>null</code> if no AssociationValue can be found on * the given <code>eventMessage</code>. * * @param EventMessageInterface $eventMessage The event message containing the value of the association * @return AssociationValue The AssociationValue to find the saga instance with, or <code>null</code> if none found */ public function getAssociationValue(EventMessageInterface $eventMessage) { if (null === $this->associationProperty) { return null; } $associationValue = $this->associationProperty->getValue($eventMessage->getPayload()); return null === $associationValue ? null : new AssociationValue($this->associationKey, $associationValue); }
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; } }
public function handle(EventMessageInterface $event) { print_r($event->getPayload()); }