/** * Creates a URI for the given route. * * @param string route name * @param array route key values * @return string */ public static function uri($route, array $values = array()) { if ($route === TRUE) { $route = Router::$current_route; $values = array_merge(array('controller' => Router::$controller, 'method' => Router::$method), Router::$arguments, $values); } if (!($route = Eight::config('routes.' . $route))) { // @todo: This should be an exception return FALSE; } // Get the URI keys from the route $keys = Router::keys($route[0]); // Copy the URI, it will have parameters replaced $uri = $route[0]; // String searches and replacements $search = $replace = array(); foreach ($keys as $key) { if (isset($values[$key])) { $search[] = ':' . $key; $replace[] = $values[$key]; } } // Replace all the keys with the values $uri = str_replace($search, $replace, $uri); // Remove trailing parts from the URI $uri = preg_replace('#/?:.+$#', '', $uri); return $uri; }