From f4a4bd8fac188ebc9cda822ffc811c218fd92b45 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Thu, 20 Oct 2011 12:18:42 -0500 Subject: adding new license file (OSL 3.0) and updating readme to ReST added notice of license to all source files. OSL to all except the few files we ship inside of the application folder, those are AFL. Updated license in user guide. incrementing next dev version to 3.0 due to licensing change --- system/core/Router.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 6da667472..748678d67 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -4,10 +4,22 @@ * * An open source application development framework for PHP 5.1.6 or newer * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. + * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 * @filesource @@ -22,7 +34,7 @@ * * @package CodeIgniter * @subpackage Libraries - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @category Libraries * @link http://codeigniter.com/user_guide/general/routing.html */ -- cgit v1.2.3-24-g4f1b From 5c1aa631c5f5ec2f6b75ba1158178418e50ba11a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 25 Dec 2011 01:24:29 -0600 Subject: Abstracting the loading of files in the config directory depending on environments. --- system/core/Router.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 748678d67..5388a9289 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -141,14 +141,7 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); - } - elseif (is_file(APPPATH.'config/routes.php')) - { - include(APPPATH.'config/routes.php'); - } + load_environ_config('routes'); $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); -- cgit v1.2.3-24-g4f1b From d96f88277c1e9a4c069c2e2ee3d779385549f31a Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 27 Dec 2011 16:23:47 -0600 Subject: Revert "Abstracting the loading of files in the config directory depending on environments." This reverts commit 5c1aa631c5f5ec2f6b75ba1158178418e50ba11a. --- system/core/Router.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5388a9289..748678d67 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -141,7 +141,14 @@ class CI_Router { } // Load the routes.php file. - load_environ_config('routes'); + if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + } + elseif (is_file(APPPATH.'config/routes.php')) + { + include(APPPATH.'config/routes.php'); + } $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; unset($route); -- cgit v1.2.3-24-g4f1b From 0defe5d33ee2633f377a109519ca818becc60f64 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Sun, 1 Jan 2012 18:46:41 -0600 Subject: Updating copyright date to 2012 --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 748678d67..8cad86888 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From ba6c04113313d49618b00c434fd5eedc6ab8a653 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 7 Jan 2012 21:10:09 +0200 Subject: Improve the core Router library --- system/core/Router.php | 107 +++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 70 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 8cad86888..d21319565 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -1,13 +1,13 @@ -config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); - log_message('debug', "Router Class Initialized"); + log_message('debug', 'Router Class Initialized'); } // -------------------------------------------------------------------- @@ -110,12 +103,11 @@ class CI_Router { * This function determines what should be served based on the URI request, * as well as any "routes" that have been set in the routing config file. * - * @access private * @return void */ - function _set_routing() + public function _set_routing() { - // Are query strings enabled in the config file? Normally CI doesn't utilize query strings + // Are query strings enabled in the config file? Normally CI doesn't utilize query strings // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently $segments = array(); @@ -157,7 +149,7 @@ class CI_Router { // the URI doesn't correlated to a valid controller. $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - // Were there any query string segments? If so, we'll validate them and bail out since we're done. + // Were there any query string segments? If so, we'll validate them and bail out since we're done. if (count($segments) > 0) { return $this->_validate_request($segments); @@ -172,17 +164,10 @@ class CI_Router { return $this->_set_default_controller(); } - // Do we need to remove the URL suffix? - $this->uri->_remove_url_suffix(); - - // Compile the segments into an array - $this->uri->_explode_segments(); - - // Parse any custom routing that may exist - $this->_parse_routes(); - - // Re-index the segment array so that it starts with 1 rather than 0 - $this->uri->_reindex_segments(); + $this->uri->_remove_url_suffix(); // Remove the URL suffix + $this->uri->_explode_segments(); // Compile the segments into an array + $this->_parse_routes(); // Parse any custom routing that may exist + $this->uri->_reindex_segments(); // Re-index the segment array so that it starts with 1 rather than 0 } // -------------------------------------------------------------------- @@ -190,20 +175,18 @@ class CI_Router { /** * Set the default controller * - * @access private * @return void */ - function _set_default_controller() + protected function _set_default_controller() { if ($this->default_controller === FALSE) { - show_error("Unable to determine what should be displayed. A default route has not been specified in the routing file."); + show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); } // Is the method being specified? if (strpos($this->default_controller, '/') !== FALSE) { $x = explode('/', $this->default_controller); - $this->set_class($x[0]); $this->set_method($x[1]); $this->_set_request($x); @@ -218,7 +201,7 @@ class CI_Router { // re-index the routed segments array so it starts with 1 rather than 0 $this->uri->_reindex_segments(); - log_message('debug', "No URI present. Default controller set."); + log_message('debug', 'No URI present. Default controller set.'); } // -------------------------------------------------------------------- @@ -229,16 +212,15 @@ class CI_Router { * This function takes an array of URI segments as * input, and sets the current class/method * - * @access private * @param array * @param bool * @return void */ - function _set_request($segments = array()) + protected function _set_request($segments = array()) { $segments = $this->_validate_request($segments); - if (count($segments) == 0) + if (count($segments) === 0) { return $this->_set_default_controller(); } @@ -269,13 +251,12 @@ class CI_Router { * Validates the supplied segments. Attempts to determine the path to * the controller. * - * @access private * @param array * @return array */ - function _validate_request($segments) + protected function _validate_request($segments) { - if (count($segments) == 0) + if (count($segments) === 0) { return $segments; } @@ -301,7 +282,6 @@ class CI_Router { if ( ! empty($this->routes['404_override'])) { $x = explode('/', $this->routes['404_override']); - $this->set_directory(''); $this->set_class($x[0]); $this->set_method(isset($x[1]) ? $x[1] : 'index'); @@ -320,7 +300,6 @@ class CI_Router { if (strpos($this->default_controller, '/') !== FALSE) { $x = explode('/', $this->default_controller); - $this->set_class($x[0]); $this->set_method($x[1]); } @@ -344,18 +323,16 @@ class CI_Router { // If we've gotten this far it means that the URI does not correlate to a valid - // controller class. We will now see if there is an override + // controller class. We will now see if there is an override if ( ! empty($this->routes['404_override'])) { $x = explode('/', $this->routes['404_override']); - $this->set_class($x[0]); $this->set_method(isset($x[1]) ? $x[1] : 'index'); return $x; } - // Nothing else to do at this point but show a 404 show_404($segments[0]); } @@ -369,10 +346,9 @@ class CI_Router { * the config/routes.php file against the URI to * determine if the class/method need to be remapped. * - * @access private * @return void */ - function _parse_routes() + protected function _parse_routes() { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); @@ -387,7 +363,7 @@ class CI_Router { foreach ($this->routes as $key => $val) { // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) @@ -412,11 +388,10 @@ class CI_Router { /** * Set the class name * - * @access public * @param string * @return void */ - function set_class($class) + public function set_class($class) { $this->class = str_replace(array('/', '.'), '', $class); } @@ -426,10 +401,9 @@ class CI_Router { /** * Fetch the current class * - * @access public * @return string */ - function fetch_class() + public function fetch_class() { return $this->class; } @@ -439,11 +413,10 @@ class CI_Router { /** * Set the method name * - * @access public * @param string * @return void */ - function set_method($method) + public function set_method($method) { $this->method = $method; } @@ -453,10 +426,9 @@ class CI_Router { /** * Fetch the current method * - * @access public * @return string */ - function fetch_method() + public function fetch_method() { if ($this->method == $this->fetch_class()) { @@ -471,11 +443,10 @@ class CI_Router { /** * Set the directory name * - * @access public * @param string * @return void */ - function set_directory($dir) + public function set_directory($dir) { $this->directory = str_replace(array('/', '.'), '', $dir).'/'; } @@ -485,10 +456,9 @@ class CI_Router { /** * Fetch the sub-directory (if any) that contains the requested controller class * - * @access public * @return string */ - function fetch_directory() + public function fetch_directory() { return $this->directory; } @@ -498,11 +468,10 @@ class CI_Router { /** * Set the controller overrides * - * @access public * @param array * @return null */ - function _set_overrides($routing) + public function _set_overrides($routing) { if ( ! is_array($routing)) { @@ -526,9 +495,7 @@ class CI_Router { } } - } -// END Router Class /* End of file Router.php */ -/* Location: ./system/core/Router.php */ \ No newline at end of file +/* Location: ./system/core/Router.php */ -- cgit v1.2.3-24-g4f1b From 07c1ac830b4e98aa40f48baef3dd05fb68c0a836 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Fri, 9 Mar 2012 17:03:37 +0000 Subject: Bumped CodeIgniter's PHP requirement to 5.2.4. Yes I know PHP 5.4 just came out, and yes I know PHP 5.3 has lovely features, but there are plenty of corporate systems running on CodeIgniter and PHP 5.3 still is not widely supported enough. CodeIgniter is great for distributed applications, and this is the highest we can reasonably go without breaking support. PHP 5.3 will most likely happen in another year or so. Fingers crossed on that one anyway... --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index d21319565..b251abb4b 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * -- cgit v1.2.3-24-g4f1b From 7b53d04eb4b89868307c65b7c64bc0889b25b4db Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Mar 2012 23:02:32 +0300 Subject: Some style adjustments and fixed comments in Router and Output classes --- system/core/Router.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index b251abb4b..5477fed5d 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -25,8 +25,6 @@ * @filesource */ -// ------------------------------------------------------------------------ - /** * Router Class * @@ -111,7 +109,7 @@ class CI_Router { // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently $segments = array(); - if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')])) + if ($this->config->item('enable_query_strings') === TRUE && isset($_GET[$this->config->item('controller_trigger')])) { if (isset($_GET[$this->config->item('directory_trigger')])) { @@ -133,7 +131,7 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } @@ -147,7 +145,7 @@ class CI_Router { // Set the default controller so we can display it in the event // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + $this->default_controller = empty($this->routes['default_controller']) ? FALSE : strtolower($this->routes['default_controller']); // Were there any query string segments? If so, we'll validate them and bail out since we're done. if (count($segments) > 0) @@ -248,8 +246,8 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Validates the supplied segments. Attempts to determine the path to - * the controller. + * Validates the supplied segments. + * Attempts to determine the path to the controller. * * @param array * @return array @@ -340,7 +338,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Parse Routes + * Parse Routes * * This function matches any routes that may exist in * the config/routes.php file against the URI to @@ -369,7 +367,7 @@ class CI_Router { if (preg_match('#^'.$key.'$#', $uri)) { // Do we have a back-reference? - if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { $val = preg_replace('#^'.$key.'$#', $val, $uri); } @@ -411,7 +409,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the method name + * Set the method name * * @param string * @return void @@ -424,7 +422,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the current method + * Fetch the current method * * @return string */ @@ -441,7 +439,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the directory name + * Set the directory name * * @param string * @return void @@ -454,7 +452,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the sub-directory (if any) that contains the requested controller class + * Fetch the sub-directory (if any) that contains the requested controller class * * @return string */ @@ -466,10 +464,10 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the controller overrides + * Set the controller overrides * * @param array - * @return null + * @return void */ public function _set_overrides($routing) { @@ -483,7 +481,7 @@ class CI_Router { $this->set_directory($routing['directory']); } - if (isset($routing['controller']) AND $routing['controller'] != '') + if (isset($routing['controller']) && $routing['controller'] != '') { $this->set_class($routing['controller']); } @@ -498,4 +496,4 @@ class CI_Router { } /* End of file Router.php */ -/* Location: ./system/core/Router.php */ +/* Location: ./system/core/Router.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ad4750509885ad5bb368fc308f86d8c06d45b15c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 19 Apr 2012 13:21:06 -0400 Subject: Normalize comments in core files --- system/core/Router.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5477fed5d..b34911859 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -211,7 +211,6 @@ class CI_Router { * input, and sets the current class/method * * @param array - * @param bool * @return void */ protected function _set_request($segments = array()) -- cgit v1.2.3-24-g4f1b From 40403d21274d5e0792c7ab816ad984d6387d5c20 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 19 Apr 2012 16:38:50 -0400 Subject: Additional formatting fixes --- system/core/Router.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index b34911859..b5c200214 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -44,36 +44,42 @@ class CI_Router { * @var object */ public $config; + /** * List of routes * * @var array */ - public $routes = array(); + public $routes = array(); + /** * List of error routes * * @var array */ - public $error_routes = array(); + public $error_routes = array(); + /** * Current class name * * @var string */ - public $class = ''; + public $class = ''; + /** * Current method name * * @var string */ - public $method = 'index'; + public $method = 'index'; + /** * Sub-directory that contains the requested controller class * * @var string */ - public $directory = ''; + public $directory = ''; + /** * Default controller (and method if specific) * -- cgit v1.2.3-24-g4f1b From 48a7fbbeb53e82e9298036d40c42ec2564699ed0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 23 Apr 2012 11:58:16 -0400 Subject: Use tabs to separate class properties --- system/core/Router.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index b5c200214..9314052fe 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -50,35 +50,35 @@ class CI_Router { * * @var array */ - public $routes = array(); + public $routes = array(); /** * List of error routes * * @var array */ - public $error_routes = array(); + public $error_routes = array(); /** * Current class name * * @var string */ - public $class = ''; + public $class = ''; /** * Current method name * * @var string */ - public $method = 'index'; + public $method = 'index'; /** * Sub-directory that contains the requested controller class * * @var string */ - public $directory = ''; + public $directory = ''; /** * Default controller (and method if specific) -- cgit v1.2.3-24-g4f1b From cdfbd5281e4dec7278a07943832c2590c1141eb3 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 26 Apr 2012 22:13:31 +0100 Subject: Fixed issue #122 - ruri_string() in subdirs. --- system/core/Router.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5477fed5d..fa88cb3dc 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -237,9 +237,12 @@ class CI_Router { $segments[1] = 'index'; } + // This is being routed to a file in a sub directory + $this->directory and array_unshift($segments, trim($this->directory, '/')); + // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments + // identical to $this->uri->segments $this->uri->rsegments = $segments; } -- cgit v1.2.3-24-g4f1b From 81aa94bbb533737c19a705d5b8864bd47fbab85c Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 2 May 2012 11:40:46 +0100 Subject: Reverted rui_string change. This had knock-on effects as can be seen in #1306. Issue #122 has been reopend until it is fixed properly. --- system/core/Router.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index fe9909b06..9314052fe 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -242,12 +242,9 @@ class CI_Router { $segments[1] = 'index'; } - // This is being routed to a file in a sub directory - $this->directory and array_unshift($segments, trim($this->directory, '/')); - // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments + // identical to $this->uri->segments $this->uri->rsegments = $segments; } -- cgit v1.2.3-24-g4f1b From 92ebfb65ac044f5c2e6d88fba137253854cf1b94 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 May 2012 12:49:24 +0300 Subject: Cleanup the core classes --- system/core/Router.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 9314052fe..5ea13797b 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -32,8 +32,8 @@ * * @package CodeIgniter * @subpackage Libraries - * @author EllisLab Dev Team * @category Libraries + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/general/routing.html */ class CI_Router { @@ -44,42 +44,42 @@ class CI_Router { * @var object */ public $config; - + /** * List of routes * * @var array */ public $routes = array(); - + /** * List of error routes * * @var array */ public $error_routes = array(); - + /** * Current class name * * @var string */ - public $class = ''; - + public $class = ''; + /** * Current method name * * @var string */ public $method = 'index'; - + /** * Sub-directory that contains the requested controller class * * @var string */ public $directory = ''; - + /** * Default controller (and method if specific) * @@ -91,6 +91,8 @@ class CI_Router { * Constructor * * Runs the route mapping function. + * + * @return void */ public function __construct() { @@ -433,12 +435,7 @@ class CI_Router { */ public function fetch_method() { - if ($this->method == $this->fetch_class()) - { - return 'index'; - } - - return $this->method; + return ($this->method == $this->fetch_class()) ? 'index' : $this->method; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ed944a3c70a0bad158cd5a6ca5ce1f2e717aff5d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:07:47 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /system/core --- system/core/Router.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5ea13797b..93875bdd9 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -165,7 +165,7 @@ class CI_Router { $this->uri->_fetch_uri_string(); // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri->uri_string == '') + if ($this->uri->uri_string === '') { return $this->_set_default_controller(); } @@ -435,7 +435,7 @@ class CI_Router { */ public function fetch_method() { - return ($this->method == $this->fetch_class()) ? 'index' : $this->method; + return ($this->method === $this->fetch_class()) ? 'index' : $this->method; } // -------------------------------------------------------------------- @@ -483,14 +483,14 @@ class CI_Router { $this->set_directory($routing['directory']); } - if (isset($routing['controller']) && $routing['controller'] != '') + if (isset($routing['controller']) && $routing['controller'] !== '') { $this->set_class($routing['controller']); } if (isset($routing['function'])) { - $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function']; + $routing['function'] = ($routing['function'] === '') ? 'index' : $routing['function']; $this->set_method($routing['function']); } } -- cgit v1.2.3-24-g4f1b From 9ba661b02c492e89028e5c67b7edbfc0efefc9f1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 4 Jun 2012 14:44:34 +0300 Subject: Revert/optimize some changes from ed944a3c70a0bad158cd5a6ca5ce1f2e717aff5d --- system/core/Router.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 93875bdd9..5bc053045 100755 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -165,7 +165,7 @@ class CI_Router { $this->uri->_fetch_uri_string(); // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri->uri_string === '') + if ($this->uri->uri_string == '') { return $this->_set_default_controller(); } @@ -483,14 +483,14 @@ class CI_Router { $this->set_directory($routing['directory']); } - if (isset($routing['controller']) && $routing['controller'] !== '') + if ( ! empty($routing['controller'])) { $this->set_class($routing['controller']); } if (isset($routing['function'])) { - $routing['function'] = ($routing['function'] === '') ? 'index' : $routing['function']; + $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function']; $this->set_method($routing['function']); } } -- cgit v1.2.3-24-g4f1b From 0d2c06ea1d96ea3f35dd1e7856977a24cec43233 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 12 Jun 2012 02:33:45 +0300 Subject: Change file permissions for system/core/*.php and system/database/DB.php so that they don't differ from the rest --- system/core/Router.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 system/core/Router.php (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php old mode 100755 new mode 100644 -- cgit v1.2.3-24-g4f1b From a101c93b93b43ac98370bb0a1378a82ff44e4e1a Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Fri, 20 Jul 2012 12:23:43 +0200 Subject: allow for routes that can be processed with php, ex: $route['([^/]+)/([^/]+)(/:any)?'] = 'php:"$1" . "/do" . ucfirst("$2") . "$3"'; --- system/core/Router.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5bc053045..cb7df5320 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -86,6 +86,13 @@ class CI_Router { * @var string */ public $default_controller; + + /** + * Prepend used in php processed routes + * + * @var string + */ + public $route_prepend = 'php:'; /** * Constructor @@ -373,10 +380,16 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) { + // Are we using php functions to process matches? + $modifier = strpos($val, $this->route_prepend) === 0? 'e': ''; + + // If we have the 'e' modifier, remove the prepend from the route value. + $val = $modifier === 'e'? substr($val, strlen($this->route_prepend)): $val; + // Do we have a back-reference? if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { - $val = preg_replace('#^'.$key.'$#', $val, $uri); + $val = preg_replace('#^'.$key.'$#'.$modifier, $val, $uri); } return $this->_set_request(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 80275c7ee050ed42678d68a752e0c282f0240752 Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Wed, 1 Aug 2012 19:15:48 +0200 Subject: Added possibility of using callbacks. --- system/core/Router.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index cb7df5320..727e85f7e 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -380,16 +380,35 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) { - // Are we using php functions to process matches? - $modifier = strpos($val, $this->route_prepend) === 0? 'e': ''; + // Are we using a callback? + $callable = is_callable($val); + + // Determine the appropriate preg_replace to use. + $preg_replace_type = $callable? 'preg_replace_callback': 'preg_replace'; + + // Are we using the route_prepend to change how we process the matches? + $modifier = (is_string($val) AND strpos($val, $this->route_prepend) === 0)? 'e': ''; - // If we have the 'e' modifier, remove the prepend from the route value. - $val = $modifier === 'e'? substr($val, strlen($this->route_prepend)): $val; + // Are we using callbacks to process the matches? + if($callable){ + $val = function($matches)use($val){ + // Remove the string we are matching against from the matches array. + array_shift($matches); + + // Distribute the matches to the arguments of the user's callback. + return call_user_func_array($val, $matches); + }; + } + else + { + // Remove the "php:" portion of the string if it exists. + $val = $modifier === 'e'? substr($val, strlen($this->route_prepend)): $val; + } // Do we have a back-reference? - if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) + if ($callable OR (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)) { - $val = preg_replace('#^'.$key.'$#'.$modifier, $val, $uri); + $val = call_user_func($preg_replace_type, '#^'.$key.'$#'.$modifier, $val, $uri); } return $this->_set_request(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From 0af2d4ffd1735e24dd4f5ee9b17ac6a90508c1e9 Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 13:05:15 +0200 Subject: revert changes to routing system - part 1 --- system/core/Router.php | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 727e85f7e..5bc053045 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -86,13 +86,6 @@ class CI_Router { * @var string */ public $default_controller; - - /** - * Prepend used in php processed routes - * - * @var string - */ - public $route_prepend = 'php:'; /** * Constructor @@ -380,35 +373,10 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) { - // Are we using a callback? - $callable = is_callable($val); - - // Determine the appropriate preg_replace to use. - $preg_replace_type = $callable? 'preg_replace_callback': 'preg_replace'; - - // Are we using the route_prepend to change how we process the matches? - $modifier = (is_string($val) AND strpos($val, $this->route_prepend) === 0)? 'e': ''; - - // Are we using callbacks to process the matches? - if($callable){ - $val = function($matches)use($val){ - // Remove the string we are matching against from the matches array. - array_shift($matches); - - // Distribute the matches to the arguments of the user's callback. - return call_user_func_array($val, $matches); - }; - } - else - { - // Remove the "php:" portion of the string if it exists. - $val = $modifier === 'e'? substr($val, strlen($this->route_prepend)): $val; - } - // Do we have a back-reference? - if ($callable OR (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE)) + if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { - $val = call_user_func($preg_replace_type, '#^'.$key.'$#'.$modifier, $val, $uri); + $val = preg_replace('#^'.$key.'$#', $val, $uri); } return $this->_set_request(explode('/', $val)); -- cgit v1.2.3-24-g4f1b From c0d98b296186e6206dfa88476199559e630d06d0 Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 15:42:50 +0100 Subject: New optional routing system, v3 --- system/core/Router.php | 90 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 33 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5bc053045..a5d01b1ee 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -354,39 +354,63 @@ class CI_Router { * @return void */ protected function _parse_routes() - { - // Turn the segment array into a URI string - $uri = implode('/', $this->uri->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - return $this->_set_request(explode('/', $this->routes[$uri])); - } - - // Loop through the route array looking for wild-cards - foreach ($this->routes as $key => $val) - { - // Convert wild-cards to RegEx - $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); - - // Does the RegEx match? - if (preg_match('#^'.$key.'$#', $uri)) - { - // Do we have a back-reference? - if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } - - return $this->_set_request(explode('/', $val)); - } - } - - // If we got this far it means we didn't encounter a - // matching route so we'll set the site default route - $this->_set_request($this->uri->segments); - } + { + // Turn the segment array into a URI string + $uri = implode('/', $this->uri->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + return $this->_set_request(explode('/', $this->routes[$uri])); + } + + // Loop through the route array looking for wild-cards + foreach ($this->routes as $key => $val) + { + // Convert wild-cards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the RegEx match? + if (preg_match('#^'.$key.'$#', $uri, $matches)) + { + // Are we using a callback? + $callable = is_callable($val); + + // Are we using callbacks to process back-references? + if($callable){ + // Remove the original string from the matches array. + array_shift($matches); + + // Get the match count. + $matchCount = count($matches); + + // Determine how many parameters the callback has. + $reflection = new ReflectionFunction($val); + $paramCount = count($reflection->getParameters()); + + // Are there more parameters than matches? + if($paramCount > $matchCount){ + // Set any extra params to empty string. + $matches = array_merge($matches, array_fill($matchCount, $paramCount - $matchCount, '')); + } + + // execute callback using matches as its parameters. + $val = call_user_func_array($val, $matches); + } + // Are we using the default routing method for back-references? + else if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } + + return $this->_set_request(explode('/', $val)); + } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_set_request($this->uri->segments); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3b45cf62bec6684f35207a1bfb2193f1adc9cd2b Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 15:47:24 +0100 Subject: Fixed a bug when detecting if the user used a callback. --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index a5d01b1ee..d6788c314 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -374,7 +374,7 @@ class CI_Router { if (preg_match('#^'.$key.'$#', $uri, $matches)) { // Are we using a callback? - $callable = is_callable($val); + $callable = ! is_string($val) && is_callable($val); // Are we using callbacks to process back-references? if($callable){ -- cgit v1.2.3-24-g4f1b From 07264381020d730ebba9ae95688b73c25e523e54 Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 16:37:26 +0100 Subject: Corrected code style to be inline with project conventions. --- system/core/Router.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index d6788c314..081468944 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -377,24 +377,26 @@ class CI_Router { $callable = ! is_string($val) && is_callable($val); // Are we using callbacks to process back-references? - if($callable){ + if($callable) + { // Remove the original string from the matches array. array_shift($matches); // Get the match count. - $matchCount = count($matches); + $match_count = count($matches); // Determine how many parameters the callback has. $reflection = new ReflectionFunction($val); - $paramCount = count($reflection->getParameters()); + $param_count = count($reflection->getParameters()); // Are there more parameters than matches? - if($paramCount > $matchCount){ - // Set any extra params to empty string. - $matches = array_merge($matches, array_fill($matchCount, $paramCount - $matchCount, '')); + if($param_count > $match_count) + { + // Any params without matches will be set to an empty string. + $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); } - // execute callback using matches as its parameters. + // Execute the callback using the values in matches as its parameters. $val = call_user_func_array($val, $matches); } // Are we using the default routing method for back-references? -- cgit v1.2.3-24-g4f1b From cf168303ead21d1c8ad89af01458806e6be197fd Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Mon, 6 Aug 2012 17:10:17 +0100 Subject: Updated documentation --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 081468944..b11aa9ba5 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -387,7 +387,7 @@ class CI_Router { // Determine how many parameters the callback has. $reflection = new ReflectionFunction($val); - $param_count = count($reflection->getParameters()); + $param_count = $reflection->getNumberOfParameters(); // Are there more parameters than matches? if($param_count > $match_count) -- cgit v1.2.3-24-g4f1b From 59dbe859ffea8159932f6d28b765de615d430cf4 Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Tue, 7 Aug 2012 12:13:32 +0100 Subject: Changed spaces to tabs where necessary. --- system/core/Router.php | 118 ++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index b11aa9ba5..1d566c56f 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -354,65 +354,65 @@ class CI_Router { * @return void */ protected function _parse_routes() - { - // Turn the segment array into a URI string - $uri = implode('/', $this->uri->segments); - - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - return $this->_set_request(explode('/', $this->routes[$uri])); - } - - // Loop through the route array looking for wild-cards - foreach ($this->routes as $key => $val) - { - // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); - - // Does the RegEx match? - if (preg_match('#^'.$key.'$#', $uri, $matches)) - { - // Are we using a callback? - $callable = ! is_string($val) && is_callable($val); - - // Are we using callbacks to process back-references? - if($callable) - { - // Remove the original string from the matches array. - array_shift($matches); - - // Get the match count. - $match_count = count($matches); - - // Determine how many parameters the callback has. - $reflection = new ReflectionFunction($val); - $param_count = $reflection->getNumberOfParameters(); - - // Are there more parameters than matches? - if($param_count > $match_count) - { - // Any params without matches will be set to an empty string. - $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); - } - - // Execute the callback using the values in matches as its parameters. - $val = call_user_func_array($val, $matches); - } - // Are we using the default routing method for back-references? - else if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } - - return $this->_set_request(explode('/', $val)); - } - } - - // If we got this far it means we didn't encounter a - // matching route so we'll set the site default route - $this->_set_request($this->uri->segments); - } + { + // Turn the segment array into a URI string + $uri = implode('/', $this->uri->segments); + + // Is there a literal match? If so we're done + if (isset($this->routes[$uri])) + { + return $this->_set_request(explode('/', $this->routes[$uri])); + } + + // Loop through the route array looking for wild-cards + foreach ($this->routes as $key => $val) + { + // Convert wild-cards to RegEx + $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + + // Does the RegEx match? + if (preg_match('#^'.$key.'$#', $uri, $matches)) + { + // Are we using a callback? + $callable = ! is_string($val) && is_callable($val); + + // Are we using callbacks to process back-references? + if($callable) + { + // Remove the original string from the matches array. + array_shift($matches); + + // Get the match count. + $match_count = count($matches); + + // Determine how many parameters the callback has. + $reflection = new ReflectionFunction($val); + $param_count = $reflection->getNumberOfParameters(); + + // Are there more parameters than matches? + if($param_count > $match_count) + { + // Any params without matches will be set to an empty string. + $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); + } + + // Execute the callback using the values in matches as its parameters. + $val = call_user_func_array($val, $matches); + } + // Are we using the default routing method for back-references? + else if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } + + return $this->_set_request(explode('/', $val)); + } + } + + // If we got this far it means we didn't encounter a + // matching route so we'll set the site default route + $this->_set_request($this->uri->segments); + } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f950e5c18d7a36408e33cb11bb67a254362607cc Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 27 Sep 2012 11:39:33 +0100 Subject: made some corrections to the code --- system/core/Router.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 1d566c56f..0e915521d 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -368,16 +368,13 @@ class CI_Router { foreach ($this->routes as $key => $val) { // Convert wild-cards to RegEx - $key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key)); + $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri, $matches)) { - // Are we using a callback? - $callable = ! is_string($val) && is_callable($val); - // Are we using callbacks to process back-references? - if($callable) + if(! is_string($val) && is_callable($val)) { // Remove the original string from the matches array. array_shift($matches); @@ -400,7 +397,7 @@ class CI_Router { $val = call_user_func_array($val, $matches); } // Are we using the default routing method for back-references? - else if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) + elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) { $val = preg_replace('#^'.$key.'$#', $val, $uri); } -- cgit v1.2.3-24-g4f1b From 24296ca1e940ac32841cc24a5fdc2f49a0f8ec8a Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Thu, 27 Sep 2012 12:10:01 +0100 Subject: corrected a few more style problems --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 0e915521d..3428ff07b 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -374,7 +374,7 @@ class CI_Router { if (preg_match('#^'.$key.'$#', $uri, $matches)) { // Are we using callbacks to process back-references? - if(! is_string($val) && is_callable($val)) + if ( ! is_string($val) && is_callable($val)) { // Remove the original string from the matches array. array_shift($matches); @@ -387,7 +387,7 @@ class CI_Router { $param_count = $reflection->getNumberOfParameters(); // Are there more parameters than matches? - if($param_count > $match_count) + if ($param_count > $match_count) { // Any params without matches will be set to an empty string. $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); -- cgit v1.2.3-24-g4f1b From efb81669b8f90352fdabd109e14fdec25bbce8fe Mon Sep 17 00:00:00 2001 From: Jonatas Miguel Date: Tue, 23 Oct 2012 19:52:46 +0100 Subject: users' default values are now respected in callback routes --- system/core/Router.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 3428ff07b..e8addf962 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -391,6 +391,21 @@ class CI_Router { { // Any params without matches will be set to an empty string. $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); + + $match_count = $param_count; + } + + // Get the parameters so we can use their default values. + $params = $reflection->getParameters(); + + for ($m = 0; $m < $match_count; $m++) + { + // Is the match empty and does a default value exist? + if (empty($matches[$m]) && $params[$m]->isDefaultValueAvailable()) + { + // Substitute the empty match for the default value. + $matches[$m] = $params[$m]->getDefaultValue(); + } } // Execute the callback using the values in matches as its parameters. -- cgit v1.2.3-24-g4f1b From b9fe7e9be099f450747de6ed28d400764ffc58b3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 18:45:59 +0300 Subject: [ci skip] Router class DocBlock improvements --- system/core/Router.php | 67 ++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 32 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 5bc053045..efee2439f 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -39,56 +39,56 @@ class CI_Router { /** - * Config class + * CI_Config class object * - * @var object + * @var object */ public $config; /** * List of routes * - * @var array + * @var array */ public $routes = array(); /** * List of error routes * - * @var array + * @var array */ public $error_routes = array(); /** * Current class name * - * @var string + * @var string */ public $class = ''; /** * Current method name * - * @var string + * @var string */ public $method = 'index'; /** * Sub-directory that contains the requested controller class * - * @var string + * @var string */ public $directory = ''; /** * Default controller (and method if specific) * - * @var string + * @var string */ public $default_controller; /** - * Constructor + * Class constructor * * Runs the route mapping function. * @@ -104,9 +104,9 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the route mapping + * Set route mapping * - * This function determines what should be served based on the URI request, + * Determines what should be served based on the URI request, * as well as any "routes" that have been set in the routing config file. * * @return void @@ -179,7 +179,7 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the default controller + * Set default controller * * @return void */ @@ -213,12 +213,12 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the Route + * Set request route * - * This function takes an array of URI segments as - * input, and sets the current class/method + * Takes an array of URI segments as input and sets the class/method + * to be called. * - * @param array + * @param array $segments URI segments * @return void */ protected function _set_request($segments = array()) @@ -253,11 +253,12 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Validates the supplied segments. - * Attempts to determine the path to the controller. + * Validate request * - * @param array - * @return array + * Attempts validate the URI request and determine the controller path. + * + * @param array $segments URI segments + * @return array URI segments */ protected function _validate_request($segments) { @@ -347,9 +348,8 @@ class CI_Router { /** * Parse Routes * - * This function matches any routes that may exist in - * the config/routes.php file against the URI to - * determine if the class/method need to be remapped. + * Matches any routes that may exist in the config/routes.php file + * against the URI to determine if the class/method need to be remapped. * * @return void */ @@ -391,9 +391,9 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the class name + * Set class name * - * @param string + * @param string $class Class name * @return void */ public function set_class($class) @@ -416,9 +416,9 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the method name + * Set method name * - * @param string + * @param string $method Method name * @return void */ public function set_method($method) @@ -441,9 +441,9 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the directory name + * Set directory name * - * @param string + * @param string $dir Directory name * @return void */ public function set_directory($dir) @@ -454,7 +454,10 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Fetch the sub-directory (if any) that contains the requested controller class + * Fetch directory + * + * Feches the sub-directory (if any) that contains the requested + * controller class. * * @return string */ @@ -466,9 +469,9 @@ class CI_Router { // -------------------------------------------------------------------- /** - * Set the controller overrides + * Set controller overrides * - * @param array + * @param array $routing Route overrides * @return void */ public function _set_overrides($routing) -- cgit v1.2.3-24-g4f1b From 7676c2d6761cb3cdeccf005c2a30140f0ba3ced5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 30 Oct 2012 13:42:01 +0200 Subject: Fix issue #658 (:any wildcard matching slashes) --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index efee2439f..a5e29f1a3 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -368,7 +368,7 @@ class CI_Router { foreach ($this->routes as $key => $val) { // Convert wild-cards to RegEx - $key = str_replace(array(':any', ':num'), array('.+', '[0-9]+'), $key); + $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri)) -- cgit v1.2.3-24-g4f1b From c5536aac5752054f7f76e448d58b86407d8f574e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Nov 2012 17:33:58 +0200 Subject: Manually apply PR #1594 (fixing phpdoc page-level generation/warnings) Also partially fixes issue #1295, fixes inconsistencies in some page-level docblocks and adds include checks in language files. --- system/core/Router.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 529cbb7c8..87f3e9e63 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -1,4 +1,4 @@ - Date: Thu, 1 Nov 2012 19:55:42 +0200 Subject: Allow use of dashes in controller/method URI segments Supersedes PR #642 --- system/core/Router.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 87f3e9e63..89fb74f2f 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -190,6 +190,7 @@ class CI_Router { { show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); } + // Is the method being specified? if (strpos($this->default_controller, '/') !== FALSE) { @@ -268,9 +269,13 @@ class CI_Router { return $segments; } + $temp = str_replace('-', '_', $segments[0]); + // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$segments[0].'.php')) + if (file_exists(APPPATH.'controllers/'.$temp.'.php')) { + $segments[0] = $temp; + empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); return $segments; } @@ -283,6 +288,9 @@ class CI_Router { if (count($segments) > 0) { + $segments[0] = str_replace('-', '_', $segments[0]); + empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); + // Does the requested controller exist in the sub-folder? if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) { -- cgit v1.2.3-24-g4f1b From 7d394f8cc75dff27324279bfbaffb1a487ea6dc7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 04:37:34 +0200 Subject: Router-related optimizations An improved version of changes suggesed in PR #1352, and more specifically: https://github.com/sourcejedi/CodeIgniter/commit/8f7d2dfe42bd8543981c0f295e391e433d82fd42 https://github.com/sourcejedi/CodeIgniter/commit/d2de251c092d9d822fc4898e3681b64e9c74dd2a (thanks again @sourcejedi) --- system/core/Router.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 89fb74f2f..48c157f18 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -53,13 +53,6 @@ class CI_Router { */ public $routes = array(); - /** - * List of error routes - * - * @var array - */ - public $error_routes = array(); - /** * Current class name * -- cgit v1.2.3-24-g4f1b From 533bf2dd5f36e277a9ee6629ccd667a32b05d154 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Nov 2012 22:44:29 +0200 Subject: Fix a directory/404_override bug and some routing-related optimizations --- system/core/Router.php | 76 ++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 55 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 48c157f18..67e9b300d 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -142,7 +142,7 @@ class CI_Router { include(APPPATH.'config/routes.php'); } - $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route; + $this->routes = (isset($route) && is_array($route)) ? $route : array(); unset($route); // Set the default controller so we can display it in the event @@ -179,26 +179,21 @@ class CI_Router { */ protected function _set_default_controller() { - if ($this->default_controller === FALSE) + if (empty($this->default_controller)) { show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); } // Is the method being specified? - if (strpos($this->default_controller, '/') !== FALSE) + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) { - $x = explode('/', $this->default_controller); - $this->set_class($x[0]); - $this->set_method($x[1]); - $this->_set_request($x); - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - $this->_set_request(array($this->default_controller, 'index')); + $method = 'index'; } + $this->set_class($class); + $this->set_method($method); + $this->_set_request(array($class, $method)); + // re-index the routed segments array so it starts with 1 rather than 0 $this->uri->_reindex_segments(); @@ -227,17 +222,8 @@ class CI_Router { $this->set_class($segments[0]); - if (isset($segments[1])) - { - // A standard method request - $this->set_method($segments[1]); - } - else - { - // This lets the "routed" segment array identify that the default - // index method is being used. - $segments[1] = 'index'; - } + isset($segments[1]) OR $segments[1] = 'index'; + $this->set_method($segments[1]); // Update our "routed" segment array to contain the segments. // Note: If there is no custom routing, this array will be @@ -276,9 +262,7 @@ class CI_Router { if (is_dir(APPPATH.'controllers/'.$segments[0])) { // Set the directory and remove it from the segment array - $this->set_directory($segments[0]); - $segments = array_slice($segments, 1); - + $this->set_directory(array_shift($segments)); if (count($segments) > 0) { $segments[0] = str_replace('-', '_', $segments[0]); @@ -289,12 +273,8 @@ class CI_Router { { if ( ! empty($this->routes['404_override'])) { - $x = explode('/', $this->routes['404_override']); - $this->set_directory(''); - $this->set_class($x[0]); - $this->set_method(isset($x[1]) ? $x[1] : 'index'); - - return $x; + $this->directory = ''; + return explode('/', $this->routes['404_override'], 2); } else { @@ -305,40 +285,26 @@ class CI_Router { else { // Is the method being specified in the route? - if (strpos($this->default_controller, '/') !== FALSE) - { - $x = explode('/', $this->default_controller); - $this->set_class($x[0]); - $this->set_method($x[1]); - } - else - { - $this->set_class($this->default_controller); - $this->set_method('index'); - } - - // Does the default controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.'.php')) + $segments = explode('/', $this->default_controller); + if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) { $this->directory = ''; - return array(); } - } return $segments; } - // If we've gotten this far it means that the URI does not correlate to a valid // controller class. We will now see if there is an override if ( ! empty($this->routes['404_override'])) { - $x = explode('/', $this->routes['404_override']); - $this->set_class($x[0]); - $this->set_method(isset($x[1]) ? $x[1] : 'index'); + if (sscanf($this->routes['404_override'], '%[^/]/%s', $class, $method) !== 2) + { + $method = 'index'; + } - return $x; + return array($class, $method); } // Nothing else to do at this point but show a 404 @@ -533,7 +499,7 @@ class CI_Router { if (isset($routing['function'])) { - $routing['function'] = ($routing['function'] == '') ? 'index' : $routing['function']; + $routing['function'] = empty($routing['function']) ? 'index' : $routing['function']; $this->set_method($routing['function']); } } -- cgit v1.2.3-24-g4f1b From a3f5c5c78f6172565e3264764e1de7dcad894b0a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 4 Nov 2012 20:08:42 +0200 Subject: Fix #98 --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 67e9b300d..30bf39657 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -147,7 +147,7 @@ class CI_Router { // Set the default controller so we can display it in the event // the URI doesn't correlated to a valid controller. - $this->default_controller = empty($this->routes['default_controller']) ? FALSE : strtolower($this->routes['default_controller']); + $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller']; // Were there any query string segments? If so, we'll validate them and bail out since we're done. if (count($segments) > 0) -- cgit v1.2.3-24-g4f1b From 96ea52894aea85b86d75f59fee35f90676735060 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 11:34:00 +0200 Subject: Change route type checks priorities --- system/core/Router.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 30bf39657..3ef55cee2 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -341,8 +341,13 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri, $matches)) { + // Are we using the default routing method for back-references? + if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } // Are we using callbacks to process back-references? - if ( ! is_string($val) && is_callable($val)) + elseif ( ! is_string($val) && is_callable($val)) { // Remove the original string from the matches array. array_shift($matches); @@ -379,11 +384,6 @@ class CI_Router { // Execute the callback using the values in matches as its parameters. $val = call_user_func_array($val, $matches); } - // Are we using the default routing method for back-references? - elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } return $this->_set_request(explode('/', $val)); } -- cgit v1.2.3-24-g4f1b From da5562a4bd87ad8ea827298dbe60e850225cfe34 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 12:34:38 +0200 Subject: Revert 96ea52894aea85b86d75f59fee35f90676735060 --- system/core/Router.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 3ef55cee2..30bf39657 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -341,13 +341,8 @@ class CI_Router { // Does the RegEx match? if (preg_match('#^'.$key.'$#', $uri, $matches)) { - // Are we using the default routing method for back-references? - if (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) - { - $val = preg_replace('#^'.$key.'$#', $val, $uri); - } // Are we using callbacks to process back-references? - elseif ( ! is_string($val) && is_callable($val)) + if ( ! is_string($val) && is_callable($val)) { // Remove the original string from the matches array. array_shift($matches); @@ -384,6 +379,11 @@ class CI_Router { // Execute the callback using the values in matches as its parameters. $val = call_user_func_array($val, $matches); } + // Are we using the default routing method for back-references? + elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) + { + $val = preg_replace('#^'.$key.'$#', $val, $uri); + } return $this->_set_request(explode('/', $val)); } -- cgit v1.2.3-24-g4f1b From e2b0754c4ea3fe227bc80a546f4d5cbd88a1e24e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 8 Nov 2012 12:37:40 +0200 Subject: Another router fix for the dumbest usage of callbacks ever --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 30bf39657..01f44bc83 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -327,7 +327,7 @@ class CI_Router { $uri = implode('/', $this->uri->segments); // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) + if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) { return $this->_set_request(explode('/', $this->routes[$uri])); } -- cgit v1.2.3-24-g4f1b From 9515dd372ed07dca9dcf728f31943d4a1d104112 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 7 Dec 2012 15:15:15 +0200 Subject: Fix issue #2061 --- system/core/Router.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 01f44bc83..76772a0fb 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -111,21 +111,21 @@ class CI_Router { // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently $segments = array(); - if ($this->config->item('enable_query_strings') === TRUE && isset($_GET[$this->config->item('controller_trigger')])) + if ($this->config->item('enable_query_strings') === TRUE + && ! empty($_GET[$this->config->item('controller_trigger')]) + && is_string($_GET[$this->config->item('controller_trigger')]) + ) { - if (isset($_GET[$this->config->item('directory_trigger')])) + if (isset($_GET[$this->config->item('directory_trigger')]) && is_string($_GET[$this->config->item('directory_trigger')])) { $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); $segments[] = $this->fetch_directory(); } - if (isset($_GET[$this->config->item('controller_trigger')])) - { - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - $segments[] = $this->fetch_class(); - } + $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + $segments[] = $this->fetch_class(); - if (isset($_GET[$this->config->item('function_trigger')])) + if ( ! empty($_GET[$this->config->item('function_trigger')]) && is_string($_GET[$this->config->item('function_trigger')])) { $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); $segments[] = $this->fetch_method(); @@ -142,7 +142,7 @@ class CI_Router { include(APPPATH.'config/routes.php'); } - $this->routes = (isset($route) && is_array($route)) ? $route : array(); + $this->routes = (empty($route) OR ! is_array($route)) ? array() : $route; unset($route); // Set the default controller so we can display it in the event -- cgit v1.2.3-24-g4f1b From 80500afbd188600212ca913a7bac073009feac73 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Jan 2013 08:16:53 +0200 Subject: [ci skip] Happy new year --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 76772a0fb..f284e29cc 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From db529ca1e13e9f9e1c73be20c3b92a7adc3c6aa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Jan 2013 11:00:02 +0200 Subject: Remove unnecessary defined('ENVIRONMENT') checks As suggested in issue #2134 & PR #2149 --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index f284e29cc..4755b3712 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -133,7 +133,7 @@ class CI_Router { } // Load the routes.php file. - if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } -- cgit v1.2.3-24-g4f1b From 0687911229be13e100724dbf8b15b95146b591a9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 29 Jan 2013 15:05:02 +0200 Subject: Replace is_file() with the faster file_exists() (where it makes sense) Also: - Implemented caching of configuration arrays for smileys, foreign characters and doctypes. - Implemented cascading-style loading of configuration files (except for library configs, DB and constants.php). --- system/core/Router.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 4755b3712..bb0ce16bd 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -133,13 +133,14 @@ class CI_Router { } // Load the routes.php file. - if (is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + if (file_exists(APPPATH.'config/routes.php')) { - include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + include(APPPATH.'config/routes.php'); } - elseif (is_file(APPPATH.'config/routes.php')) + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) { - include(APPPATH.'config/routes.php'); + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } $this->routes = (empty($route) OR ! is_array($route)) ? array() : $route; -- cgit v1.2.3-24-g4f1b From 0e4237f8fb01320fb7cc87b1fb93a552630505d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Apr 2013 16:53:21 +0300 Subject: Fix #2380 and deprecate CI_Router::fetch_*() methods --- system/core/Router.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index bb0ce16bd..c86ab9c20 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -119,16 +119,16 @@ class CI_Router { if (isset($_GET[$this->config->item('directory_trigger')]) && is_string($_GET[$this->config->item('directory_trigger')])) { $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); - $segments[] = $this->fetch_directory(); + $segments[] = $this->directory; } $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); - $segments[] = $this->fetch_class(); + $segments[] = $this->class; if ( ! empty($_GET[$this->config->item('function_trigger')]) && is_string($_GET[$this->config->item('function_trigger')])) { $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); - $segments[] = $this->fetch_method(); + $segments[] = $this->method; } } @@ -270,7 +270,7 @@ class CI_Router { empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php')) { if ( ! empty($this->routes['404_override'])) { @@ -279,7 +279,7 @@ class CI_Router { } else { - show_404($this->fetch_directory().$segments[0]); + show_404($this->directory.$segments[0]); } } } @@ -287,7 +287,7 @@ class CI_Router { { // Is the method being specified in the route? $segments = explode('/', $this->default_controller); - if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php')) { $this->directory = ''; } @@ -413,6 +413,7 @@ class CI_Router { /** * Fetch the current class * + * @deprecated 3.0.0 Read the 'class' property instead * @return string */ public function fetch_class() @@ -438,11 +439,12 @@ class CI_Router { /** * Fetch the current method * + * @deprecated 3.0.0 Read the 'method' property instead * @return string */ public function fetch_method() { - return ($this->method === $this->fetch_class()) ? 'index' : $this->method; + return $this->method; } // -------------------------------------------------------------------- @@ -466,6 +468,7 @@ class CI_Router { * Feches the sub-directory (if any) that contains the requested * controller class. * + * @deprecated 3.0.0 Read the 'directory' property instead * @return string */ public function fetch_directory() -- cgit v1.2.3-24-g4f1b From 08fec7bdf846daa3dfa4114310f065294ac092fc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 19 Jul 2013 16:25:51 +0300 Subject: Router improvements - Make dashes-to-underscores URI segment replacement configurable via ['translate_uri_dashes']. - Make _set_routing() protected and move the call to the class constructor. - Remove redudant calls to set_class() and set_method(). - Clean-up/optimize the routes loading procedure. (fixes issue #2503) --- system/core/Router.php | 56 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index c86ab9c20..cc3916f86 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -81,6 +81,18 @@ class CI_Router { */ public $default_controller; + /** + * Translate URI dashes + * + * Determines whether dashes in controller & method segments + * should be automatically replaced by underscores. + * + * @var bool + */ + public $translate_uri_dashes = FALSE; + + // -------------------------------------------------------------------- + /** * Class constructor * @@ -92,6 +104,7 @@ class CI_Router { { $this->config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); + $this->_set_routing(); log_message('debug', 'Router Class Initialized'); } @@ -105,7 +118,7 @@ class CI_Router { * * @return void */ - public function _set_routing() + protected function _set_routing() { // Are query strings enabled in the config file? Normally CI doesn't utilize query strings // since URI segments are more search-engine friendly, but they can optionally be used. @@ -143,12 +156,14 @@ class CI_Router { include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); } - $this->routes = (empty($route) OR ! is_array($route)) ? array() : $route; - unset($route); - - // Set the default controller so we can display it in the event - // the URI doesn't correlated to a valid controller. - $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller']; + // Validate & get reserved routes + if (isset($route) && is_array($route)) + { + isset($route['default_controller']) && $this->default_controller = $route['default_controller']; + isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; + unset($route['default_controller'], $route['translate_uri_dashes']); + $this->routes = $route; + } // Were there any query string segments? If so, we'll validate them and bail out since we're done. if (count($segments) > 0) @@ -191,8 +206,6 @@ class CI_Router { $method = 'index'; } - $this->set_class($class); - $this->set_method($method); $this->_set_request(array($class, $method)); // re-index the routed segments array so it starts with 1 rather than 0 @@ -221,8 +234,16 @@ class CI_Router { return $this->_set_default_controller(); } - $this->set_class($segments[0]); + if ($this->translate_uri_dashes === TRUE) + { + $segments[0] = str_replace('-', '_', $segments[0]); + if (isset($segments[1])) + { + $segments[1] = str_replace('-', '_', $segments[1]); + } + } + $this->set_class($segments[0]); isset($segments[1]) OR $segments[1] = 'index'; $this->set_method($segments[1]); @@ -249,13 +270,12 @@ class CI_Router { return $segments; } - $temp = str_replace('-', '_', $segments[0]); + $test = ($this->translate_uri_dashes === TRUE) + ? str_replace('-', '_', $segments[0]) : $segments[0]; // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$temp.'.php')) + if (file_exists(APPPATH.'controllers/'.$test.'.php')) { - $segments[0] = $temp; - empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); return $segments; } @@ -266,11 +286,11 @@ class CI_Router { $this->set_directory(array_shift($segments)); if (count($segments) > 0) { - $segments[0] = str_replace('-', '_', $segments[0]); - empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); + $test = ($this->translate_uri_dashes === TRUE) + ? str_replace('-', '_', $segments[0]) : $segments[0]; - // Does the requested controller exist in the sub-folder? - if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php')) + // Does the requested controller exist in the sub-directory? + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php')) { if ( ! empty($this->routes['404_override'])) { -- cgit v1.2.3-24-g4f1b From 20292311636837e120d205e470e41826820feb46 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Jul 2013 14:29:10 +0300 Subject: Change class filenames to Ucfirst --- system/core/Router.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index cc3916f86..989ae542e 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -270,8 +270,7 @@ class CI_Router { return $segments; } - $test = ($this->translate_uri_dashes === TRUE) - ? str_replace('-', '_', $segments[0]) : $segments[0]; + $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); // Does the requested controller exist in the root folder? if (file_exists(APPPATH.'controllers/'.$test.'.php')) @@ -286,8 +285,7 @@ class CI_Router { $this->set_directory(array_shift($segments)); if (count($segments) > 0) { - $test = ($this->translate_uri_dashes === TRUE) - ? str_replace('-', '_', $segments[0]) : $segments[0]; + $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); // Does the requested controller exist in the sub-directory? if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php')) @@ -307,7 +305,7 @@ class CI_Router { { // Is the method being specified in the route? $segments = explode('/', $this->default_controller); - if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php')) + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($segments[0]).'.php')) { $this->directory = ''; } -- cgit v1.2.3-24-g4f1b From c941d855dc32ec44107cb863596fa385c7aed015 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 6 Aug 2013 14:44:40 +0200 Subject: Various typos and tabs adjustments --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 989ae542e..0f7278ae6 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -351,10 +351,10 @@ class CI_Router { return $this->_set_request(explode('/', $this->routes[$uri])); } - // Loop through the route array looking for wild-cards + // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { - // Convert wild-cards to RegEx + // Convert wildcards to RegEx $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); // Does the RegEx match? -- cgit v1.2.3-24-g4f1b From 442b50b0c78a8c630b139d3a9a30d3b731253565 Mon Sep 17 00:00:00 2001 From: Fatih Kalifa Date: Fri, 1 Nov 2013 02:44:56 +0700 Subject: Enable HTTP Verb in Routing Using array for HTTP Verb e.g: $route['(:any)']['POST'] = "controller/post_method"; $route['path']['GET'] = "controller/path_get_method"; $route['path']['(:any)'] = "controller/path_any_method"; Using (:any) or not will make same result e.g: $route['path']['(:any)'] == $route['path'] So it won't break existing route --- system/core/Router.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 0f7278ae6..89d11afab 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -345,8 +345,20 @@ class CI_Router { // Turn the segment array into a URI string $uri = implode('/', $this->uri->segments); + // Get HTTP verb + $http_verb = strtolower($_SERVER['REQUEST_METHOD']); + // Is there a literal match? If so we're done - if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) + if (isset($this->routes[$uri][$http_verb])) + { + return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + } + else if (isset($this->routes[$uri]['(:any)'])) + { + return $this->_set_request(explode('/', $this->routes[$uri]['(:any)'])); + } + // Fallback to default routing + else if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) { return $this->_set_request(explode('/', $this->routes[$uri])); } @@ -354,6 +366,25 @@ class CI_Router { // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { + // Check if HTTP Verb is exist + if (is_array($val)) + { + // HTTP verb included in routes + if (isset($val[$http_verb])) + { + $val = $val[$http_verb]; + } + else if (isset($val['(:any)'])) + { + $val = $val['(:any)']; + } + else + { + // HTTP Verb not found + continue; + } + } + // Convert wildcards to RegEx $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); -- cgit v1.2.3-24-g4f1b From 0b58b3cad456efc5ecce89f622876c6b715439c2 Mon Sep 17 00:00:00 2001 From: Fatih Kalifa Date: Tue, 5 Nov 2013 15:36:40 +0700 Subject: Fix HTTP Verb Routing Rules Fix code style, removed (:any) rule in http verb to avoid confusion, and add proposed documentation and changelog --- system/core/Router.php | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 89d11afab..9071f84b7 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -349,38 +349,34 @@ class CI_Router { $http_verb = strtolower($_SERVER['REQUEST_METHOD']); // Is there a literal match? If so we're done - if (isset($this->routes[$uri][$http_verb])) + if (isset($this->routes[$uri])) { - return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); - } - else if (isset($this->routes[$uri]['(:any)'])) - { - return $this->_set_request(explode('/', $this->routes[$uri]['(:any)'])); - } - // Fallback to default routing - else if (isset($this->routes[$uri]) && is_string($this->routes[$uri])) - { - return $this->_set_request(explode('/', $this->routes[$uri])); + // Check default routes format + if (is_string($this->routes[$uri])) + { + return $this->_set_request(explode('/', $this->routes[$uri])); + } + // Is there any matching http verb? + elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb])) + { + return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + } } // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { - // Check if HTTP Verb is exist + // Check if route format is using http verb if (is_array($val)) { - // HTTP verb included in routes + // Does the http verb match? if (isset($val[$http_verb])) { $val = $val[$http_verb]; } - else if (isset($val['(:any)'])) - { - $val = $val['(:any)']; - } + // No match, skip to next rule else { - // HTTP Verb not found continue; } } -- cgit v1.2.3-24-g4f1b From c761a206def7714d18623d46b05adc2bbeedce21 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Nov 2013 14:02:15 +0200 Subject: Polish changes from PR #2712 --- system/core/Router.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 9071f84b7..d467d60fd 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -346,7 +346,7 @@ class CI_Router { $uri = implode('/', $this->uri->segments); // Get HTTP verb - $http_verb = strtolower($_SERVER['REQUEST_METHOD']); + $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; // Is there a literal match? If so we're done if (isset($this->routes[$uri])) @@ -356,7 +356,7 @@ class CI_Router { { return $this->_set_request(explode('/', $this->routes[$uri])); } - // Is there any matching http verb? + // Is there a matching http verb? elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb])) { return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); @@ -369,12 +369,10 @@ class CI_Router { // Check if route format is using http verb if (is_array($val)) { - // Does the http verb match? if (isset($val[$http_verb])) { $val = $val[$http_verb]; } - // No match, skip to next rule else { continue; -- cgit v1.2.3-24-g4f1b From 4e6c5281a3258b3ff530a43580d1b8dc8e34dd59 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 10 Jan 2014 19:29:49 +0200 Subject: Finally get rid of the CI_Router::_set_overrides() calls --- system/core/Router.php | 55 +++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index d467d60fd..cb44a3ce9 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -102,9 +102,32 @@ class CI_Router { */ public function __construct() { + global $routing; + $this->config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); $this->_set_routing(); + + // Set any routing overrides that may exist in the main index file + if (isset($routing) && is_array($routing)) + { + if (isset($routing['directory'])) + { + $this->set_directory($routing['directory']); + } + + if ( ! empty($routing['controller'])) + { + $this->set_class($routing['controller']); + } + + if (isset($routing['function'])) + { + $routing['function'] = empty($routing['function']) ? 'index' : $routing['function']; + $this->set_method($routing['function']); + } + } + log_message('debug', 'Router Class Initialized'); } @@ -519,38 +542,6 @@ class CI_Router { return $this->directory; } - // -------------------------------------------------------------------- - - /** - * Set controller overrides - * - * @param array $routing Route overrides - * @return void - */ - public function _set_overrides($routing) - { - if ( ! is_array($routing)) - { - return; - } - - if (isset($routing['directory'])) - { - $this->set_directory($routing['directory']); - } - - if ( ! empty($routing['controller'])) - { - $this->set_class($routing['controller']); - } - - if (isset($routing['function'])) - { - $routing['function'] = empty($routing['function']) ? 'index' : $routing['function']; - $this->set_method($routing['function']); - } - } - } /* End of file Router.php */ -- cgit v1.2.3-24-g4f1b From de14aa5a29b1b122bfd536f979dfda7f2fd9f53d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Jan 2014 15:51:08 +0200 Subject: CI_URI changes related to the 'permitted_uri_chars' setting - Initialize and cache the value in the class constructor instead of searching for it every time - Removed the preg_quote() call from _filter_uri() to allow more fine-tuning from configuration - Renamed _filter_uri() to filter_uri() - it was public anyway and using it cannot break anything Related: issue #2799 --- system/core/Router.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index cb44a3ce9..71530ff07 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -154,16 +154,16 @@ class CI_Router { { if (isset($_GET[$this->config->item('directory_trigger')]) && is_string($_GET[$this->config->item('directory_trigger')])) { - $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); + $this->set_directory(trim($this->uri->filter_uri($_GET[$this->config->item('directory_trigger')]))); $segments[] = $this->directory; } - $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); + $this->set_class(trim($this->uri->filter_uri($_GET[$this->config->item('controller_trigger')]))); $segments[] = $this->class; if ( ! empty($_GET[$this->config->item('function_trigger')]) && is_string($_GET[$this->config->item('function_trigger')])) { - $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); + $this->set_method(trim($this->uri->filter_uri($_GET[$this->config->item('function_trigger')]))); $segments[] = $this->method; } } -- cgit v1.2.3-24-g4f1b From 30d5324617ae136c7a91badb6ed8f7de418fd7f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 16 Jan 2014 14:41:46 +0200 Subject: URI Routing overhaul - Allow multiple levels of controller directories (supersedes PRs #390, #2439) - Add support for per-directory 'defaul_controller' and '404_override' (resolves issue #2611; supersedes PR #939) - Fixed a bug where default_controller was called instead of triggering 404 if the current route is inside a directory - Removed a few calls from CI_Router to CI_URI that made a necessity for otherwise internal CI_URI methods to be public: - Removed CI_URI::_fetch_uri_string() and moved its logic into CI_URI::__construct() - Removed CI_URI::_remove_url_suffix, CI_URI::_explode_segments() and moved their logic into CI_URI::_set_uri_string() - Removed CI_URI::_reindex_segments() altogether ( doesn't need further manipulation, while is public anyway and can be properly (and more effectively) replaced on the spot) --- system/core/Router.php | 240 ++++++++++++++++++++++++------------------------- 1 file changed, 118 insertions(+), 122 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 71530ff07..e3c911511 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -91,6 +91,15 @@ class CI_Router { */ public $translate_uri_dashes = FALSE; + /** + * Enable query strings flag + * + * Determines wether to use GET parameters or segment URIs + * + * @var bool + */ + public $enable_query_strings = FALSE; + // -------------------------------------------------------------------- /** @@ -106,6 +115,8 @@ class CI_Router { $this->config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); + + $this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE); $this->_set_routing(); // Set any routing overrides that may exist in the main index file @@ -146,26 +157,39 @@ class CI_Router { // Are query strings enabled in the config file? Normally CI doesn't utilize query strings // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently - $segments = array(); - if ($this->config->item('enable_query_strings') === TRUE - && ! empty($_GET[$this->config->item('controller_trigger')]) - && is_string($_GET[$this->config->item('controller_trigger')]) - ) + if ($this->enable_query_strings) { - if (isset($_GET[$this->config->item('directory_trigger')]) && is_string($_GET[$this->config->item('directory_trigger')])) + $_d = $this->config->item('directory_trigger'); + $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; + if ($_d !== '') { - $this->set_directory(trim($this->uri->filter_uri($_GET[$this->config->item('directory_trigger')]))); - $segments[] = $this->directory; + $this->set_directory($this->uri->filter_uri($_d)); } - $this->set_class(trim($this->uri->filter_uri($_GET[$this->config->item('controller_trigger')]))); - $segments[] = $this->class; + $_c = $this->config->item('controller_trigger'); + if ( ! empty($_GET[$_c])) + { + $this->set_class(trim($this->uri->filter_uri(trim($_GET[$_c])))); + + $_f = $this->config->item('function_trigger'); + if ( ! empty($_GET[$_f])) + { + $this->set_method(trim($this->uri->filter_uri($_GET[$_f]))); + } - if ( ! empty($_GET[$this->config->item('function_trigger')]) && is_string($_GET[$this->config->item('function_trigger')])) + $this->uri->rsegments = array( + 1 => $this->class, + 2 => $this->method + ); + } + else { - $this->set_method(trim($this->uri->filter_uri($_GET[$this->config->item('function_trigger')]))); - $segments[] = $this->method; + $this->_set_default_controller(); } + + // Routing rules don't apply to query strings and we don't need to detect + // directories, so we're done here + return; } // Load the routes.php file. @@ -188,53 +212,15 @@ class CI_Router { $this->routes = $route; } - // Were there any query string segments? If so, we'll validate them and bail out since we're done. - if (count($segments) > 0) + // Is there anything to parse? + if ($this->uri->uri_string !== '') { - return $this->_validate_request($segments); + $this->_parse_routes(); } - - // Fetch the complete URI string - $this->uri->_fetch_uri_string(); - - // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. - if ($this->uri->uri_string == '') + else { - return $this->_set_default_controller(); + $this->_set_default_controller(); } - - $this->uri->_remove_url_suffix(); // Remove the URL suffix - $this->uri->_explode_segments(); // Compile the segments into an array - $this->_parse_routes(); // Parse any custom routing that may exist - $this->uri->_reindex_segments(); // Re-index the segment array so that it starts with 1 rather than 0 - } - - // -------------------------------------------------------------------- - - /** - * Set default controller - * - * @return void - */ - protected function _set_default_controller() - { - if (empty($this->default_controller)) - { - show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); - } - - // Is the method being specified? - if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) - { - $method = 'index'; - } - - $this->_set_request(array($class, $method)); - - // re-index the routed segments array so it starts with 1 rather than 0 - $this->uri->_reindex_segments(); - - log_message('debug', 'No URI present. Default controller set.'); } // -------------------------------------------------------------------- @@ -245,16 +231,19 @@ class CI_Router { * Takes an array of URI segments as input and sets the class/method * to be called. * + * @used-by CI_Router::_parse_routes() * @param array $segments URI segments * @return void */ protected function _set_request($segments = array()) { $segments = $this->_validate_request($segments); - - if (count($segments) === 0) + // If we don't have any segments left - try the default controller; + // WARNING: Directories get shifted out of the segments array! + if (empty($segments)) { - return $this->_set_default_controller(); + $this->_set_default_controller(); + return; } if ($this->translate_uri_dashes === TRUE) @@ -267,90 +256,86 @@ class CI_Router { } $this->set_class($segments[0]); - isset($segments[1]) OR $segments[1] = 'index'; - $this->set_method($segments[1]); + if (isset($segments[1])) + { + $this->set_method($segments[1]); + } - // Update our "routed" segment array to contain the segments. - // Note: If there is no custom routing, this array will be - // identical to $this->uri->segments + array_unshift($segments, NULL); + unset($segments[0]); $this->uri->rsegments = $segments; } // -------------------------------------------------------------------- /** - * Validate request - * - * Attempts validate the URI request and determine the controller path. + * Set default controller * - * @param array $segments URI segments - * @return array URI segments + * @return void */ - protected function _validate_request($segments) + protected function _set_default_controller() { - if (count($segments) === 0) + if (empty($this->default_controller)) { - return $segments; + show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); } - $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); - - // Does the requested controller exist in the root folder? - if (file_exists(APPPATH.'controllers/'.$test.'.php')) + // Is the method being specified? + if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) { - return $segments; + $method = 'index'; } - // Is the controller in a sub-folder? - if (is_dir(APPPATH.'controllers/'.$segments[0])) + if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) { - // Set the directory and remove it from the segment array - $this->set_directory(array_shift($segments)); - if (count($segments) > 0) - { - $test = ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); + // This will trigger 404 later + return; + } - // Does the requested controller exist in the sub-directory? - if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php')) - { - if ( ! empty($this->routes['404_override'])) - { - $this->directory = ''; - return explode('/', $this->routes['404_override'], 2); - } - else - { - show_404($this->directory.$segments[0]); - } - } - } - else - { - // Is the method being specified in the route? - $segments = explode('/', $this->default_controller); - if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($segments[0]).'.php')) - { - $this->directory = ''; - } - } + $this->set_class($class); + $this->set_method($method); - return $segments; - } + // Assign routed segments, index starting from 1 + $this->uri->rsegments = array( + 1 => $class, + 2 => $method + ); + + log_message('debug', 'No URI present. Default controller set.'); + } + + // -------------------------------------------------------------------- - // If we've gotten this far it means that the URI does not correlate to a valid - // controller class. We will now see if there is an override - if ( ! empty($this->routes['404_override'])) + /** + * Validate request + * + * Attempts validate the URI request and determine the controller path. + * + * @used-by CI_Router::_set_request() + * @param array $segments URI segments + * @return mixed URI segments + */ + protected function _validate_request($segments) + { + $c = count($segments); + // Loop through our segments and return as soon as a controller + // is found or when such a directory doesn't exist + while ($c-- > 0) { - if (sscanf($this->routes['404_override'], '%[^/]/%s', $class, $method) !== 2) + $test = $this->directory + .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); + + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0])) { - $method = 'index'; + $this->set_directory(array_shift($segments), TRUE); + continue; } - return array($class, $method); + return $segments; } - // Nothing else to do at this point but show a 404 - show_404($segments[0]); + // This means that all segments were actually directories + return $segments; } // -------------------------------------------------------------------- @@ -377,12 +362,14 @@ class CI_Router { // Check default routes format if (is_string($this->routes[$uri])) { - return $this->_set_request(explode('/', $this->routes[$uri])); + $this->_set_request(explode('/', $this->routes[$uri])); + return; } // Is there a matching http verb? elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb])) { - return $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + return; } } @@ -452,7 +439,8 @@ class CI_Router { $val = preg_replace('#^'.$key.'$#', $val, $uri); } - return $this->_set_request(explode('/', $val)); + $this->_set_request(explode('/', $val)); + return; } } @@ -519,11 +507,19 @@ class CI_Router { * Set directory name * * @param string $dir Directory name + * @param bool $appent Whether we're appending rather then setting the full value * @return void */ - public function set_directory($dir) + public function set_directory($dir, $append = FALSE) { - $this->directory = str_replace(array('/', '.'), '', $dir).'/'; + if ($append !== TRUE OR empty($this->directory)) + { + $this->directory = str_replace('.', '', trim($dir, '/')).'/'; + } + else + { + $this->directory .= str_replace('.', '', trim($dir, '/')).'/'; + } } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From a9237cb4ec63c8bc2e9dff911406c8c60aef7213 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 18 Jan 2014 19:07:20 +0200 Subject: Fix 2 Router-related errors --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index e3c911511..633524023 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -446,7 +446,7 @@ class CI_Router { // If we got this far it means we didn't encounter a // matching route so we'll set the site default route - $this->_set_request($this->uri->segments); + $this->_set_request(array_values($this->uri->segments)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 871754af60251993d640981e107d2def5f2db396 Mon Sep 17 00:00:00 2001 From: darwinel Date: Tue, 11 Feb 2014 17:34:57 +0100 Subject: 2013 > 2014 Update copyright notices from 2013 to 2014. And update one calendar example in user_guide from year 2013/2014 to 2014/2015. --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 633524023..05263b153 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -18,7 +18,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From c26b9ebb00e29be2e972fece3bcf73d33249a64b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 24 Feb 2014 11:31:36 +0200 Subject: Don't use globals - Use load_class() to get objects during bootstrap process. - Change load_class() to accept a class constructor parameter instead of previously unused class name prefix. - Change CI_Router::__construct() to accept as a parameter. --- system/core/Router.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 05263b153..2448d9c8c 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -109,10 +109,8 @@ class CI_Router { * * @return void */ - public function __construct() + public function __construct($routing = NULL) { - global $routing; - $this->config =& load_class('Config', 'core'); $this->uri =& load_class('URI', 'core'); @@ -120,7 +118,7 @@ class CI_Router { $this->_set_routing(); // Set any routing overrides that may exist in the main index file - if (isset($routing) && is_array($routing)) + if (is_array($routing)) { if (isset($routing['directory'])) { -- cgit v1.2.3-24-g4f1b From a8b0efb5012618dcfa54a88a417929f7d1f2be15 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 25 Mar 2014 13:47:42 +0200 Subject: Simplify callback routes There's no need for all that Reflection magic, it's only slowing down the whole process --- system/core/Router.php | 29 ----------------------------- 1 file changed, 29 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 2448d9c8c..765e32374 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -399,35 +399,6 @@ class CI_Router { // Remove the original string from the matches array. array_shift($matches); - // Get the match count. - $match_count = count($matches); - - // Determine how many parameters the callback has. - $reflection = new ReflectionFunction($val); - $param_count = $reflection->getNumberOfParameters(); - - // Are there more parameters than matches? - if ($param_count > $match_count) - { - // Any params without matches will be set to an empty string. - $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); - - $match_count = $param_count; - } - - // Get the parameters so we can use their default values. - $params = $reflection->getParameters(); - - for ($m = 0; $m < $match_count; $m++) - { - // Is the match empty and does a default value exist? - if (empty($matches[$m]) && $params[$m]->isDefaultValueAvailable()) - { - // Substitute the empty match for the default value. - $matches[$m] = $params[$m]->getDefaultValue(); - } - } - // Execute the callback using the values in matches as its parameters. $val = call_user_func_array($val, $matches); } -- cgit v1.2.3-24-g4f1b From 9cab42746a4f1bfcce9620fa87bec5d2f590666e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 30 Mar 2014 18:58:23 +0300 Subject: Fix #2976 --- system/core/Router.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 765e32374..ea4f4a4f7 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -258,6 +258,10 @@ class CI_Router { { $this->set_method($segments[1]); } + else + { + $segments[1] = 'index'; + } array_unshift($segments, NULL); unset($segments[0]); -- cgit v1.2.3-24-g4f1b From bc89b3ccaf40d8659a2fdb2730cad88ba8cc24ed Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 15 Apr 2014 17:46:05 +0300 Subject: #3005 --- system/core/Router.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index ea4f4a4f7..1bb18b088 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -130,9 +130,8 @@ class CI_Router { $this->set_class($routing['controller']); } - if (isset($routing['function'])) + if ( ! empty($routing['function'])) { - $routing['function'] = empty($routing['function']) ? 'index' : $routing['function']; $this->set_method($routing['function']); } } -- cgit v1.2.3-24-g4f1b From bdb96ca1b1dbfc1791172fd169d7751cbc4d7d55 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 28 Oct 2014 00:13:31 +0200 Subject: [ci skip] Switch to MIT license; close #3293 --- system/core/Router.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 1bb18b088..7f18adbf5 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -4,24 +4,35 @@ * * An open source application development framework for PHP 5.2.4 or newer * - * NOTICE OF LICENSE + * This content is released under the MIT License (MIT) * - * Licensed under the Open Software License version 3.0 + * Copyright (c) 2014, British Columbia Institute of Technology * - * This source file is subject to the Open Software License (OSL 3.0) that is - * bundled with this package in the files license.txt / license.rst. It is - * also available through the world wide web at this URL: - * http://opensource.org/licenses/OSL-3.0 - * If you did not receive a copy of the license and are unable to obtain it - * through the world wide web, please send an email to - * licensing@ellislab.com so we can send you a copy immediately. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * @package CodeIgniter - * @author EllisLab Dev Team + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @package CodeIgniter + * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * @link http://codeigniter.com - * @since Version 1.0 + * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @license http://opensource.org/licenses/MIT MIT License + * @link http://codeigniter.com + * @since Version 1.0.0 * @filesource */ defined('BASEPATH') OR exit('No direct script access allowed'); -- cgit v1.2.3-24-g4f1b From bfa233f559a50ee0674a209fa56f866edc814fd9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Dec 2014 12:00:11 +0200 Subject: Further changes related to issue #47, PR #3323 - Removed a test that was created specifically for the 'convert programmatic characters to entities' feature. - Changed filter_uri() to accept by reference and to not return anything as its only purpose now is to trigger a show_error() call. - Added changelog messages and updated the upgrade instructions. --- system/core/Router.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 7f18adbf5..d86735f5f 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -171,18 +171,21 @@ class CI_Router { $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; if ($_d !== '') { - $this->set_directory($this->uri->filter_uri($_d)); + $this->uri->filter_uri($_d); + $this->set_directory($_d); } - $_c = $this->config->item('controller_trigger'); + $_c = trim($this->config->item('controller_trigger')); if ( ! empty($_GET[$_c])) { - $this->set_class(trim($this->uri->filter_uri(trim($_GET[$_c])))); + $this->uri->filter_uri($_GET[$_c]); + $this->set_class($_GET[$_c]); - $_f = $this->config->item('function_trigger'); + $_f = trim($this->config->item('function_trigger')); if ( ! empty($_GET[$_f])) { - $this->set_method(trim($this->uri->filter_uri($_GET[$_f]))); + $this->uri->filter_uri($_GET[$_f]); + $this->set_method($_GET[$_f]); } $this->uri->rsegments = array( -- cgit v1.2.3-24-g4f1b From fe9309d22c1b088f5363954d6dac013c8c955894 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 9 Jan 2015 17:48:58 +0200 Subject: Bulk (mostly documentation) update - Remove PHP version from license notices - Bump year number in copyright notices - Recommend PHP 5.4 or newer to be used - Tell Travis-CI to test on PHP 5.3.0 instead of the latest 5.3 version Related: #3450 --- system/core/Router.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index d86735f5f..b21335fc2 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -2,11 +2,11 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.2.4 or newer + * An open source application development framework for PHP * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014, British Columbia Institute of Technology + * Copyright (c) 2014 - 2015, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index b21335fc2..c7acad074 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -147,7 +147,7 @@ class CI_Router { } } - log_message('debug', 'Router Class Initialized'); + log_message('info', 'Router Class Initialized'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 4cbe463b4c442e0e2dae2f43565e77f7ac5ecb86 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 21 Jan 2015 22:56:22 +0100 Subject: Remove closing blocks at end of PHP files --- system/core/Router.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index c7acad074..eb3da2285 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -525,6 +525,3 @@ class CI_Router { } } - -/* End of file Router.php */ -/* Location: ./system/core/Router.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1924eb37cc5488be7560a8a754663bba6a47a5e4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 8 Apr 2015 17:19:24 +0300 Subject: [ci skip] Fix comment typos https://github.com/bcit-ci/CodeIgniter/pull/3748#issuecomment-90925762 --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index eb3da2285..f91d3f6ec 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -493,7 +493,7 @@ class CI_Router { * Set directory name * * @param string $dir Directory name - * @param bool $appent Whether we're appending rather then setting the full value + * @param bool $appent Whether we're appending rather than setting the full value * @return void */ public function set_directory($dir, $append = FALSE) -- cgit v1.2.3-24-g4f1b From bf0488b59daaa9a77a72289b00a5ee807d907286 Mon Sep 17 00:00:00 2001 From: ftwbzhao Date: Mon, 6 Jul 2015 17:48:08 +0800 Subject: fix typo in router class --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index f91d3f6ec..051000533 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -105,7 +105,7 @@ class CI_Router { /** * Enable query strings flag * - * Determines wether to use GET parameters or segment URIs + * Determines whether to use GET parameters or segment URIs * * @var bool */ -- cgit v1.2.3-24-g4f1b From 2ef5ed458c611331facfeb5abee051f4c0d1b08e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 17 Jul 2015 14:24:26 +0300 Subject: Fix #3752 --- system/core/Router.php | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 051000533..af87a305a 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -83,7 +83,7 @@ class CI_Router { * * @var string */ - public $directory = ''; + public $directory; /** * Default controller (and method if specific) @@ -126,25 +126,16 @@ class CI_Router { $this->uri =& load_class('URI', 'core'); $this->enable_query_strings = ( ! is_cli() && $this->config->item('enable_query_strings') === TRUE); + + // If a directory override is configured, it has to be set before any dynamic routing logic + is_array($routing) && isset($routing['directory']) && $this->set_directory($routing['directory']); $this->_set_routing(); // Set any routing overrides that may exist in the main index file if (is_array($routing)) { - if (isset($routing['directory'])) - { - $this->set_directory($routing['directory']); - } - - if ( ! empty($routing['controller'])) - { - $this->set_class($routing['controller']); - } - - if ( ! empty($routing['function'])) - { - $this->set_method($routing['function']); - } + empty($routing['controller']) OR $this->set_class($routing['controller']); + empty($routing['function']) OR $this->set_method($routing['function']); } log_message('info', 'Router Class Initialized'); @@ -167,12 +158,17 @@ class CI_Router { // If this feature is enabled, we will gather the directory/class/method a little differently if ($this->enable_query_strings) { - $_d = $this->config->item('directory_trigger'); - $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; - if ($_d !== '') + // If the directory is set at this time, it means an override exists, so skip the checks + if ( ! isset($this->directory)) { - $this->uri->filter_uri($_d); - $this->set_directory($_d); + $_d = $this->config->item('directory_trigger'); + $_d = isset($_GET[$_d]) ? trim($_GET[$_d], " \t\n\r\0\x0B/") : ''; + + if ($_d !== '') + { + $this->uri->filter_uri($_d); + $this->set_directory($_d); + } } $_c = trim($this->config->item('controller_trigger')); @@ -333,6 +329,8 @@ class CI_Router { protected function _validate_request($segments) { $c = count($segments); + $directory_override = isset($this->directory); + // Loop through our segments and return as soon as a controller // is found or when such a directory doesn't exist while ($c-- > 0) @@ -340,7 +338,10 @@ class CI_Router { $test = $this->directory .ucfirst($this->translate_uri_dashes === TRUE ? str_replace('-', '_', $segments[0]) : $segments[0]); - if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0])) + if ( ! file_exists(APPPATH.'controllers/'.$test.'.php') + && $directory_override === FALSE + && is_dir(APPPATH.'controllers/'.$this->directory.$segments[0]) + ) { $this->set_directory(array_shift($segments), TRUE); continue; -- cgit v1.2.3-24-g4f1b From 55bc50578b9f1aa3fd71cb427848b21748655690 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Fri, 24 Jul 2015 02:27:24 -0700 Subject: Fixed typos --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index af87a305a..ab5246a1f 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -494,7 +494,7 @@ class CI_Router { * Set directory name * * @param string $dir Directory name - * @param bool $appent Whether we're appending rather than setting the full value + * @param bool $append Whether we're appending rather than setting the full value * @return void */ public function set_directory($dir, $append = FALSE) -- cgit v1.2.3-24-g4f1b From abc299b3a234eb7da1b7e3d257b7eba2da649219 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Aug 2015 12:26:22 +0300 Subject: Fix #4027 --- system/core/Router.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index ab5246a1f..0c793e418 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -375,16 +375,19 @@ class CI_Router { // Is there a literal match? If so we're done if (isset($this->routes[$uri])) { - // Check default routes format - if (is_string($this->routes[$uri])) + // Is it an HTTP verb-based route? + if (is_array($this->routes[$uri])) { - $this->_set_request(explode('/', $this->routes[$uri])); - return; + $route = array_change_key_case($this->routes[$uri], CASE_LOWER); + if (isset($route[$http_verb])) + { + $this->_set_request(explode('/', $route[$http_verb])); + return; + } } - // Is there a matching http verb? - elseif (is_array($this->routes[$uri]) && isset($this->routes[$uri][$http_verb])) + else { - $this->_set_request(explode('/', $this->routes[$uri][$http_verb])); + $this->_set_request(explode('/', $this->routes[$uri])); return; } } @@ -392,9 +395,10 @@ class CI_Router { // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { - // Check if route format is using http verb + // Check if route format is using HTTP verbs if (is_array($val)) { + $val = array_change_key_case($val, CASE_LOWER); if (isset($val[$http_verb])) { $val = $val[$http_verb]; -- cgit v1.2.3-24-g4f1b From c2c7cb7e9d869ba8ba8b16a04e5d8300d462d8de Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 14 Aug 2015 13:48:31 +0300 Subject: Fix #4052 The bug actually had two instances: - Callback routes with literal matches and HTTP verbs has never worked - The reported issue in #4052, which is a regression introduced in 3.0.1 with abc299b3a234eb7da1b7e3d257b7eba2da649219 Removed the literal matches logic altogether to avoid similar issues in the future and reduce code complexity. The same logic is performed with the regular expressions logic. --- system/core/Router.php | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 0c793e418..eb868cd5b 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -372,26 +372,6 @@ class CI_Router { // Get HTTP verb $http_verb = isset($_SERVER['REQUEST_METHOD']) ? strtolower($_SERVER['REQUEST_METHOD']) : 'cli'; - // Is there a literal match? If so we're done - if (isset($this->routes[$uri])) - { - // Is it an HTTP verb-based route? - if (is_array($this->routes[$uri])) - { - $route = array_change_key_case($this->routes[$uri], CASE_LOWER); - if (isset($route[$http_verb])) - { - $this->_set_request(explode('/', $route[$http_verb])); - return; - } - } - else - { - $this->_set_request(explode('/', $this->routes[$uri])); - return; - } - } - // Loop through the route array looking for wildcards foreach ($this->routes as $key => $val) { -- cgit v1.2.3-24-g4f1b From f2239fe1f6e0578a00afb88e9fc2b2cdd2ac2626 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Sep 2015 13:48:03 +0300 Subject: Fix #4109 --- system/core/Router.php | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index eb868cd5b..a84be1f1d 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -153,6 +153,28 @@ class CI_Router { */ protected function _set_routing() { + // Load the routes.php file. It would be great if we could + // skip this for enable_query_strings = TRUE, but then + // default_controller would be empty ... + if (file_exists(APPPATH.'config/routes.php')) + { + include(APPPATH.'config/routes.php'); + } + + if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) + { + include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); + } + + // Validate & get reserved routes + if (isset($route) && is_array($route)) + { + isset($route['default_controller']) && $this->default_controller = $route['default_controller']; + isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; + unset($route['default_controller'], $route['translate_uri_dashes']); + $this->routes = $route; + } + // Are query strings enabled in the config file? Normally CI doesn't utilize query strings // since URI segments are more search-engine friendly, but they can optionally be used. // If this feature is enabled, we will gather the directory/class/method a little differently @@ -199,26 +221,6 @@ class CI_Router { return; } - // Load the routes.php file. - if (file_exists(APPPATH.'config/routes.php')) - { - include(APPPATH.'config/routes.php'); - } - - if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) - { - include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); - } - - // Validate & get reserved routes - if (isset($route) && is_array($route)) - { - isset($route['default_controller']) && $this->default_controller = $route['default_controller']; - isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes']; - unset($route['default_controller'], $route['translate_uri_dashes']); - $this->routes = $route; - } - // Is there anything to parse? if ($this->uri->uri_string !== '') { -- cgit v1.2.3-24-g4f1b From f0f93f50d2a85373988a225504115d4805446189 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 7 Dec 2015 12:12:44 +0200 Subject: Merge pull request #4291 from b-kaxa/fix-phpdoc [ci skip] phpdoc adjustments in CI_Router and CI_URI --- system/core/Router.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index a84be1f1d..ce41aa958 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -118,6 +118,7 @@ class CI_Router { * * Runs the route mapping function. * + * @param array $routing * @return void */ public function __construct($routing = NULL) -- cgit v1.2.3-24-g4f1b From 125ef4751080a2118cb203357d77687699e3eb25 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:33:00 +0200 Subject: [ci skip] Bump year to 2016 --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index ce41aa958..85d1df719 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2015, British Columbia Institute of Technology + * Copyright (c) 2014 - 2016, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) - * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link http://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From bd202c91b0e9cf0a8c93bcaa71df9574f5909346 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:50:18 +0200 Subject: [ci skip] Update codeigniter.com links to https --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 85d1df719..e46ddb4a9 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -31,7 +31,7 @@ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License - * @link http://codeigniter.com + * @link https://codeigniter.com * @since Version 1.0.0 * @filesource */ @@ -46,7 +46,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Libraries * @category Libraries * @author EllisLab Dev Team - * @link http://codeigniter.com/user_guide/general/routing.html + * @link https://codeigniter.com/user_guide/general/routing.html */ class CI_Router { -- cgit v1.2.3-24-g4f1b From 1924e879b165fb119847a49a7a5eab2f28295fa2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:55:34 +0200 Subject: [ci skip] Update ellislab.com links to https too --- system/core/Router.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index e46ddb4a9..045d36687 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -28,7 +28,7 @@ * * @package CodeIgniter * @author EllisLab Dev Team - * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) + * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com -- cgit v1.2.3-24-g4f1b From da60e9bc66ec90970fbd2dfd08b0a6e66b9f5f5f Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/core/Router.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/core/Router.php') diff --git a/system/core/Router.php b/system/core/Router.php index 045d36687..1abe4c4e5 100644 --- a/system/core/Router.php +++ b/system/core/Router.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b