system/classes/Route.php
protected function routeFind($basePath = '', $offset = 0)
    {
        $this->debug('');

        // Vars setup
        $curPath = $this->partialPathArray($offset, 1);
        $controller = '';
        $controllerFileName = '';

        $this->debug('Current Path: '.implode('/', $curPath));

        // if $curPath isn't empty
        if (is_array($curPath) and !empty($curPath) and $curPath[0] != '') {
            $controller_path = $curPath[0];
        }
        // Else grab the default controller.
        else {
            $controller_path = $this->config['default_controller'];
        }
            $controller = $this->getClassName($controller_path);
            $controllerFileName =   $this->config['controllersPrefix'] .
                                    $controller .
                                    $this->config['controllersPostfix'] .
                                    '.php';

        // Set working filepath.
        $dirpath = $this->config['pathToControllers'].$basePath.$controller_path;
        $filepath = $this->config['pathToControllers'].$basePath.$controllerFileName;

        // Debug
        $this->debug('Searching for: ' . $filepath);

        // Check if the controller .php file exists in this directory.
        if (file_exists($filepath)) {
            $this->controllerPath = $this->partialPathString(0, $offset+1);
            $this->controllerOffset = $offset;
            $this->controllerName = $controller;

            $this->debug('File Found: ' . $controllerFileName);
            $this->debug('Controller Path: ' . $this->controllerPath);

            // Create instance of controller and check if that method exists in it. Otherwise we want to keep
            // looking for other sub-folder classes that might map to the url.
            $controllerInstance = $this->getController();
            $method = $this->getMethod();
            $this->debug("getMethod() call in routeFind() returns: ".$method);

            if (!is_callable(array($controllerInstance, $method))) {
                // Update namespace
                $this->controllerNamespace .= $this->controllerName.'\\';

                //  Controller->Method combo doesn't exist, so undo previously set data.
                $this->controllerPath = null;
                $this->controllerOffset = null;
                $this->controllerName = null;

                // Debug
                $this->debug('Not matching method within controller. Continuing search.');

            } else {
                // Valid controller+method combination found, so stop searching further.
                $this->controller   = $controllerInstance;
                $this->method       = $method;
                return true;
            }
        }
        else {
            // Update namespace
            $this->controllerNamespace .= $controller.'\\';
        }

        // Else check if there's a matching directory we can look through.
        if (is_dir($dirpath)) {
            $this->debug('Directory Found: ' . $basePath . $controller);

            // Recursive call
            $this->routeFind($basePath . $controller_path . '/', $offset+1);
        }

    }
protected function routeFind($basePath = '', $offset = 0)
    {
        $this->debug('');

        // Vars setup
        $curPath = $this->partialPathArray($offset, 1);
        $controller = '';
        $controllerFileName = '';

        $this->debug('Current Path: '.implode('/', $curPath));

        // if $curPath isn't empty
        if (is_array($curPath) and !empty($curPath) and $curPath[0] != '') {
            $controller_path = $curPath[0];
        }
        // Else grab the default controller.
        else {
            $controller_path = $this->config['default_controller'];
        }
            $controller = $this->getClassName($controller_path);
            $controllerFileName =   $this->config['controllersPrefix'] .
                                    $controller .
                                    $this->config['controllersPostfix'] .
                                    '.php';

        // Set working filepath.
        $dirpath = $this->config['pathToControllers'].$basePath.$controller_path;
        $filepath = $this->config['pathToControllers'].$basePath.$controllerFileName;

        // Debug
        $this->debug('Searching for: ' . $filepath);

        // Check if the controller .php file exists in this directory.
        if (file_exists($filepath)) {
            $this->controllerPath = $this->partialPathString(0, $offset+1);
            $this->controllerOffset = $offset;
            $this->controllerName = $controller;

            $this->debug('File Found: ' . $controllerFileName);
            $this->debug('Controller Path: ' . $this->controllerPath);

            // Create instance of controller and check if that method exists in it. Otherwise we want to keep
            // looking for other sub-folder classes that might map to the url.
            $controllerInstance = $this->getController();
            $method = $this->getMethod();
            $this->debug("getMethod() call in routeFind() returns: ".$method);

            if (!is_callable(array($controllerInstance, $method))) {
                // Update namespace
                $this->controllerNamespace .= $this->controllerName.'\\';

                //  Controller->Method combo doesn't exist, so undo previously set data.
                $this->controllerPath = null;
                $this->controllerOffset = null;
                $this->controllerName = null;

                // Debug
                $this->debug('Not matching method within controller. Continuing search.');

            } else {
                // Valid controller+method combination found, so stop searching further.
                $this->controller   = $controllerInstance;
                $this->method       = $method;
                return true;
            }
        }
        else {
            // Update namespace
            $this->controllerNamespace .= $controller.'\\';
        }

        // Else check if there's a matching directory we can look through.
        if (is_dir($dirpath)) {
            $this->debug('Directory Found: ' . $basePath . $controller);

            // Recursive call
            $this->routeFind($basePath . $controller_path . '/', $offset+1);
        }

    }
Searches through $path to figure out what part of it is the controller.
This requires searching through the filesystem.

If   $path = /folder1/folder2/Controller/Method/Id
Then $controllerPath    = '/folder1/folder2/Controller'
And  $controllerOffset  = 2

NOTE: This is a recursive function.