Class declared in MODPATH/gleez/classes/route.php on line 3.
string(18) "<([a-zA-Z0-9_]++)>"string(12) "[^/.,;?\n]++"string(17) "[.\+*?[^\]${}=!|]"bool $cacheIndicates whether routes are cached
bool TRUE
string $default_actiondefault action for all routes
string(5) "index"string $default_protocoldefault protocol for all routes
string(7) "http://"array $localhostslist of valid localhost entries
array(4) ( 0 => bool FALSE 1 => string(0) "" 2 => string(5) "local" 3 => string(9) "localhost" )
callback $_callbackThe callback method for routes
array $_defaultsarray $_filtersRoute filters
string $_nameRoute name
array $_regexstring $_route_regexarray $_routesarray(32) ( "resize" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(45) "media/imagecache/<type>/<dimensions>(/<file>)" protected _regex => array(3) ( "dimensions" => string(7) "\d+x\d+" "type" => string(17) "crop|ratio|resize" "file" => string(2) ".+" ) protected _defaults => array(3) ( "controller" => string(6) "resize" "action" => string(5) "image" "type" => string(6) "resize" ) protected _route_regex => string(92) "#^media/imagecache/(?P<type>crop|ratio|resize)/(?P<dimensions>\d+x\d+)(?:/(?P<file>.+))?$#uD" }"media" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(12) "media/<file>" protected _regex => array(1) ( "file" => string(2) ".+" ) protected _defaults => array(3) ( "controller" => string(5) "media" "action" => string(5) "serve" "file" => NULL ) protected _route_regex => string(24) "#^media/(?P<file>.+)$#uD" }"user" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(32) "user(/<action>)(/<id>)(/<token>)" protected _regex => array(2) ( "action" => string(62) "edit|login|logout|view|register|confirm|password|profile|photo" "id" => string(3) "\d+" ) protected _defaults => array(3) ( "controller" => string(4) "user" "action" => string(4) "view" "token" => NULL ) protected _route_regex => string(136) "#^user(?:/(?P<action>edit|login|logout|view|register|confirm|password|profile|photo))?(?:/(?P<id>\d+))?(?:/(?P<token>[^/.,;?\n]++))?$#uD" }"user/oauth" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(29) "oauth/<controller>(/<action>)" protected _regex => array(0) protected _defaults => array(2) ( "directory" => string(5) "oauth" "action" => string(5) "index" ) protected _route_regex => string(70) "#^oauth/(?P<controller>[^/.,;?\n]++)(?:/(?P<action>[^/.,;?\n]++))?$#uD" }"user/reset" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(47) "user/reset(/<action>)(/<id>)(/<token>)(/<time>)" protected _regex => array(3) ( "action" => string(25) "password|confirm_password" "id" => string(3) "\d+" "time" => string(3) "\d+" ) protected _defaults => array(4) ( "controller" => string(4) "user" "action" => string(16) "confirm_password" "token" => NULL "time" => NULL ) protected _route_regex => string(124) "#^user/reset(?:/(?P<action>password|confirm_password))?(?:/(?P<id>\d+))?(?:/(?P<token>[^/.,;?\n]++))?(?:/(?P<time>\d+))?$#uD" }"admin/permission" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(28) "admin/permissions(/<action>)" protected _regex => array(0) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(10) "permission" "action" => string(4) "list" ) protected _route_regex => string(53) "#^admin/permissions(?:/(?P<action>[^/.,;?\n]++))?$#uD" }"admin/role" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(39) "admin/roles(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(20) "list|add|edit|delete" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "role" "action" => string(4) "list" ) protected _route_regex => string(92) "#^admin/roles(?:/(?P<action>list|add|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/user" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(39) "admin/users(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(20) "list|add|edit|delete" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "user" "action" => string(4) "list" ) protected _route_regex => string(92) "#^admin/users(?:/(?P<action>list|add|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"captcha" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(17) "captcha(/<group>)" protected _regex => array(0) protected _defaults => array(3) ( "controller" => string(7) "captcha" "action" => string(5) "index" "group" => NULL ) protected _route_regex => string(42) "#^captcha(?:/(?P<group>[^/.,;?\n]++))?$#uD" }"docs/media" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(20) "guide/media(/<file>)" protected _regex => array(1) ( "file" => string(2) ".+" ) protected _defaults => array(3) ( "controller" => string(9) "userguide" "action" => string(5) "media" "file" => NULL ) protected _route_regex => string(35) "#^guide/media(?:/(?P<file>.+))?$#uD" }"docs/api" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(19) "guide/api(/<class>)" protected _regex => array(1) ( "class" => string(13) "[a-zA-Z0-9_]+" ) protected _defaults => array(3) ( "controller" => string(9) "userguide" "action" => string(3) "api" "class" => NULL ) protected _route_regex => string(45) "#^guide/api(?:/(?P<class>[a-zA-Z0-9_]+))?$#uD" }"docs/guide" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(25) "guide(/<module>(/<page>))" protected _regex => array(1) ( "page" => string(2) ".+" ) protected _defaults => array(3) ( "controller" => string(9) "userguide" "action" => string(4) "docs" "module" => string(0) "" ) protected _route_regex => string(59) "#^guide(?:/(?P<module>[^/.,;?\n]++)(?:/(?P<page>.+))?)?$#uD" }"admin/module" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(24) "admin/modules(/<action>)" protected _regex => array(0) protected _defaults => array(2) ( "directory" => string(5) "admin" "controller" => string(7) "modules" ) protected _route_regex => string(49) "#^admin/modules(?:/(?P<action>[^/.,;?\n]++))?$#uD" }"admin/page" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(39) "admin/pages(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(33) "index|list|settings|reset|confirm" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "page" "action" => string(4) "list" ) protected _route_regex => string(105) "#^admin/pages(?:/(?P<action>index|list|settings|reset|confirm)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/comment" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(42) "admin/comments(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(43) "index|list|process|view|delete|spam|pending" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(7) "comment" "action" => string(4) "list" ) protected _route_regex => string(118) "#^admin/comments(?:/(?P<action>index|list|process|view|delete|spam|pending)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/menu" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(40) "admin/menus(/<action>(/<id>))(/p/<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(28) "list|add|edit|delete|confirm" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "menu" "action" => string(4) "list" ) protected _route_regex => string(101) "#^admin/menus(?:/(?P<action>list|add|edit|delete|confirm)(?:/(?P<id>\d+))?)?(?:/p/(?P<page>\d+))?$#uD" }"admin/menu/item" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(44) "admin/menu/manage/<id>(/<action>)(/p/<page>)" protected _regex => array(4) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(28) "list|add|edit|delete|confirm" "slug" => string(13) "[A-Za-z0-9-]+" ) protected _defaults => array(3) ( "directory" => string(10) "admin/menu" "controller" => string(4) "item" "action" => string(4) "list" ) protected _route_regex => string(102) "#^admin/menu/manage/(?P<id>\d+)(?:/(?P<action>list|add|edit|delete|confirm))?(?:/p/(?P<page>\d+))?$#uD" }"admin/path" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(39) "admin/paths(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(20) "list|add|edit|delete" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "path" "action" => string(4) "list" ) protected _route_regex => string(92) "#^admin/paths(?:/(?P<action>list|add|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/tag" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(38) "admin/tags(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(20) "list|add|edit|delete" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(3) "tag" "action" => string(4) "list" ) protected _route_regex => string(91) "#^admin/tags(?:/(?P<action>list|add|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/taxonomy" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(42) "admin/taxonomy(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(20) "list|add|edit|delete" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(8) "taxonomy" "action" => string(4) "list" ) protected _route_regex => string(95) "#^admin/taxonomy(?:/(?P<action>list|add|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/term" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(37) "admin/terms(/<action>)/<id>(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(28) "list|add|edit|delete|confirm" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(4) "term" "action" => string(4) "list" ) protected _route_regex => string(95) "#^admin/terms(?:/(?P<action>list|add|edit|delete|confirm))?/(?P<id>\d+)(?:/p(?P<page>\d+))?$#uD" }"admin/widget" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(41) "admin/widgets(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(51) "index|list|view|add|edit|delete|reset|confirm|clone" ) protected _defaults => array(2) ( "directory" => string(5) "admin" "controller" => string(6) "widget" ) protected _route_regex => string(125) "#^admin/widgets(?:/(?P<action>index|list|view|add|edit|delete|reset|confirm|clone)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"admin/format" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(31) "admin/formats(/<action>(/<id>))" protected _regex => array(2) ( "id" => string(3) "\d+" "action" => string(41) "list|view|add|edit|delete|configure|reset" ) protected _defaults => array(3) ( "directory" => string(5) "admin" "controller" => string(6) "format" "action" => string(4) "list" ) protected _route_regex => string(95) "#^admin/formats(?:/(?P<action>list|view|add|edit|delete|configure|reset)(?:/(?P<id>\d+))?)?$#uD" }"admin/setting" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(25) "admin/settings(/<action>)" protected _regex => array(0) protected _defaults => array(2) ( "directory" => string(5) "admin" "controller" => string(7) "setting" ) protected _route_regex => string(50) "#^admin/settings(?:/(?P<action>[^/.,;?\n]++))?$#uD" }"admin" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(48) "admin(/<controller>)(/<action>)(/<id>)(/p<page>)" protected _regex => array(2) ( "id" => string(3) "\d+" "page" => string(3) "\d+" ) protected _defaults => array(2) ( "directory" => string(5) "admin" "controller" => string(9) "dashboard" ) protected _route_regex => string(112) "#^admin(?:/(?P<controller>[^/.,;?\n]++))?(?:/(?P<action>[^/.,;?\n]++))?(?:/(?P<id>\d+))?(?:/p(?P<page>\d+))?$#uD" }"autocomplete" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(41) "autocomplete/<action>(/<type>)(/<string>)" protected _regex => array(3) ( "string" => string(20) "([A-Za-z0-9\-\,\s]+)" "action" => string(24) "index|user|nick|tag|post" "type" => string(20) "post|page|blog|forum" ) protected _defaults => array(2) ( "controller" => string(12) "autocomplete" "type" => string(4) "blog" ) protected _route_regex => string(129) "#^autocomplete/(?P<action>index|user|nick|tag|post)(?:/(?P<type>post|page|blog|forum))?(?:/(?P<string>([A-Za-z0-9\-\,\s]+)))?$#uD" }"page" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(32) "page(/<action>)(/<id>)(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(36) "index|list|view|add|edit|delete|term" ) protected _defaults => array(2) ( "controller" => string(4) "page" "action" => string(5) "index" ) protected _route_regex => string(101) "#^page(?:/(?P<action>index|list|view|add|edit|delete|term))?(?:/(?P<id>\d+))?(?:/p(?P<page>\d+))?$#uD" }"comment" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(35) "comment(/<action>(/<id>))(/p<page>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "action" => string(33) "list|process|add|view|edit|delete" ) protected _defaults => array(2) ( "controller" => string(7) "comment" "action" => string(4) "list" ) protected _route_regex => string(101) "#^comment(?:/(?P<action>list|process|add|view|edit|delete)(?:/(?P<id>\d+))?)?(?:/p(?P<page>\d+))?$#uD" }"comments" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(52) "comments/<group>/<action>(/<id>)(/p<page>)(<format>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "format" => string(5) "\.\w+" ) protected _defaults => array(4) ( "controller" => string(8) "comments" "group" => string(4) "page" "action" => string(6) "public" "format" => string(6) ".xhtml" ) protected _route_regex => string(122) "#^comments/(?P<group>[^/.,;?\n]++)/(?P<action>[^/.,;?\n]++)(?:/(?P<id>\d+))?(?:/p(?P<page>\d+))?(?:(?P<format>\.\w+))?$#uD" }"rss" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(57) "rss(/<controller>)(/<action>)(/<id>)(/p<page>)(/l<limit>)" protected _regex => array(3) ( "id" => string(3) "\d+" "page" => string(3) "\d+" "limit" => string(3) "\d+" ) protected _defaults => array(2) ( "directory" => string(5) "feeds" "controller" => string(4) "base" ) protected _route_regex => string(131) "#^rss(?:/(?P<controller>[^/.,;?\n]++))?(?:/(?P<action>[^/.,;?\n]++))?(?:/(?P<id>\d+))?(?:/p(?P<page>\d+))?(?:/l(?P<limit>\d+))?$#uD" }"welcome" => object Route(7){ protected _name => NULL protected _filters => array(0) protected _callback => NULL protected _uri => string(25) "welcome(/<action>)(/<id>)" protected _regex => array(0) protected _defaults => array(1) ( "controller" => string(7) "welcome" ) protected _route_regex => string(69) "#^welcome(?:/(?P<action>[^/.,;?\n]++))?(?:/(?P<id>[^/.,;?\n]++))?$#uD" }"default" => object Route(7){ protected _name => NULL protected _filters => array(1) ( 0 => string(12) "Path::lookup" ) protected _callback => NULL protected _uri => string(32) "(<controller>(/<action>(/<id>)))" protected _regex => array(0) protected _defaults => array(2) ( "controller" => string(7) "welcome" "action" => string(5) "index" ) protected _route_regex => string(95) "#^(?:(?P<controller>[^/.,;?\n]++)(?:/(?P<action>[^/.,;?\n]++)(?:/(?P<id>[^/.,;?\n]++))?)?)?$#uD" })
string $_uriroute URI
Creates a new route
Routes should always be created with Route::set or they will not be properly stored.
Example:
$route = new Route($uri, $regex);
string
$uri
= NULL - Route URI pattern or lambda/callback function [Optional]array
$regex
= NULL - Key patterns [Optional]public function __construct($uri = NULL, array $regex = NULL)
{
if (is_null($uri))
{
// Assume the route is from cache
return;
}
if ( ! empty($uri))
{
$this->_uri = $uri;
}
if ( ! empty($regex))
{
$this->_regex = $regex;
}
// Store the compiled regex locally
$this->_route_regex = Route::compile($uri, $regex);
}
Saves or loads the route cache
If your routes will remain the same for a long period of time, use this to reload the routes from the cache rather than redefining them on every page load.
Set routes:
if ( ! Route::cache())
{
Route::cache(TRUE);
}
boolean
$save
= bool FALSE - Cache the current routes [Optional]boolean
$append
= bool FALSE - Append, rather than replace, cached routes when loading [Optional]void - When saving routesboolean - When loading routespublic static function cache($save = FALSE, $append = FALSE)
{
if ($save)
{
// Cache all defined routes
Kohana::cache('Route::cache()', Route::$_routes);
}
else
{
if ($routes = Kohana::cache('Route::cache()'))
{
if ($append)
{
// Append cached routes
Route::$_routes = Arr::merge(Route::$_routes, $routes);
}
else
{
// Replace existing routes
Route::$_routes = $routes;
}
// Routes were cached
return Route::$cache = TRUE;
}
else
{
// Routes were not cached
return Route::$cache = FALSE;
}
}
}
Route filters
Filters to be run before route parameters are returned.
Exmaple: $route->filter( function(Route $route, $params) { if ($params AND $params['controller'] === 'welcome') { $params['controller'] = 'home'; }
return $params;
}
);
To prevent a route from matching, return FALSE.
To replace the route parameters, return an array.
Default parameters are added before filters are called!
array
$callback
required - Callback string, array, or closureRoutepublic function filter($callback)
{
if ( ! is_callable($callback))
{
throw new Kohana_Exception('Invalid Route::callback specified');
}
$this->_filters[] = $callback;
return $this;
}
Fix for pagination on lambda routes
Tests if the route matches a given URI. A successful match will return all of the routed parameters as an array. A failed match will return boolean FALSE.
// Params: controller = users, action = edit, id = 10
$params = $route->matches('users/edit/10');
This method should almost always be used within an if/else block:
if ($params = $route->matches($uri))
{
// Parse the parameters
}
string
$uri
required - URI to matcharray - On successFALSE - On failurepublic function matches($uri)
{
if ( ! preg_match($this->_route_regex, $uri, $matches))
{
return FALSE;
}
$params = array();
foreach ($matches as $key => $value)
{
if (is_int($key))
{
// Skip all unnamed keys
continue;
}
// Set the value for all matched keys
$params[$key] = $value;
}
foreach ($this->_defaults as $key => $value)
{
if ( ! isset($params[$key]) OR $params[$key] === '')
{
// Set default values for any key that was not matched
$params[$key] = $value;
}
}
if ($this->_filters)
{
foreach ($this->_filters as $callback)
{
// Execute the filter
$return = call_user_func($callback, $uri, $this, $params);
if ($return === FALSE)
{
// Filter has aborted the match
return FALSE;
}
elseif (is_array($return))
{
// Filter has modified the parameters
$params = $return;
// fix for pagination on lambda routes
$this->_uri = Arr::get($params, 'uri', '');
}
}
}
return $params;
}
Retrieves all named routes.
$routes = Route::all();
array - Routes by namepublic static function all()
{
return Route::$_routes;
}
Returns the compiled regular expression for the route. This translates keys and optional groups to a proper PCRE regular expression.
$compiled = Route::compile(
'<controller>(/<action>(/<id>))',
array(
'controller' => '[a-z]+',
'id' => '\d+',
)
);
stringpublic static function compile($uri, array $regex = NULL)
{
if ( ! is_string($uri))
return;
// The URI should be considered literal except for keys and optional parts
// Escape everything preg_quote would escape except for : ( ) < >
$expression = preg_replace('#'.Route::REGEX_ESCAPE.'#', '\\\\$0', $uri);
if (strpos($expression, '(') !== FALSE)
{
// Make optional parts of the URI non-capturing and optional
$expression = str_replace(array('(', ')'), array('(?:', ')?'), $expression);
}
// Insert default regex for keys
$expression = str_replace(array('<', '>'), array('(?P<', '>'.Route::REGEX_SEGMENT.')'), $expression);
if ($regex)
{
$search = $replace = array();
foreach ($regex as $key => $value)
{
$search[] = "<$key>".Route::REGEX_SEGMENT;
$replace[] = "<$key>$value";
}
// Replace the default regex with the user-specified regex
$expression = str_replace($search, $replace, $expression);
}
return '#^'.$expression.'$#uD';
}
Provides default values for keys when they are not present. The default action will always be "index" unless it is overloaded here.
$route->defaults(array(
'controller' => 'welcome',
'action' => 'index'
));
If no parameter is passed, this method will act as a getter.
array
$defaults
= NULL - Key values$this - Or arraypublic function defaults(array $defaults = NULL)
{
if ($defaults === NULL)
{
return $this->_defaults;
}
$this->_defaults = $defaults;
return $this;
}
Retrieves a named route.
$route = Route::get('default');
string
$name
required - Route nameRoutepublic static function get($name)
{
if ( ! isset(Route::$_routes[$name]))
{
throw new Kohana_Exception('The requested route does not exist: :route',
array(':route' => $name));
}
return Route::$_routes[$name];
}
Returns whether this route is an external route to a remote controller.
booleanpublic function is_external()
{
return ! in_array(Arr::get($this->_defaults, 'host', FALSE), Route::$localhosts);
}
Get the name of a route.
$name = Route::name($route)
Route
$route
required - Instancestringpublic static function name(Route $route)
{
return array_search($route, Route::$_routes);
}
Stores a named route and returns it. The "action" will always be set to "index" if it is not defined.
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
));
string
$name
required - Route namestring
$uri_callback
= NULL - URI patternarray
$regex
= NULL - Regex patterns for route keysRoutepublic static function set($name, $uri_callback = NULL, $regex = NULL)
{
return Route::$_routes[$name] = new Route($uri_callback, $regex);
}
Generates a URI for the current route based on the parameters given.
// Using the "default" route: "users/profile/10"
$route->uri(array(
'controller' => 'users',
'action' => 'profile',
'id' => '10'
));
array
$params
= NULL - URI parametersstringpublic function uri(array $params = NULL)
{
// Start with the routed URI
$uri = $this->_uri;
if (strpos($uri, '<') === FALSE AND strpos($uri, '(') === FALSE)
{
// This is a static route, no need to replace anything
if ( ! $this->is_external())
return $uri;
// If the localhost setting does not have a protocol
if (strpos($this->_defaults['host'], '://') === FALSE)
{
// Use the default defined protocol
$params['host'] = Route::$default_protocol.$this->_defaults['host'];
}
else
{
// Use the supplied host with protocol
$params['host'] = $this->_defaults['host'];
}
// Compile the final uri and return it
return rtrim($params['host'], '/').'/'.$uri;
}
while (preg_match('#\([^()]++\)#', $uri, $match))
{
// Search for the matched value
$search = $match[0];
// Remove the parenthesis from the match as the replace
$replace = substr($match[0], 1, -1);
while (preg_match('#'.Route::REGEX_KEY.'#', $replace, $match))
{
list($key, $param) = $match;
if (isset($params[$param]))
{
// Replace the key with the parameter value
$replace = str_replace($key, $params[$param], $replace);
}
else
{
// This group has missing parameters
$replace = '';
break;
}
}
// Replace the group in the URI
$uri = str_replace($search, $replace, $uri);
}
while (preg_match('#'.Route::REGEX_KEY.'#', $uri, $match))
{
list($key, $param) = $match;
if ( ! isset($params[$param]))
{
// Look for a default
if (isset($this->_defaults[$param]))
{
$params[$param] = $this->_defaults[$param];
}
else
{
// Ungrouped parameters are required
throw new Kohana_Exception('Required route parameter not passed: :param', array(
':param' => $param,
));
}
}
$uri = str_replace($key, $params[$param], $uri);
}
// Trim all extra slashes from the URI
$uri = preg_replace('#//+#', '/', rtrim($uri, '/'));
if ($this->is_external())
{
// Need to add the host to the URI
$host = $this->_defaults['host'];
if (strpos($host, '://') === FALSE)
{
// Use the default defined protocol
$host = Route::$default_protocol.$host;
}
// Clean up the host and prepend it to the URI
$uri = rtrim($host, '/').'/'.$uri;
}
return $uri;
}
Create a URL from a route name. This is a shortcut for:
echo URL::site(Route::get($name)->uri($params), $protocol);
string
$name
required - Route namearray
$params
= NULL - URI parametersmixed
$protocol
= NULL - Protocol string or boolean, adds protocol and domainstringpublic static function url($name, array $params = NULL, $protocol = NULL)
{
$route = Route::get($name);
// Create a URI with the route and convert it to a URL
if ($route->is_external())
return Route::get($name)->uri($params);
else
return URL::site(Route::get($name)->uri($params), $protocol);
}