public function get_resource() { static $resource; if (empty($resource)) { $resource = Route::parse(); } return $resource; }
/** * Processes the given request using the defined routes * * @param Request the given Request object * @param bool whether to use the defined routes or not * @return mixed the match array or false */ public static function process(\Request $request, $route = true) { $match = false; if ($route) { foreach (static::$routes as $route) { if ($match = $route->parse($request)) { break; } } } if (!$match) { // Since we didn't find a match, we will create a new route. $match = new Route(preg_quote($request->uri->get()), $request->uri->get()); $match->parse($request); } return static::find_controller($match); }
public function route() { // Route $route = new Route($this->registry); // Parse $route->parse(); // Set $this->registry->set('route', $route); $this->trigger->fire('post.app.route'); }
/** * Creates the new Request object by getting a new URI object, then parsing * the uri with the Route class. * * @access public * @param string the uri string * @param bool whether or not to route the URI * @return void */ public function __construct($uri, $route) { $this->uri = new \URI($uri); $route = $route === true ? \Route::parse($this->uri) : \Route::parse_match($uri); // Attempts to register the first segment as a module $mod_path = \Fuel::add_module($route['segments'][0]); if ($mod_path !== false) { $this->module = array_shift($route['segments']); $this->paths = array($mod_path, $mod_path . 'classes' . DS); } // Check for directory $path = (!empty($this->module) ? $mod_path : APPPATH) . 'classes' . DS . 'controller' . DS; if (!empty($route['segments']) && is_dir($dirpath = $path . strtolower($route['segments'][0]))) { $this->directory = array_shift($route['segments']); } // When emptied the controller defaults to directory or module $controller = empty($this->directory) ? $this->module : $this->directory; if (count($route['segments']) == 0) { $route['segments'] = array($controller); } $this->controller = $route['segments'][0]; $this->action = isset($route['segments'][1]) ? $route['segments'][1] : ''; $this->method_params = array_slice($route['segments'], 2); $this->named_params = $route['named_params']; unset($route); }
/** * 设置路由 */ private function _setRoute() { $routeObj = new Route(); $routeObj->parse(); }
/** * Processes the given request using the defined routes * * @param Request the given Request object * @param bool whether to use the defined routes or not * @return mixed the match array or false */ public static function process(\Request $request, $route = true) { $match = false; if ($route) { foreach (static::$routes as $route) { if ($match = $route->parse($request)) { break; } } } if (!$match) { // Since we didn't find a match, we will create a new route. $match = new \Route(preg_quote($request->uri->get(), '#'), $request->uri->get()); $match->parse($request); } if ($match->callable !== null) { return $match; } return static::parse_match($match); }