private function callController($controller, CompiledRoute $route) : Response
    {
        if (is_callable($controller)) {
            try {
                $reflection = new ReflectionFunction($controller);
            } catch (\ReflectionException $e) {
                throw new RouteException("Function {$controller} does not exist");
            }
            $parameters = $this->resolveControllerParameters(
                $reflection->getParameters(),
                $route->getPathVars(),
                $route,
                true
            );

            $response = $controller(...$parameters);
        } else {
            try {
                $reflection = new ReflectionMethod($controller, $route->getControllerMethod());
            } catch (\ReflectionException $e) {
                throw new RouteException("Method {$route->getControllerMethod()} does not exist");
            }
            $parameters = $this->resolveControllerParameters(
                $reflection->getParameters(),
                $route->getPathVars(),
                $route,
                false
            );

            if ($reflection->isPrivate()) {
                throw new RouteException("Method {$route->getControllerMethod()} is private");
            }

            if ($controller instanceof Controller) {
                $response = $controller->callMethod(
                    $route->getControllerMethod(), $parameters
                );
            } else {
                $response = $controller->{$route->getControllerMethod()}(...$parameters);
            }
        }

        if (is_string($response)) {
            $response = new Response($response);
        }

        return $response;
    }