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;
    }
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;
    }
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 ; }
Calls the method on the input controller

@param Controller|Closure|mixed $controller The instance of the controller to call
@param CompiledRoute $route The route being dispatched
@return Response Returns the value from the controller method
@throws RouteException Thrown if the method could not be called on the controller
Calls the method on the input controller