/**
  * Subscribe the given <code>handler</code> to commands of type <code>commandType</code> to the local segment of the
  * command bus.
  * <p/>
  * If a subscription already exists for the given type, the behavior is undefined. Implementations may throw an
  * Exception to refuse duplicate subscription or alternatively decide whether the existing or new
  * <code>handler</code> gets the subscription.
  *
  * @param string $commandName The name of the command to subscribe the handler to
  * @param CommandHandlerInterface $handler The handler instance that handles the given type of command
  */
 public function subscribe($commandName, CommandHandlerInterface $handler)
 {
     $this->localSegment->subscribe($commandName, $handler);
 }
 /**
  * @param string $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->subscribe($handlerDefinition->getPayloadType(), $handler);
     }
 }