src/API.php
private function resolveController($route, $path)
    {
        $pathComponents = explode('/', $path);
        $baseClassPath = $this->config->getClassPath($route);

        $classObject = null;
        $aliases = $this->config->getAliases($route);

        $class = $baseClassPath;
        $classAlias = '';

        $controllerFactory = $this->config->getControllerFactory();
        $routeConfig = [];

        $routes = $this->config->getRoutes();
        if (is_array($routes) && isset($routes[$route]['config'])) {
            $routeConfig = $routes[$route]['config'];
        }

        while ($pathComponents) {
            $pathComponent = array_shift($pathComponents);

            $class = $class.'\\'.ucfirst($pathComponent);
            $classAlias .= ucfirst($pathComponent);

            // check for an alias first
            if (isset($aliases[strtolower($classAlias)])) {
                $aliasClass = $baseClassPath.'\\'.$aliases[strtolower($classAlias)];

                if (class_exists($aliasClass)) {
                    $classObject = $controllerFactory($aliasClass, $routeConfig);
                    break;
                }
            }

            if (class_exists($class)) {
                $classObject = $controllerFactory($class, $routeConfig);

                if (!$classObject) {
                    $classObject = new $class();
                    break;
                }

                break;
            }

            $classAlias .= '/';
        }

        if (!$classObject) {
            throw new \Exception('API: No controller found for the requested end point. ');
        }

        // any path left over becomes args
        $pathArgs = $pathComponents;

        return [$classObject, array_shift($pathArgs), $pathArgs];
    }
private function resolveController($route, $path)
    {
        $pathComponents = explode('/', $path);
        $baseClassPath = $this->config->getClassPath($route);

        $classObject = null;
        $aliases = $this->config->getAliases($route);

        $class = $baseClassPath;
        $classAlias = '';

        $controllerFactory = $this->config->getControllerFactory();
        $routeConfig = [];

        $routes = $this->config->getRoutes();
        if (is_array($routes) && isset($routes[$route]['config'])) {
            $routeConfig = $routes[$route]['config'];
        }

        while ($pathComponents) {
            $pathComponent = array_shift($pathComponents);

            $class = $class.'\\'.ucfirst($pathComponent);
            $classAlias .= ucfirst($pathComponent);

            // check for an alias first
            if (isset($aliases[strtolower($classAlias)])) {
                $aliasClass = $baseClassPath.'\\'.$aliases[strtolower($classAlias)];

                if (class_exists($aliasClass)) {
                    $classObject = $controllerFactory($aliasClass, $routeConfig);
                    break;
                }
            }

            if (class_exists($class)) {
                $classObject = $controllerFactory($class, $routeConfig);

                if (!$classObject) {
                    $classObject = new $class();
                    break;
                }

                break;
            }

            $classAlias .= '/';
        }

        if (!$classObject) {
            throw new \Exception('API: No controller found for the requested end point. ');
        }

        // any path left over becomes args
        $pathArgs = $pathComponents;

        return [$classObject, array_shift($pathArgs), $pathArgs];
    }
private function resolveController ( $ route , $ path ) { $ pathComponents = explode ( '/' , $ path ) ; $ baseClassPath = $ this -> config -> getClassPath ( $ route ) ; $ classObject = null ; $ aliases = $ this -> config -> getAliases ( $ route ) ; $ class = $ baseClassPath ; $ classAlias = '' ; $ controllerFactory = $ this -> config -> getControllerFactory ( ) ; $ routeConfig = [ ] ; $ routes = $ this -> config -> getRoutes ( ) ; if ( is_array ( $ routes ) && isset ( $ routes [ $ route ] [ 'config' ] ) ) { $ routeConfig = $ routes [ $ route ] [ 'config' ] ; } while ( $ pathComponents ) { $ pathComponent = array_shift ( $ pathComponents ) ; $ class = $ class . '\\' . ucfirst ( $ pathComponent ) ; $ classAlias .= ucfirst ( $ pathComponent ) ; // check for an alias first if ( isset ( $ aliases [ strtolower ( $ classAlias ) ] ) ) { $ aliasClass = $ baseClassPath . '\\' . $ aliases [ strtolower ( $ classAlias ) ] ; if ( class_exists ( $ aliasClass ) ) { $ classObject = $ controllerFactory ( $ aliasClass , $ routeConfig ) ; break ; } } if ( class_exists ( $ class ) ) { $ classObject = $ controllerFactory ( $ class , $ routeConfig ) ; if ( ! $ classObject ) { $ classObject = new $ class ( ) ; break ; } break ; } $ classAlias .= '/' ; } if ( ! $ classObject ) { throw new \ Exception ( 'API: No controller found for the requested end point. ' ) ; } // any path left over becomes args $ pathArgs = $ pathComponents ; return [ $ classObject , array_shift ( $ pathArgs ) , $ pathArgs ] ; }
Resolves controller to object and remaining args.

@param string $route
@param string $path

@throws \Exception

@return array
Resolves controller to object and remaining args .