/** * Generates routed URI from given URI. * * @param string URI to convert * @return string Routed uri */ public static function routed_uri($uri) { if (self::$routes === NULL) { // Load routes self::$routes = Kohana::config('routes'); } // Prepare variables $routed_uri = $uri = trim($uri, '/'); if (isset(self::$routes[$uri])) { // Literal match, no need for regex $routed_uri = self::$routes[$uri]; } else { // Loop through the routes and see if anything matches foreach (self::$routes as $key => $val) { if ($key === '_default') { continue; } // Trim slashes $key = trim($key, '/'); $val = trim($val, '/'); if (preg_match('#^' . $key . '$#u', $uri)) { if (strpos($val, '$') !== FALSE) { // Use regex routing $routed_uri = preg_replace('#^' . $key . '$#u', $val, $uri); } else { // Standard routing $routed_uri = $val; } // A valid route has been found break; } } } if (isset(self::$routes[$routed_uri])) { // Check for double routing (without regex) $routed_uri = self::$routes[$routed_uri]; } return trim($routed_uri, '/'); }