public function loadRoutesFromClass($className, $hooks=[])
    {
        $cache = new CheckableCache($this->cache);

        $key = 'loadRoutesFromClass:' . md5(__CLASS__ . ':' . $className);
        $routes = $cache->get($key, $this);

        $controller = null;
        if ($routes == $this) { //not cached
            $routes = [];
            $controller = $this->controllerContainerBuilder->build($className);
            foreach ($controller->getRoutes() as $actionName => $route) {
                $routes[] = [$route->getMethod(), $route->getUri(), $actionName];
            }
            $cache->set($key, $routes, 0, new ClassModifiedChecker($className));
        }
        foreach ($routes as $route) {
            list($method, $uri, $actionName) = $route;
            $this->routes[] = [
                $method,
                $uri,
                function (Application $app, Request $request) use ($cache, $className, $actionName, $controller) {

                    $key = 'loadRoutesFromClass:route:' . md5(__CLASS__ . ':' . $className . ':' . $actionName);

                    $routeInstance = $cache->get($key, $this);
                    if ($routeInstance == $this) {
                        if (!$controller) {
                            $controller = $app->controllerContainerBuilder->build($className);
                        }
                        $routeInstance = $controller->getRoute($actionName) or
                        abort(new NotFoundHttpException("action $actionName not found"));
                        $cache->set($key, $routeInstance, 0, new ClassModifiedChecker($className));
                    }
                    return ControllerContainer::dispatch($this, $className, $actionName, $routeInstance, $request);
                },
                $hooks
            ];
        }
        $this->controllers[] = $className;
    }
public function loadRoutesFromClass($className, $hooks=[])
    {
        $cache = new CheckableCache($this->cache);

        $key = 'loadRoutesFromClass:' . md5(__CLASS__ . ':' . $className);
        $routes = $cache->get($key, $this);

        $controller = null;
        if ($routes == $this) { //not cached
            $routes = [];
            $controller = $this->controllerContainerBuilder->build($className);
            foreach ($controller->getRoutes() as $actionName => $route) {
                $routes[] = [$route->getMethod(), $route->getUri(), $actionName];
            }
            $cache->set($key, $routes, 0, new ClassModifiedChecker($className));
        }
        foreach ($routes as $route) {
            list($method, $uri, $actionName) = $route;
            $this->routes[] = [
                $method,
                $uri,
                function (Application $app, Request $request) use ($cache, $className, $actionName, $controller) {

                    $key = 'loadRoutesFromClass:route:' . md5(__CLASS__ . ':' . $className . ':' . $actionName);

                    $routeInstance = $cache->get($key, $this);
                    if ($routeInstance == $this) {
                        if (!$controller) {
                            $controller = $app->controllerContainerBuilder->build($className);
                        }
                        $routeInstance = $controller->getRoute($actionName) or
                        abort(new NotFoundHttpException("action $actionName not found"));
                        $cache->set($key, $routeInstance, 0, new ClassModifiedChecker($className));
                    }
                    return ControllerContainer::dispatch($this, $className, $actionName, $routeInstance, $request);
                },
                $hooks
            ];
        }
        $this->controllers[] = $className;
    }
public function loadRoutesFromClass ( $ className , $ hooks = [ ] ) { $ cache = new CheckableCache ( $ this -> cache ) ; $ key = 'loadRoutesFromClass:' . md5 ( __CLASS__ . ':' . $ className ) ; $ routes = $ cache -> get ( $ key , $ this ) ; $ controller = null ; if ( $ routes == $ this ) { //not cached $ routes = [ ] ; $ controller = $ this -> controllerContainerBuilder -> build ( $ className ) ; foreach ( $ controller -> getRoutes ( ) as $ actionName => $ route ) { $ routes [ ] = [ $ route -> getMethod ( ) , $ route -> getUri ( ) , $ actionName ] ; } $ cache -> set ( $ key , $ routes , 0 , new ClassModifiedChecker ( $ className ) ) ; } foreach ( $ routes as $ route ) { list ( $ method , $ uri , $ actionName ) = $ route ; $ this -> routes [ ] = [ $ method , $ uri , function ( Application $ app , Request $ request ) use ( $ cache , $ className , $ actionName , $ controller ) { $ key = 'loadRoutesFromClass:route:' . md5 ( __CLASS__ . ':' . $ className . ':' . $ actionName ) ; $ routeInstance = $ cache -> get ( $ key , $ this ) ; if ( $ routeInstance == $ this ) { if ( ! $ controller ) { $ controller = $ app -> controllerContainerBuilder -> build ( $ className ) ; } $ routeInstance = $ controller -> getRoute ( $ actionName ) or abort ( new NotFoundHttpException ( "action $actionName not found" ) ) ; $ cache -> set ( $ key , $ routeInstance , 0 , new ClassModifiedChecker ( $ className ) ) ; } return ControllerContainer :: dispatch ( $ this , $ className , $ actionName , $ routeInstance , $ request ) ; } , $ hooks ] ; } $ this -> controllers [ ] = $ className ; }
load routes from class

@param string $className
@param string[] $hooks hook class names
@return void
load routes from class