Source for file base.php
Documentation is available at base.php
* @package Joomla.Platform
* @subpackage Application
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Basic Web application router class for the Joomla Platform.
* @package Joomla.Platform
* @subpackage Application
* @var array An array of rules, each rule being an associative array('regex'=> $regex, 'vars' => $vars, 'controller' => $controller)
* for routing the request.
protected $maps =
array();
* Add a route map to the router. If the pattern already exists it will be overwritten.
* @param string $pattern The route pattern to use for matching.
* @param string $controller The controller name to map to the given pattern.
* @return JApplicationWebRouter This object for method chaining.
public function addMap($pattern, $controller)
// Sanitize and explode the pattern.
// Prepare the route variables
// Initialize regular expression
foreach ($pattern as $segment)
// Match a splat with no variable.
// Match a splat and capture the data to a named variable.
elseif ($segment[0] ==
'*')
$vars[] =
substr($segment, 1);
// Match an escaped splat segment.
elseif ($segment[0] ==
'\\' &&
$segment[1] ==
'*')
// Match an unnamed variable without capture.
// Match a named variable and capture the data.
elseif ($segment[0] ==
':')
$vars[] =
substr($segment, 1);
// Match a segment with an escaped variable character prefix.
elseif ($segment[0] ==
'\\' &&
$segment[1] ==
':')
// Match the standard segment.
'controller' => (string)
$controller
* Add a route map to the router. If the pattern already exists it will be overwritten.
* @param array $maps A list of route maps to add to the router as $pattern => $controller.
* @return JApplicationWebRouter This object for method chaining.
foreach ($maps as $pattern =>
$controller)
$this->addMap($pattern, $controller);
* Parse the given route and return the name of a controller mapped to the given route.
* @param string $route The route string for which to find and execute a controller.
* @return string The controller name for the given route excluding prefix.
* @throws InvalidArgumentException
// Trim the query string off.
// Sanitize and explode the route.
// If the route is empty then simply return the default route. No parsing necessary.
// Iterate through all of the known route maps looking for a match.
foreach ($this->maps as $rule)
// If we have gotten this far then we have a positive match.
$controller =
$rule['controller'];
// Time to set the input variables.
// We are only going to set them if they don't already exist to avoid overwriting things.
foreach ($rule['vars'] as $i =>
$var)
$this->input->def($var, $matches[$i +
1]);
// Don't forget to do an explicit set on the GET superglobal.
$this->input->get->def($var, $matches[$i +
1]);
$this->input->def('_rawRoute', $route);
// We were unable to find a route match for the request. Panic.
throw
new InvalidArgumentException(sprintf('Unable to handle request for route `%s`.', $route), 404);
Documentation generated on Tue, 19 Nov 2013 14:54:24 +0100 by phpDocumentor 1.4.3