Gear::subControllerHandler PHP Method

subControllerHandler() private method

Hendle the sub-controller calling process.
private subControllerHandler ( )
    private function subControllerHandler()
    {
        if (!is_dir($subControllerFolder = APP . 'Controllers/' . $this->firstUriPath . '/')) {
            $this->moduleHandler();
            return;
        }
        $controllerClass = $this->uriObj->getMethod(null);
        // No argument? set to default controller.
        if (is_null($controllerClass)) {
            $controllerClass = $this->config['main']['defaultController'];
        }
        $controllerClass = ucwords($controllerClass);
        if (!file_exists($classFile = $subControllerFolder . $controllerClass . '.php')) {
            throw new Resources\HttpException('Controller ' . $controllerClass . ' does not exists in sub-controller ' . $this->firstUriPath . '.');
        }
        $controllerNamespace = 'Controllers\\' . $this->firstUriPath . '\\' . $controllerClass;
        if (!class_exists($controllerNamespace)) {
            throw new Resources\RunException('Class ' . $controllerNamespace . '  not found in ' . $classFile);
        }
        $instance = new $controllerNamespace();
        $request = array_slice($this->uriObj->path(), 3);
        if (!($method = $this->uriObj->path(2))) {
            $method = 'index';
        }
        if (!method_exists($instance, $method)) {
            $request = array_slice($this->uriObj->path(), 2);
            $method = $this->config['main']['alias']['method'];
            if (!method_exists($instance, $method)) {
                throw new Resources\HttpException('Method ' . $this->uriObj->path(2) . ' does not exists in controller /' . $this->firstUriPath . '/' . $controllerClass . '.');
            }
        }
        $this->run($instance, $method, $request);
    }