private function getRouteAsMiddleware(ResultInterface $result): MiddlewareInterface
    {
        $callback = $result->getRoute()->getCallback();

        // resolve the callback
        if (is_string($callback)) {
            // resolve using the container
            $callback = ($this->container ? $this->container->get($callback) : null);
        }

        if (is_array($callback) && count($callback) === 2) {
            // resolve the [class, method] call
            list($class, $method) = $callback;
            $callback = ($this->container ? function ($request, $response) use ($class, $method) {
                $class = $this->container->get($class);
                return $class->$method($request, $response);
            } : null);
        }

        if ($callback instanceof MiddlewareInterface) {
            // return the middleware
            return $callback;
        }

        if (is_callable($callback)) {
            return new Route($callback);
        }

        throw new CannotExecuteRouteException('Dispatch doesn\'t know how to handle the callback');
    }