/** * Loads routes in from the cache or database * * @return bool */ protected static function _loadDynamicRoutes() { if (static::$options['cache']) { static::$_routes = Cache::read(static::$options['cacheKey']); if (static::$_routes) { return self::_loadRoutes(); } } if (is_object(static::$options['model'])) { static::$model = static::$options['model']; } else { static::$model = ClassRegistry::init(static::$options['model']); } if (!is_object(static::$model)) { CakeLog::write('dynamic_route', 'Unable to load dynamic_route model'); return false; } static::$_routes = static::$model->find('load'); if (static::$_routes) { if (static::$options['cache']) { Cache::write(static::$options['cacheKey'], static::$_routes); } return self::_loadRoutes(); } CakeLog::write('dynamic_route', 'No routes available'); return false; }
/** * @param bool $parseActions * @param bool $forced */ static function routes($parseActions = TRUE, $forced = FALSE) { if ($forced || !static::$_routes) { $pathPrefix = 'classes' . DIRECTORY_SEPARATOR; $directoryPrefix = self::config('directory_prefix'); $path = rtrim($pathPrefix . 'Controller' . DIRECTORY_SEPARATOR . $directoryPrefix, DIRECTORY_SEPARATOR); $controllers = array_keys(Arr::flatten(Kohana::list_files($path))); $urlBase = self::config('route.url.base', 'api'); $urlPrefix = $urlBase . self::config('route.url.version', '/v{version}'); foreach ($controllers as $controller) { $className = str_replace([$pathPrefix, DIRECTORY_SEPARATOR, EXT], ['', '_', ''], $controller); self::getClassRoutes($className, $directoryPrefix, $urlPrefix, $parseActions); } Route::set('RestfulAPI\\Error', $urlBase . '(/<unknown>)', ['unknown' => '.*'])->filter([get_class(), 'error404']); static::$_routes = TRUE; } }
/** * register_handler * registers a new set of routes under a handler * * @param object $instance * @param array $routes * @return bool */ public static function register_handler($instance, array $routes) { if (static::$_routes === null) { static::$_routes = array(); } foreach ($routes as $route => $method) { static::$_routes[] = array($route, array($instance, $method)); } return true; }
/** * Reloads default Router settings. Resets all class variables and * removes all connected routes. * * @return void */ public static function reload() { if (empty(static::$_initialState)) { static::$_initialState = get_class_vars(get_called_class()); static::_setPrefixes(); static::$_routes = new RouteCollection(); return; } foreach (static::$_initialState as $key => $val) { if ($key != '_initialState') { static::${$key} = $val; } } static::_setPrefixes(); static::$_routes = new RouteCollection(); }