1) { Router::$rsegments = Router::routed_uri(Router::$current_uri); } Router::$routed_uri = Router::$rsegments; Router::$rsegments = explode('/', Router::$rsegments); $controller_path = ''; $method_segment = NULL; $paths = Kohana::include_paths(); foreach (Router::$rsegments as $key => $segment) { $controller_path .= $segment; $found = FALSE; foreach ($paths as $dir) { $dir .= 'controllers/'; if (is_dir($dir.$controller_path) OR is_file($dir.$controller_path.EXT)) { $found = TRUE; if ($c = str_replace('\\', '/', realpath($dir.$controller_path.EXT)) AND is_file($c) AND strpos($c, $dir) === 0) { Router::$controller = $segment; Router::$controller_path = $c; $method_segment = $key + 1; break; } } } if ($found === FALSE) { break; } $controller_path .= '/'; } if ($method_segment !== NULL AND isset(Router::$rsegments[$method_segment])) { Router::$method = Router::$rsegments[$method_segment]; if (isset(Router::$rsegments[$method_segment + 1])) { Router::$arguments = array_slice(Router::$rsegments, $method_segment + 1); } } Event::run('system.post_routing'); if (Router::$controller === NULL) { Event::run('system.404'); } } public static function find_uri() { if (PHP_SAPI === 'cli') { if (isset($_SERVER['argv'][1])) { Router::$current_uri = $_SERVER['argv'][1]; if (($query = strpos(Router::$current_uri, '?')) !== FALSE) { list (Router::$current_uri, $query) = explode('?', Router::$current_uri, 2); parse_str($query, $_GET); $_GET = utf8::clean($_GET); } } } elseif (isset($_GET['kohana_uri'])) { Router::$current_uri = $_GET['kohana_uri']; unset($_GET['kohana_uri']); $_SERVER['QUERY_STRING'] = preg_replace('~\bkohana_uri\b[^&]*+&?~', '', $_SERVER['QUERY_STRING']); } elseif (isset($_SERVER['PATH_INFO']) AND $_SERVER['PATH_INFO']) { Router::$current_uri = $_SERVER['PATH_INFO']; } elseif (isset($_SERVER['ORIG_PATH_INFO']) AND $_SERVER['ORIG_PATH_INFO']) { Router::$current_uri = $_SERVER['ORIG_PATH_INFO']; } elseif (isset($_SERVER['PHP_SELF']) AND $_SERVER['PHP_SELF']) { Router::$current_uri = $_SERVER['PHP_SELF']; } if (($strpos_fc = strpos(Router::$current_uri, KOHANA)) !== FALSE) { Router::$current_uri = (string) substr(Router::$current_uri, $strpos_fc + strlen(KOHANA)); } Router::$original_current_uri = Router::$current_uri; Router::$current_uri = trim(Router::$current_uri, '/'); if (Router::$current_uri !== '') { if ($suffix = Kohana::config('core.url_suffix') AND strpos(Router::$current_uri, $suffix) !== FALSE) { Router::$current_uri = preg_replace('#'.preg_quote($suffix).'$#u', '', Router::$current_uri); Router::$url_suffix = $suffix; } Router::$current_uri = preg_replace('#//+#', '/', Router::$current_uri); } } public static function routed_uri($uri) { if (Router::$routes === NULL) { Router::$routes = Kohana::config('routes'); } $routed_uri = $uri = trim($uri, '/'); if (isset(Router::$routes[$uri])) { $routed_uri = Router::$routes[$uri]; } else { foreach (Router::$routes as $key => $val) { if ($key === '_default') continue; $key = trim($key, '/'); $val = trim($val, '/'); if (preg_match('#^'.$key.'$#u', $uri)) { if (strpos($val, '$') !== FALSE) { $routed_uri = preg_replace('#^'.$key.'$#u', $val, $uri); } else { $routed_uri = $val; } break; } } } if (isset(Router::$routes[$routed_uri])) { $routed_uri = Router::$routes[$routed_uri]; } return trim($routed_uri, '/'); } }