/**
  * {@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 registerAnnotatedCommandHandler($annotatedCommandHandler)
 {
     $this->registerAggregateCommandHandlers();
     $this->explicitCommandHandlersSet = true;
     $reflectionClass = new \ReflectionClass($annotatedCommandHandler);
     $inspector = new MethodMessageHandlerInspector(new SimpleAnnotationReaderFactory(), $reflectionClass, CommandHandler::class);
     foreach ($inspector->getHandlerDefinitions() as $handlerDefinition) {
         $handler = new AnnotatedCommandHandler($reflectionClass->name, $handlerDefinition->getMethod()->name, $this->parameterResolver, $annotatedCommandHandler);
         $this->commandBus->subscribe($handlerDefinition->getPayloadType(), $handler);
     }
     return $this;
 }
 /**
  * @param $className
  * @param RepositoryInterface $repository
  * @param CommandBusInterface $commandBus
  * @param ParameterResolverFactoryInterface $parameterResolver
  * @param CommandTargetResolverInterface $targetResolver
  * @param AnnotationReaderFactoryInterface $annotationReaderFactory
  */
 public static function subscribe($className, RepositoryInterface $repository, CommandBusInterface $commandBus, ParameterResolverFactoryInterface $parameterResolver, CommandTargetResolverInterface $targetResolver = null, AnnotationReaderFactoryInterface $annotationReaderFactory = null)
 {
     $inspector = new MethodMessageHandlerInspector($annotationReaderFactory, new \ReflectionClass($className), CommandHandler::class);
     foreach ($inspector->getHandlerDefinitions() as $handlerDefinition) {
         $handler = new AnnotatedAggregateCommandHandler($className, $handlerDefinition->getMethod()->name, $parameterResolver, $repository, $targetResolver, $annotationReaderFactory);
         $commandBus->getCommandHandlerRegistry()->subscribe($handlerDefinition->getPayloadType(), $handler);
     }
 }