Source for file router.php
Documentation is available at router.php
* @package Joomla.Libraries
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Set the available masks for the routing mode
const JROUTER_MODE_RAW =
0;
const JROUTER_MODE_SEF =
1;
* Class to create and parse routes
* @package Joomla.Libraries
* @deprecated 4.0 Will convert to $mode
protected $vars =
array();
* @deprecated 4.0 Will convert to $vars
* @deprecated 4.0 Will convert to $rules
* JRouter instances container.
protected static $instances =
array();
* @param array $options Array of options
$this->_mode =
$options['mode'];
$this->_mode =
JROUTER_MODE_RAW;
* Returns the global JRouter object, only creating it if it
* @param string $client The name of the client
* @param array $options An associative array of options
* @return JRouter A JRouter object.
* @throws RuntimeException
public static function getInstance($client, $options =
array())
if (empty(self::$instances[$client]))
// Create a JRouter object
$classname =
'JRouter' .
ucfirst($client);
// @deprecated 4.0 Everything in this block is deprecated but the warning is only logged after the file_exists
// Load the router object
$path =
$info->path .
'/includes/router.php';
JLog::add('Non-autoloadable JRouter subclasses are deprecated, support will be removed in 4.0.', JLog::WARNING, 'deprecated');
self::$instances[$client] =
new $classname($options);
throw
new RuntimeException(JText::sprintf('JLIB_APPLICATION_ERROR_ROUTER_LOAD', $client), 500);
return self::$instances[$client];
* Function to convert a route to an internal URI
* @param JUri &$uri The uri.
public function parse(&$uri)
// Process the parsed variables based on custom defined rules
if ($this->_mode ==
JROUTER_MODE_RAW)
if ($this->_mode ==
JROUTER_MODE_SEF)
* Function to convert an internal URI to a route
* @param string $url The internal URL
* @return string The absolute search engine friendly URL
public function build($url)
// Process the uri information based on custom defined rules
if ($this->_mode ==
JROUTER_MODE_RAW)
// Build SEF URL : mysite/route/index.php?var=x
if ($this->_mode ==
JROUTER_MODE_SEF)
* @param integer $mode The routing mode.
* Set a router variable, creating it if it doesn't exist
* @param string $key The name of the variable
* @param mixed $value The value of the variable
* @param boolean $create If True, the variable will be created if it doesn't exist yet
public function setVar($key, $value, $create =
true)
$this->_vars[$key] =
$value;
* Set the router variable array
* @param array $vars An associative array with variables
* @param boolean $merge If True, the array will be merged instead of overwritten
public function setVars($vars =
array(), $merge =
true)
* @param string $key The name of the variable
* @return mixed Value of the variable
if (isset
($this->_vars[$key]))
$result =
$this->_vars[$key];
* Get the router variable array
* @return array An associative array of router variables
* @param callback $callback The function to be called
$this->_rules['build'][] =
$callback;
* @param callback $callback The function to be called.
$this->_rules['parse'][] =
$callback;
* Function to convert a raw route to an internal URI
* @param JUri &$uri The raw route
* @deprecated 4.0 Use parseRawRoute() instead
* Function to convert a raw route to an internal URI
* @param JUri &$uri The raw route
* Function to convert a sef route to an internal URI
* @param JUri &$uri The sef URI
* @return string Internal URI
* @deprecated 4.0 Use parseSefRoute() instead
* Function to convert a sef route to an internal URI
* @param JUri &$uri The sef URI
* @return string Internal URI
* Function to build a raw route
* @param JUri &$uri The internal URL
* @return string Raw Route
* @deprecated 4.0 Use buildRawRoute() instead
* Function to build a raw route
* @param JUri &$uri The internal URL
* @return string Raw Route
* Function to build a sef route
* @param JUri &$uri The uri
* @return string The SEF route
* @deprecated 4.0 Use buildSefRoute() instead
* Function to build a sef route
* @param JUri &$uri The uri
* @return string The SEF route
* Process the parsed router variables based on custom defined rules
* @param JUri &$uri The URI to parse
* @return array The array of processed URI variables
* @deprecated 4.0 Use processParseRules() instead
* Process the parsed router variables based on custom defined rules
* @param JUri &$uri The URI to parse
* @return array The array of processed URI variables
foreach ($this->_rules['parse'] as $rule)
* Process the build uri query data based on custom defined rules
* @param JUri &$uri The URI
* @deprecated 4.0 Use processBuildRules() instead
* Process the build uri query data based on custom defined rules
* @param JUri &$uri The URI
foreach ($this->_rules['build'] as $rule)
* Create a uri based on a full or partial url string
* @param string $url The URI
* @deprecated 4.0 Use createURI() instead
* Create a uri based on a full or partial url string
* @param string $url The URI
// Create full URL if we are only appending variables to it
if (substr($url, 0, 1) ==
'&')
if (strpos($url, '&') !==
false)
foreach ($vars as $key =>
$var)
// Decompose link into url component parts
* @param array $segments An array of route segments
* @return array Array of encoded route segments
* @deprecated 4.0 Use encodeSegments() instead
* @param array $segments An array of route segments
* @return array Array of encoded route segments
$total =
count($segments);
for ($i =
0; $i <
$total; $i++
)
* @param array $segments An array of route segments
* @return array Array of decoded route segments
* @deprecated 4.0 Use decodeSegments() instead
* @param array $segments An array of route segments
* @return array Array of decoded route segments
$total =
count($segments);
for ($i =
0; $i <
$total; $i++
)
Documentation generated on Tue, 19 Nov 2013 15:12:28 +0100 by phpDocumentor 1.4.3