blob: a7118bfc7243fcccdf3a0bff761515d9063f9dbc [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev9c5c24a2012-01-07 18:51:21 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev9c5c24a2012-01-07 18:51:21 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
Derek Jones218876c2010-03-02 13:11:00 -060030 * System Initialization File
Derek Allard2067d1a2008-11-13 22:59:24 +000031 *
32 * Loads the base classes and executes the request.
33 *
34 * @package CodeIgniter
Andrey Andreev92ebfb62012-05-17 12:49:24 +030035 * @subpackage CodeIgniter
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @category Front-controller
Derek Jonesf4a4bd82011-10-20 12:18:42 -050037 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000038 * @link http://codeigniter.com/user_guide/
39 */
40
Phil Sturgeond8ef6302011-08-14 12:10:55 -060041/**
42 * CodeIgniter Version
43 *
Timothy Warren48a7fbb2012-04-23 11:58:16 -040044 * @var string
Phil Sturgeond8ef6302011-08-14 12:10:55 -060045 *
Derek Jones218876c2010-03-02 13:11:00 -060046 */
Derek Jonesf4a4bd82011-10-20 12:18:42 -050047 define('CI_VERSION', '3.0-dev');
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +020048
Derek Allard2067d1a2008-11-13 22:59:24 +000049/*
50 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -050051 * Load the framework constants
Derek Allard2067d1a2008-11-13 22:59:24 +000052 * ------------------------------------------------------
53 */
Andrey Andreevdb529ca2013-01-28 11:00:02 +020054 if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
Greg Akerd96f8822011-12-27 16:23:47 -060055 {
Andrey Andreev30d53242014-01-16 14:41:46 +020056 require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
Greg Akerd96f8822011-12-27 16:23:47 -060057 }
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +020058
Andrey Andreev30d53242014-01-16 14:41:46 +020059 require_once(APPPATH.'config/constants.php');
Derek Allard2067d1a2008-11-13 22:59:24 +000060
61/*
62 * ------------------------------------------------------
josephok1095d112013-11-16 09:33:37 +080063 * Load the global functions
64 * ------------------------------------------------------
65 */
66 require_once(BASEPATH.'core/Common.php');
67
Andrey Andreevb78a8c72014-04-15 17:21:16 +030068
69/*
70 * ------------------------------------------------------
71 * Security procedures
72 * ------------------------------------------------------
73 */
74
75if ( ! is_php('5.4'))
76{
77 ini_set('magic_quotes_runtime', 0);
78
79 if ((bool) ini_get('register_globals'))
80 {
81 $_protected = array(
82 '_SERVER',
83 '_GET',
84 '_POST',
85 '_FILES',
86 '_REQUEST',
87 '_SESSION',
88 '_ENV',
89 '_COOKIE',
90 'GLOBALS',
91 'HTTP_RAW_POST_DATA',
vlakoffde70dbb2014-04-15 16:46:03 +020092 'system_path',
Andrey Andreevb78a8c72014-04-15 17:21:16 +030093 'application_folder',
94 'view_folder',
95 '_protected',
96 '_registered'
97 );
98
99 $_registered = ini_get('variables_order');
100 foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal)
101 {
102 if (strpos($_registered, $key) === FALSE)
103 {
104 continue;
105 }
106
107 foreach (array_keys($$superglobal) as $var)
108 {
109 if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE))
110 {
111 $GLOBALS[$var] = NULL;
112 }
113 }
114 }
115 }
116}
117
118
josephok1095d112013-11-16 09:33:37 +0800119/*
120 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500121 * Define a custom error handler so we can log PHP errors
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 * ------------------------------------------------------
123 */
Derek Jones218876c2010-03-02 13:11:00 -0600124 set_error_handler('_exception_handler');
Kaiwang Chen21fe9da2013-09-11 13:09:41 +0800125 register_shutdown_function('_shutdown_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200126
Derek Jones218876c2010-03-02 13:11:00 -0600127/*
128 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500129 * Set the subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -0600130 * ------------------------------------------------------
131 *
Barry Mienydd671972010-10-04 16:33:58 +0200132 * Normally the "subclass_prefix" is set in the config file.
133 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -0600134 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +0200135 * "libraries" folder. Since CI allows config items to be
vlakoff8d70c0a2013-08-17 07:31:29 +0200136 * overriden via data set in the main index.php file,
Barry Mienydd671972010-10-04 16:33:58 +0200137 * before proceeding we need to know if a subclass_prefix
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200138 * override exists. If so, we will set this value now,
Derek Jones218876c2010-03-02 13:11:00 -0600139 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +0200140 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -0600141 * hurt to load it here.
142 */
Andrey Andreev9ba661b2012-06-04 14:44:34 +0300143 if ( ! empty($assign_to_config['subclass_prefix']))
Derek Jones218876c2010-03-02 13:11:00 -0600144 {
145 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
146 }
Eric Barnesc5bf6162011-01-30 21:17:11 -0500147
Pascal Krietef566af52010-11-09 13:03:26 -0500148/*
149 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500150 * Start the timer... tick tock tick tock...
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 * ------------------------------------------------------
152 */
Derek Jones218876c2010-03-02 13:11:00 -0600153 $BM =& load_class('Benchmark', 'core');
154 $BM->mark('total_execution_time_start');
155 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000156
157/*
158 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500159 * Instantiate the hooks class
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * ------------------------------------------------------
161 */
Derek Jones218876c2010-03-02 13:11:00 -0600162 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000163
164/*
165 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500166 * Is there a "pre_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 * ------------------------------------------------------
168 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300169 $EXT->call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000170
171/*
172 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500173 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200175 *
176 * Note: It is important that Config is loaded first as
177 * most other classes depend on it either directly or by
178 * depending on another class that uses it.
179 *
Barry Mienydd671972010-10-04 16:33:58 +0200180 */
Derek Jones218876c2010-03-02 13:11:00 -0600181 $CFG =& load_class('Config', 'core');
182
183 // Do we have any manually set config items in the index.php file?
Andrey Andreev5232ba02012-10-27 15:25:05 +0300184 if (isset($assign_to_config) && is_array($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200185 {
Andrey Andreev5232ba02012-10-27 15:25:05 +0300186 foreach ($assign_to_config as $key => $value)
187 {
188 $CFG->set_item($key, $value);
189 }
Derek Jones218876c2010-03-02 13:11:00 -0600190 }
191
192/*
193 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200194 * Important charset-related stuff
Derek Jones218876c2010-03-02 13:11:00 -0600195 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200196 *
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200197 * Configure mbstring and/or iconv if they are enabled
198 * and set MB_ENABLED and ICONV_ENABLED constants, so
199 * that we don't repeatedly do extension_loaded() or
200 * function_exists() calls.
Barry Mienydd671972010-10-04 16:33:58 +0200201 *
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200202 * Note: UTF-8 class depends on this. It used to be done
203 * in it's constructor, but it's _not_ class-specific.
204 *
205 */
206 $charset = strtoupper(config_item('charset'));
Andrey Andreev51593f42014-05-07 00:06:31 +0300207 ini_set('default_charset', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200208
209 if (extension_loaded('mbstring'))
210 {
211 define('MB_ENABLED', TRUE);
Andrey Andreev51593f42014-05-07 00:06:31 +0300212 ini_set('mbstring.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200213 // This is required for mb_convert_encoding() to strip invalid characters.
214 // That's utilized by CI_Utf8, but it's also done for consistency with iconv.
215 mb_substitute_character('none');
216 }
217 else
218 {
219 define('MB_ENABLED', FALSE);
220 }
221
222 // There's an ICONV_IMPL constant, but the PHP manual says that using
223 // iconv's predefined constants is "strongly discouraged".
224 if (extension_loaded('iconv'))
225 {
226 define('ICONV_ENABLED', TRUE);
Andrey Andreev51593f42014-05-07 00:06:31 +0300227 // iconv.internal_encoding is deprecated starting with PHP 5.6
228 // and it's usage triggers E_DEPRECATED messages.
229 @ini_set('iconv.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200230 }
231 else
232 {
233 define('ICONV_ENABLED', FALSE);
234 }
235
Andrey Andreev51593f42014-05-07 00:06:31 +0300236 if (is_php('5.6'))
237 {
238 ini_set('php.internal_encoding', $charset);
239 }
240
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200241/*
242 * ------------------------------------------------------
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200243 * Load compatibility features
244 * ------------------------------------------------------
245 */
246
Andrey Andreev376b2152014-02-13 12:35:52 +0200247 require_once(BASEPATH.'core/compat/mbstring.php');
Andrey Andreev9a152a92014-02-18 16:29:53 +0200248 require_once(BASEPATH.'core/compat/hash.php');
Andrey Andreev376b2152014-02-13 12:35:52 +0200249 require_once(BASEPATH.'core/compat/password.php');
Andrey Andreev02545892014-02-19 23:49:31 +0200250 require_once(BASEPATH.'core/compat/array.php');
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200251
252/*
253 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200254 * Instantiate the UTF-8 class
255 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 */
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500257 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200258
Derek Jones218876c2010-03-02 13:11:00 -0600259/*
260 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500261 * Instantiate the URI class
Derek Jones218876c2010-03-02 13:11:00 -0600262 * ------------------------------------------------------
263 */
264 $URI =& load_class('URI', 'core');
265
266/*
267 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500268 * Instantiate the routing class and set the routing
Derek Jones218876c2010-03-02 13:11:00 -0600269 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200270 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200271 $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
Barry Mienydd671972010-10-04 16:33:58 +0200272
Derek Jones218876c2010-03-02 13:11:00 -0600273/*
274 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500275 * Instantiate the output class
Derek Jones218876c2010-03-02 13:11:00 -0600276 * ------------------------------------------------------
277 */
278 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000279
280/*
281 * ------------------------------------------------------
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200282 * Is there a valid cache file? If so, we're done...
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 * ------------------------------------------------------
284 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200285 if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200287 exit;
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000289
290/*
Pascal Kriete14a0ac62011-04-05 14:55:56 -0400291 * -----------------------------------------------------
292 * Load the security class for xss and csrf support
293 * -----------------------------------------------------
294 */
295 $SEC =& load_class('Security', 'core');
296
297/*
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500299 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * ------------------------------------------------------
301 */
Barry Mienydd671972010-10-04 16:33:58 +0200302 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000303
Derek Jones218876c2010-03-02 13:11:00 -0600304/*
305 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500306 * Load the Language class
Derek Jones218876c2010-03-02 13:11:00 -0600307 * ------------------------------------------------------
308 */
309 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000310
311/*
312 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500313 * Load the app controller and local controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 * ------------------------------------------------------
315 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 */
Derek Jones218876c2010-03-02 13:11:00 -0600317 // Load the base controller class
Andrey Andreev30d53242014-01-16 14:41:46 +0200318 require_once BASEPATH.'core/Controller.php';
Barry Mienydd671972010-10-04 16:33:58 +0200319
Timothy Warrenad475052012-04-19 13:21:06 -0400320 /**
321 * Reference to the CI_Controller method.
322 *
323 * Returns current CI instance object
324 *
325 * @return object
326 */
Greg Aker4abfa682010-11-10 14:44:26 -0600327 function &get_instance()
328 {
329 return CI_Controller::get_instance();
330 }
331
Greg Aker3a746652011-04-19 10:59:47 -0500332 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
Greg Akerfa281352010-03-22 14:41:27 -0500333 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200334 require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
Greg Akerfa281352010-03-22 14:41:27 -0500335 }
Barry Mienydd671972010-10-04 16:33:58 +0200336
Derek Jones218876c2010-03-02 13:11:00 -0600337 // Set a mark point for benchmarking
338 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000339
340/*
341 * ------------------------------------------------------
Andrey Andreev30d53242014-01-16 14:41:46 +0200342 * Sanity checks
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 * ------------------------------------------------------
344 *
Andrey Andreev30d53242014-01-16 14:41:46 +0200345 * The Router class has already validated the request,
346 * leaving us with 3 options here:
347 *
348 * 1) an empty class name, if we reached the default
349 * controller, but it didn't exist;
350 * 2) a query string which doesn't go through a
351 * file_exists() check
352 * 3) a regular request for a non-existing page
353 *
354 * We handle all of these as a 404 error.
355 *
356 * Furthermore, none of the methods in the app controller
357 * or the loader class can be called via the URI, nor can
Andrey Andreev20292312013-07-22 14:29:10 +0300358 * controller methods that begin with an underscore.
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 */
Barry Mienydd671972010-10-04 16:33:58 +0200360
Andrey Andreev30d53242014-01-16 14:41:46 +0200361 $e404 = FALSE;
362 $class = ucfirst($RTR->class);
363 $method = $RTR->method;
364
365 if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
Derek Jones218876c2010-03-02 13:11:00 -0600366 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200367 $e404 = TRUE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200368 }
369 else
370 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200371 require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
372
373 if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
374 {
375 $e404 = TRUE;
376 }
377 elseif (method_exists($class, '_remap'))
378 {
379 $params = array($method, array_slice($URI->rsegments, 2));
380 $method = '_remap';
381 }
Andrey Andreev522c7362012-11-05 16:40:32 +0200382 // WARNING: It appears that there are issues with is_callable() even in PHP 5.2!
383 // Furthermore, there are bug reports and feature/change requests related to it
384 // that make it unreliable to use in this context. Please, DO NOT change this
385 // work-around until a better alternative is available.
Andrey Andreev30d53242014-01-16 14:41:46 +0200386 elseif ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200387 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200388 $e404 = TRUE;
389 }
390 }
391
392 if ($e404)
393 {
394 if ( ! empty($RTR->routes['404_override']))
395 {
396 if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
Andrey Andreev38e32f62012-11-03 00:16:47 +0200397 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200398 $error_method = 'index';
Andrey Andreev38e32f62012-11-03 00:16:47 +0200399 }
400
Andrey Andreev30d53242014-01-16 14:41:46 +0200401 $error_class = ucfirst($error_class);
Andrey Andreev20292312013-07-22 14:29:10 +0300402
Andrey Andreev30d53242014-01-16 14:41:46 +0200403 if ( ! class_exists($error_class, FALSE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200404 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200405 if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200406 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200407 require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
408 $e404 = ! class_exists($error_class, FALSE);
Andrey Andreev38e32f62012-11-03 00:16:47 +0200409 }
Andrey Andreev30d53242014-01-16 14:41:46 +0200410 // Were we in a directory? If so, check for a global override
411 elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
412 {
413 require_once(APPPATH.'controllers/'.$error_class.'.php');
414 if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
415 {
416 $RTR->directory = '';
417 }
418 }
419 }
420 else
421 {
422 $e404 = FALSE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200423 }
424 }
425
Andrey Andreev30d53242014-01-16 14:41:46 +0200426 // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
427 if ( ! $e404)
428 {
429 $class = $error_class;
430 $method = $error_method;
431
432 $URI->rsegments = array(
433 1 => $class,
434 2 => $method
435 );
436 }
437 else
438 {
439 show_404($RTR->directory.$class.'/'.$method);
440 }
441 }
442
443 if ($method !== '_remap')
444 {
Andrey Andreev38e32f62012-11-03 00:16:47 +0200445 $params = array_slice($URI->rsegments, 2);
446 }
447
Derek Allard2067d1a2008-11-13 22:59:24 +0000448/*
449 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500450 * Is there a "pre_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * ------------------------------------------------------
452 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300453 $EXT->call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000454
455/*
456 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500457 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 * ------------------------------------------------------
459 */
Derek Jones218876c2010-03-02 13:11:00 -0600460 // Mark a start point so we can benchmark the controller
461 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200462
Derek Jones218876c2010-03-02 13:11:00 -0600463 $CI = new $class();
464
465/*
466 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500467 * Is there a "post_controller_constructor" hook?
Derek Jones218876c2010-03-02 13:11:00 -0600468 * ------------------------------------------------------
469 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300470 $EXT->call_hook('post_controller_constructor');
Derek Jones218876c2010-03-02 13:11:00 -0600471
472/*
473 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500474 * Call the requested method
Derek Jones218876c2010-03-02 13:11:00 -0600475 * ------------------------------------------------------
476 */
Andrey Andreev38e32f62012-11-03 00:16:47 +0200477 call_user_func_array(array(&$CI, $method), $params);
Derek Allard2067d1a2008-11-13 22:59:24 +0000478
Derek Jones218876c2010-03-02 13:11:00 -0600479 // Mark a benchmark end point
480 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000481
482/*
483 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500484 * Is there a "post_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 * ------------------------------------------------------
486 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300487 $EXT->call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000488
489/*
490 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500491 * Send the final rendered output to the browser
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 * ------------------------------------------------------
493 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300494 if ($EXT->call_hook('display_override') === FALSE)
Derek Jones218876c2010-03-02 13:11:00 -0600495 {
496 $OUT->_display();
497 }
Barry Mienydd671972010-10-04 16:33:58 +0200498
Derek Allard2067d1a2008-11-13 22:59:24 +0000499/*
500 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500501 * Is there a "post_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 * ------------------------------------------------------
503 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300504 $EXT->call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000505
Derek Allard2067d1a2008-11-13 22:59:24 +0000506/* End of file CodeIgniter.php */
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +0200507/* Location: ./system/core/CodeIgniter.php */