Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 29 | /** |
| 30 | * Router Class |
| 31 | * |
| 32 | * Parses URIs and determines routing |
| 33 | * |
| 34 | * @package CodeIgniter |
| 35 | * @subpackage Libraries |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @category Libraries |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 37 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | * @link http://codeigniter.com/user_guide/general/routing.html |
| 39 | */ |
| 40 | class CI_Router { |
| 41 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 42 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 43 | * CI_Config class object |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 44 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 45 | * @var object |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 46 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 47 | public $config; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 48 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 49 | /** |
| 50 | * List of routes |
| 51 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 52 | * @var array |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 53 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 54 | public $routes = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 55 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 56 | /** |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 57 | * Current class name |
| 58 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 59 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 60 | */ |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 61 | public $class = ''; |
| 62 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 63 | /** |
| 64 | * Current method name |
| 65 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 66 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 67 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 68 | public $method = 'index'; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 69 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 70 | /** |
| 71 | * Sub-directory that contains the requested controller class |
| 72 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 73 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 74 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 75 | public $directory = ''; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 76 | |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 77 | /** |
| 78 | * Default controller (and method if specific) |
| 79 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 80 | * @var string |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 81 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 82 | public $default_controller; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 83 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 84 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 85 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | * |
| 87 | * Runs the route mapping function. |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 88 | * |
| 89 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 91 | public function __construct() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 92 | { |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 93 | $this->config =& load_class('Config', 'core'); |
| 94 | $this->uri =& load_class('URI', 'core'); |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 95 | log_message('debug', 'Router Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 97 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 99 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 101 | * Set route mapping |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 103 | * Determines what should be served based on the URI request, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 104 | * as well as any "routes" that have been set in the routing config file. |
| 105 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 106 | * @return void |
| 107 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 108 | public function _set_routing() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 109 | { |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 110 | // Are query strings enabled in the config file? Normally CI doesn't utilize query strings |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | // since URI segments are more search-engine friendly, but they can optionally be used. |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 112 | // If this feature is enabled, we will gather the directory/class/method a little differently |
| 113 | $segments = array(); |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 114 | if ($this->config->item('enable_query_strings') === TRUE && isset($_GET[$this->config->item('controller_trigger')])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 115 | { |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 116 | if (isset($_GET[$this->config->item('directory_trigger')])) |
| 117 | { |
| 118 | $this->set_directory(trim($this->uri->_filter_uri($_GET[$this->config->item('directory_trigger')]))); |
| 119 | $segments[] = $this->fetch_directory(); |
| 120 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 121 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 122 | if (isset($_GET[$this->config->item('controller_trigger')])) |
| 123 | { |
| 124 | $this->set_class(trim($this->uri->_filter_uri($_GET[$this->config->item('controller_trigger')]))); |
| 125 | $segments[] = $this->fetch_class(); |
| 126 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 127 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 128 | if (isset($_GET[$this->config->item('function_trigger')])) |
| 129 | { |
| 130 | $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')]))); |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 131 | $segments[] = $this->fetch_method(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 134 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | // Load the routes.php file. |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 136 | if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php')) |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 137 | { |
| 138 | include(APPPATH.'config/'.ENVIRONMENT.'/routes.php'); |
| 139 | } |
| 140 | elseif (is_file(APPPATH.'config/routes.php')) |
| 141 | { |
| 142 | include(APPPATH.'config/routes.php'); |
| 143 | } |
David Behler | 07b5342 | 2011-08-15 00:25:06 +0200 | [diff] [blame] | 144 | |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 145 | $this->routes = (isset($route) && is_array($route)) ? $route : array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | unset($route); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 147 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 148 | // Set the default controller so we can display it in the event |
| 149 | // the URI doesn't correlated to a valid controller. |
Andrey Andreev | a3f5c5c | 2012-11-04 20:08:42 +0200 | [diff] [blame] | 150 | $this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 151 | |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 152 | // Were there any query string segments? If so, we'll validate them and bail out since we're done. |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 153 | if (count($segments) > 0) |
| 154 | { |
| 155 | return $this->_validate_request($segments); |
| 156 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 157 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 158 | // Fetch the complete URI string |
| 159 | $this->uri->_fetch_uri_string(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 160 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 161 | // Is there a URI string? If not, the default controller specified in the "routes" file will be shown. |
Andrey Andreev | 9ba661b | 2012-06-04 14:44:34 +0300 | [diff] [blame] | 162 | if ($this->uri->uri_string == '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | { |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 164 | return $this->_set_default_controller(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 167 | $this->uri->_remove_url_suffix(); // Remove the URL suffix |
| 168 | $this->uri->_explode_segments(); // Compile the segments into an array |
| 169 | $this->_parse_routes(); // Parse any custom routing that may exist |
| 170 | $this->uri->_reindex_segments(); // Re-index the segment array so that it starts with 1 rather than 0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | } |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 172 | |
| 173 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 174 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 175 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 176 | * Set default controller |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 177 | * |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 178 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 179 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 180 | protected function _set_default_controller() |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 181 | { |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 182 | if (empty($this->default_controller)) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 183 | { |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 184 | show_error('Unable to determine what should be displayed. A default route has not been specified in the routing file.'); |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 185 | } |
Andrey Andreev | d1097a1 | 2012-11-01 19:55:42 +0200 | [diff] [blame] | 186 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 187 | // Is the method being specified? |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 188 | if (sscanf($this->default_controller, '%[^/]/%s', $class, $method) !== 2) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 189 | { |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 190 | $method = 'index'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 191 | } |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 192 | |
| 193 | $this->set_class($class); |
| 194 | $this->set_method($method); |
| 195 | $this->_set_request(array($class, $method)); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 196 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 197 | // re-index the routed segments array so it starts with 1 rather than 0 |
| 198 | $this->uri->_reindex_segments(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 199 | |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 200 | log_message('debug', 'No URI present. Default controller set.'); |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 201 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 202 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 204 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 206 | * Set request route |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 208 | * Takes an array of URI segments as input and sets the class/method |
| 209 | * to be called. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 210 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 211 | * @param array $segments URI segments |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | * @return void |
| 213 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 214 | protected function _set_request($segments = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 215 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | $segments = $this->_validate_request($segments); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 217 | |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 218 | if (count($segments) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | { |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 220 | return $this->_set_default_controller(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 222 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | $this->set_class($segments[0]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 224 | |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 225 | isset($segments[1]) OR $segments[1] = 'index'; |
| 226 | $this->set_method($segments[1]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 227 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | // Update our "routed" segment array to contain the segments. |
| 229 | // Note: If there is no custom routing, this array will be |
Phil Sturgeon | 81aa94b | 2012-05-02 11:40:46 +0100 | [diff] [blame] | 230 | // identical to $this->uri->segments |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | $this->uri->rsegments = $segments; |
| 232 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 237 | * Validate request |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 238 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 239 | * Attempts validate the URI request and determine the controller path. |
| 240 | * |
| 241 | * @param array $segments URI segments |
| 242 | * @return array URI segments |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 243 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 244 | protected function _validate_request($segments) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | { |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 246 | if (count($segments) === 0) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 247 | { |
| 248 | return $segments; |
| 249 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 250 | |
Andrey Andreev | d1097a1 | 2012-11-01 19:55:42 +0200 | [diff] [blame] | 251 | $temp = str_replace('-', '_', $segments[0]); |
| 252 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | // Does the requested controller exist in the root folder? |
Andrey Andreev | d1097a1 | 2012-11-01 19:55:42 +0200 | [diff] [blame] | 254 | if (file_exists(APPPATH.'controllers/'.$temp.'.php')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | { |
Andrey Andreev | d1097a1 | 2012-11-01 19:55:42 +0200 | [diff] [blame] | 256 | $segments[0] = $temp; |
| 257 | empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | return $segments; |
| 259 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 260 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 261 | // Is the controller in a sub-folder? |
| 262 | if (is_dir(APPPATH.'controllers/'.$segments[0])) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 263 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | // Set the directory and remove it from the segment array |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 265 | $this->set_directory(array_shift($segments)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 266 | if (count($segments) > 0) |
| 267 | { |
Andrey Andreev | d1097a1 | 2012-11-01 19:55:42 +0200 | [diff] [blame] | 268 | $segments[0] = str_replace('-', '_', $segments[0]); |
| 269 | empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]); |
| 270 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 271 | // Does the requested controller exist in the sub-folder? |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 272 | if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 273 | { |
Shane Pearson | 664a935 | 2011-08-10 16:02:32 -0500 | [diff] [blame] | 274 | if ( ! empty($this->routes['404_override'])) |
| 275 | { |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 276 | $this->directory = ''; |
| 277 | return explode('/', $this->routes['404_override'], 2); |
Shane Pearson | 664a935 | 2011-08-10 16:02:32 -0500 | [diff] [blame] | 278 | } |
| 279 | else |
| 280 | { |
| 281 | show_404($this->fetch_directory().$segments[0]); |
| 282 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | else |
| 286 | { |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 287 | // Is the method being specified in the route? |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 288 | $segments = explode('/', $this->default_controller); |
| 289 | if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].'.php')) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | { |
| 291 | $this->directory = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 293 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 294 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | return $segments; |
| 296 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 297 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 298 | // If we've gotten this far it means that the URI does not correlate to a valid |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 299 | // controller class. We will now see if there is an override |
Eric Barnes | c5bf616 | 2011-01-30 21:17:11 -0500 | [diff] [blame] | 300 | if ( ! empty($this->routes['404_override'])) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 301 | { |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 302 | if (sscanf($this->routes['404_override'], '%[^/]/%s', $class, $method) !== 2) |
| 303 | { |
| 304 | $method = 'index'; |
| 305 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 307 | return array($class, $method); |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 308 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 309 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 310 | // Nothing else to do at this point but show a 404 |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 311 | show_404($segments[0]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 312 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 313 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 314 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 315 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | /** |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 317 | * Parse Routes |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 319 | * Matches any routes that may exist in the config/routes.php file |
| 320 | * against the URI to determine if the class/method need to be remapped. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | * @return void |
| 323 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 324 | protected function _parse_routes() |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 325 | { |
| 326 | // Turn the segment array into a URI string |
| 327 | $uri = implode('/', $this->uri->segments); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 328 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 329 | // Is there a literal match? If so we're done |
| 330 | if (isset($this->routes[$uri])) |
| 331 | { |
| 332 | return $this->_set_request(explode('/', $this->routes[$uri])); |
| 333 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 334 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 335 | // Loop through the route array looking for wild-cards |
| 336 | foreach ($this->routes as $key => $val) |
| 337 | { |
| 338 | // Convert wild-cards to RegEx |
Andrey Andreev | 7676c2d | 2012-10-30 13:42:01 +0200 | [diff] [blame] | 339 | $key = str_replace(array(':any', ':num'), array('[^/]+', '[0-9]+'), $key); |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 340 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 341 | // Does the RegEx match? |
| 342 | if (preg_match('#^'.$key.'$#', $uri, $matches)) |
| 343 | { |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 344 | // Are we using callbacks to process back-references? |
Andrey Andreev | da5562a | 2012-11-08 12:34:38 +0200 | [diff] [blame^] | 345 | if ( ! is_string($val) && is_callable($val)) |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 346 | { |
| 347 | // Remove the original string from the matches array. |
| 348 | array_shift($matches); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 350 | // Get the match count. |
| 351 | $match_count = count($matches); |
Jonatas Miguel | c0d98b2 | 2012-08-06 15:42:50 +0100 | [diff] [blame] | 352 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 353 | // Determine how many parameters the callback has. |
| 354 | $reflection = new ReflectionFunction($val); |
| 355 | $param_count = $reflection->getNumberOfParameters(); |
Jonatas Miguel | c0d98b2 | 2012-08-06 15:42:50 +0100 | [diff] [blame] | 356 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 357 | // Are there more parameters than matches? |
Jonatas Miguel | 24296ca | 2012-09-27 12:10:01 +0100 | [diff] [blame] | 358 | if ($param_count > $match_count) |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 359 | { |
| 360 | // Any params without matches will be set to an empty string. |
| 361 | $matches = array_merge($matches, array_fill($match_count, $param_count - $match_count, '')); |
Jonatas Miguel | efb8166 | 2012-10-23 19:52:46 +0100 | [diff] [blame] | 362 | |
| 363 | $match_count = $param_count; |
| 364 | } |
| 365 | |
| 366 | // Get the parameters so we can use their default values. |
| 367 | $params = $reflection->getParameters(); |
| 368 | |
| 369 | for ($m = 0; $m < $match_count; $m++) |
| 370 | { |
| 371 | // Is the match empty and does a default value exist? |
| 372 | if (empty($matches[$m]) && $params[$m]->isDefaultValueAvailable()) |
| 373 | { |
| 374 | // Substitute the empty match for the default value. |
| 375 | $matches[$m] = $params[$m]->getDefaultValue(); |
| 376 | } |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 377 | } |
Jonatas Miguel | c0d98b2 | 2012-08-06 15:42:50 +0100 | [diff] [blame] | 378 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 379 | // Execute the callback using the values in matches as its parameters. |
| 380 | $val = call_user_func_array($val, $matches); |
| 381 | } |
Andrey Andreev | da5562a | 2012-11-08 12:34:38 +0200 | [diff] [blame^] | 382 | // Are we using the default routing method for back-references? |
| 383 | elseif (strpos($val, '$') !== FALSE && strpos($key, '(') !== FALSE) |
| 384 | { |
| 385 | $val = preg_replace('#^'.$key.'$#', $val, $uri); |
| 386 | } |
Jonatas Miguel | c0d98b2 | 2012-08-06 15:42:50 +0100 | [diff] [blame] | 387 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 388 | return $this->_set_request(explode('/', $val)); |
| 389 | } |
| 390 | } |
Jonatas Miguel | c0d98b2 | 2012-08-06 15:42:50 +0100 | [diff] [blame] | 391 | |
Jonatas Miguel | 59dbe85 | 2012-08-07 12:13:32 +0100 | [diff] [blame] | 392 | // If we got this far it means we didn't encounter a |
| 393 | // matching route so we'll set the site default route |
| 394 | $this->_set_request($this->uri->segments); |
| 395 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | |
| 397 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 400 | * Set class name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 402 | * @param string $class Class name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 404 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 405 | public function set_class($class) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 406 | { |
Derek Jones | 2615e41 | 2010-10-06 17:51:16 -0500 | [diff] [blame] | 407 | $this->class = str_replace(array('/', '.'), '', $class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 409 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 411 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | /** |
| 413 | * Fetch the current class |
| 414 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 415 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 416 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 417 | public function fetch_class() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 418 | { |
| 419 | return $this->class; |
| 420 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 421 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 423 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 425 | * Set method name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 427 | * @param string $method Method name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 429 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 430 | public function set_method($method) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | { |
| 432 | $this->method = $method; |
| 433 | } |
| 434 | |
| 435 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 436 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 437 | /** |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 438 | * Fetch the current method |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 441 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 442 | public function fetch_method() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | { |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 444 | return ($this->method === $this->fetch_class()) ? 'index' : $this->method; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 448 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 450 | * Set directory name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 451 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 452 | * @param string $dir Directory name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 454 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 455 | public function set_directory($dir) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | { |
Derek Jones | 2615e41 | 2010-10-06 17:51:16 -0500 | [diff] [blame] | 457 | $this->directory = str_replace(array('/', '.'), '', $dir).'/'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 461 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 462 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 463 | * Fetch directory |
| 464 | * |
| 465 | * Feches the sub-directory (if any) that contains the requested |
| 466 | * controller class. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 467 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 469 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 470 | public function fetch_directory() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | { |
| 472 | return $this->directory; |
| 473 | } |
| 474 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 475 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 476 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 477 | /** |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 478 | * Set controller overrides |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 479 | * |
Andrey Andreev | b9fe7e9 | 2012-10-27 18:45:59 +0300 | [diff] [blame] | 480 | * @param array $routing Route overrides |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 481 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 482 | */ |
Andrey Andreev | ba6c041 | 2012-01-07 21:10:09 +0200 | [diff] [blame] | 483 | public function _set_overrides($routing) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 484 | { |
| 485 | if ( ! is_array($routing)) |
| 486 | { |
| 487 | return; |
| 488 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 489 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 490 | if (isset($routing['directory'])) |
| 491 | { |
| 492 | $this->set_directory($routing['directory']); |
| 493 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 494 | |
Andrey Andreev | 9ba661b | 2012-06-04 14:44:34 +0300 | [diff] [blame] | 495 | if ( ! empty($routing['controller'])) |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 496 | { |
| 497 | $this->set_class($routing['controller']); |
| 498 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 499 | |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 500 | if (isset($routing['function'])) |
| 501 | { |
Andrey Andreev | 533bf2d | 2012-11-02 22:44:29 +0200 | [diff] [blame] | 502 | $routing['function'] = empty($routing['function']) ? 'index' : $routing['function']; |
Derek Jones | c773840 | 2010-03-02 13:55:13 -0600 | [diff] [blame] | 503 | $this->set_method($routing['function']); |
| 504 | } |
| 505 | } |
| 506 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 507 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | |
| 509 | /* End of file Router.php */ |
Andrey Andreev | 7b53d04 | 2012-03-26 23:02:32 +0300 | [diff] [blame] | 510 | /* Location: ./system/core/Router.php */ |