Connector/ServiceBus/QueryHandlerMiddleware/QueryHandlerMiddleware.php
public function execute($query, callable $next)
    {
        if (null === $this->handlers) {
            return $next($query);
        }

        if (!($query instanceof QueryInterface)) {
            return $next($query);
        }

        $handlers = array_filter($this->handlers, function (QueryHandlerInterface $handler) use ($query) {
            return $handler->supports($query);
        });

        if (0 === count($handlers)) {
            throw NotFoundException::fromQuery($query);
        }

        /**
         * @var QueryHandlerInterface $handler
         */
        $handler = array_shift($handlers);
        $response = $handler->handle($query);

        if (null !== $response) {
            return $response;
        }

        return $next($query);
    }
public function execute($query, callable $next)
    {
        if (null === $this->handlers) {
            return $next($query);
        }

        if (!($query instanceof QueryInterface)) {
            return $next($query);
        }

        $handlers = array_filter($this->handlers, function (QueryHandlerInterface $handler) use ($query) {
            return $handler->supports($query);
        });

        if (0 === count($handlers)) {
            throw NotFoundException::fromQuery($query);
        }

        /**
         * @var QueryHandlerInterface $handler
         */
        $handler = array_shift($handlers);
        $response = $handler->handle($query);

        if (null !== $response) {
            return $response;
        }

        return $next($query);
    }
@param QueryInterface $query
@param callable       $next

@return mixed