public function loadController($basePath, $controllerClass, $middleware = null)
    {
        $method_list = get_class_methods($controllerClass);
        $reflector = new \ReflectionClass($controllerClass);
        foreach ($method_list as $method) {
            if (strpos($method, '_') === 0) {
                continue;
            }
            $path = $basePath . $method;
            $parameters = $reflector->getMethod($method)->getParameters();
            $after_string = "";
            $came_in_default_area = false;
            if (!empty($parameters)) {
                //self::ROUTER_TYPE_REGEX
                foreach ($parameters as $param) {
                    if ($param->isDefaultValueAvailable()) {
                        $path .= "(";
                        $after_string .= ")?";
                        $came_in_default_area = true;
                    } elseif ($came_in_default_area) {
                        //non-default after default
                        if ($this->debug) {
                            echo ("ROUTE SETTING ERROR: required-parameter after non-required-parameter") . PHP_EOL;
                        }
                        return;
                    }
                    $path .= '/{' . $param->name . '}';
                }
                $path .= $after_string;
            }
            $this->registerRoute(null, $path, [$controllerClass, $method], $middleware);
            if ($method == $this->default_method_name) {
                $basePathX = $basePath;
                if (strlen($basePathX) > 0) {
                    $basePathX = substr($basePathX, 0, strlen($basePathX) - 1);
                }
                $this->registerRoute(null, $basePathX, [$controllerClass, $method], $middleware);
            }
        }
    }
public function loadController($basePath, $controllerClass, $middleware = null)
    {
        $method_list = get_class_methods($controllerClass);
        $reflector = new \ReflectionClass($controllerClass);
        foreach ($method_list as $method) {
            if (strpos($method, '_') === 0) {
                continue;
            }
            $path = $basePath . $method;
            $parameters = $reflector->getMethod($method)->getParameters();
            $after_string = "";
            $came_in_default_area = false;
            if (!empty($parameters)) {
                //self::ROUTER_TYPE_REGEX
                foreach ($parameters as $param) {
                    if ($param->isDefaultValueAvailable()) {
                        $path .= "(";
                        $after_string .= ")?";
                        $came_in_default_area = true;
                    } elseif ($came_in_default_area) {
                        //non-default after default
                        if ($this->debug) {
                            echo ("ROUTE SETTING ERROR: required-parameter after non-required-parameter") . PHP_EOL;
                        }
                        return;
                    }
                    $path .= '/{' . $param->name . '}';
                }
                $path .= $after_string;
            }
            $this->registerRoute(null, $path, [$controllerClass, $method], $middleware);
            if ($method == $this->default_method_name) {
                $basePathX = $basePath;
                if (strlen($basePathX) > 0) {
                    $basePathX = substr($basePathX, 0, strlen($basePathX) - 1);
                }
                $this->registerRoute(null, $basePathX, [$controllerClass, $method], $middleware);
            }
        }
    }
public function loadController ( $ basePath , $ controllerClass , $ middleware = null ) { $ method_list = get_class_methods ( $ controllerClass ) ; $ reflector = new \ ReflectionClass ( $ controllerClass ) ; foreach ( $ method_list as $ method ) { if ( strpos ( $ method , '_' ) === 0 ) { continue ; } $ path = $ basePath . $ method ; $ parameters = $ reflector -> getMethod ( $ method ) -> getParameters ( ) ; $ after_string = "" ; $ came_in_default_area = false ; if ( ! empty ( $ parameters ) ) { //self::ROUTER_TYPE_REGEX foreach ( $ parameters as $ param ) { if ( $ param -> isDefaultValueAvailable ( ) ) { $ path .= "(" ; $ after_string .= ")?" ; $ came_in_default_area = true ; } elseif ( $ came_in_default_area ) { //non-default after default if ( $ this -> debug ) { echo ( "ROUTE SETTING ERROR: required-parameter after non-required-parameter" ) . PHP_EOL ; } return ; } $ path .= '/{' . $ param -> name . '}' ; } $ path .= $ after_string ; } $ this -> registerRoute ( null , $ path , [ $ controllerClass , $ method ] , $ middleware ) ; if ( $ method == $ this -> default_method_name ) { $ basePathX = $ basePath ; if ( strlen ( $ basePathX ) > 0 ) { $ basePathX = substr ( $ basePathX , 0 , strlen ( $ basePathX ) - 1 ) ; } $ this -> registerRoute ( null , $ basePathX , [ $ controllerClass , $ method ] , $ middleware ) ; } } }
Like CI, bind a controller to a base URL
@param string $basePath controller/base/
@param string $controllerClass app/controller/controllerA
@param null|MiddlewareInterface $middleware as is
@throws \ReflectionException
Like CI bind a controller to a base URL