blob: 1c6e76b4ff7331dac9f1df12b069b0c2adee526f [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 Andreev1ffa2232014-05-09 12:30:59 +0300212 // mbstring.internal_encoding is deprecated starting with PHP 5.6
213 // and it's usage triggers E_DEPRECATED messages.
214 @ini_set('mbstring.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200215 // This is required for mb_convert_encoding() to strip invalid characters.
216 // That's utilized by CI_Utf8, but it's also done for consistency with iconv.
217 mb_substitute_character('none');
218 }
219 else
220 {
221 define('MB_ENABLED', FALSE);
222 }
223
224 // There's an ICONV_IMPL constant, but the PHP manual says that using
225 // iconv's predefined constants is "strongly discouraged".
226 if (extension_loaded('iconv'))
227 {
228 define('ICONV_ENABLED', TRUE);
Andrey Andreev51593f42014-05-07 00:06:31 +0300229 // iconv.internal_encoding is deprecated starting with PHP 5.6
230 // and it's usage triggers E_DEPRECATED messages.
231 @ini_set('iconv.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200232 }
233 else
234 {
235 define('ICONV_ENABLED', FALSE);
236 }
237
Andrey Andreev51593f42014-05-07 00:06:31 +0300238 if (is_php('5.6'))
239 {
240 ini_set('php.internal_encoding', $charset);
241 }
242
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200243/*
244 * ------------------------------------------------------
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200245 * Load compatibility features
246 * ------------------------------------------------------
247 */
248
Andrey Andreev376b2152014-02-13 12:35:52 +0200249 require_once(BASEPATH.'core/compat/mbstring.php');
Andrey Andreev9a152a92014-02-18 16:29:53 +0200250 require_once(BASEPATH.'core/compat/hash.php');
Andrey Andreev376b2152014-02-13 12:35:52 +0200251 require_once(BASEPATH.'core/compat/password.php');
Andrey Andreev02545892014-02-19 23:49:31 +0200252 require_once(BASEPATH.'core/compat/array.php');
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200253
254/*
255 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200256 * Instantiate the UTF-8 class
257 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 */
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500259 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200260
Derek Jones218876c2010-03-02 13:11:00 -0600261/*
262 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500263 * Instantiate the URI class
Derek Jones218876c2010-03-02 13:11:00 -0600264 * ------------------------------------------------------
265 */
266 $URI =& load_class('URI', 'core');
267
268/*
269 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500270 * Instantiate the routing class and set the routing
Derek Jones218876c2010-03-02 13:11:00 -0600271 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200272 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200273 $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
Barry Mienydd671972010-10-04 16:33:58 +0200274
Derek Jones218876c2010-03-02 13:11:00 -0600275/*
276 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500277 * Instantiate the output class
Derek Jones218876c2010-03-02 13:11:00 -0600278 * ------------------------------------------------------
279 */
280 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000281
282/*
283 * ------------------------------------------------------
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200284 * Is there a valid cache file? If so, we're done...
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 * ------------------------------------------------------
286 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200287 if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 {
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200289 exit;
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000291
292/*
Pascal Kriete14a0ac62011-04-05 14:55:56 -0400293 * -----------------------------------------------------
294 * Load the security class for xss and csrf support
295 * -----------------------------------------------------
296 */
297 $SEC =& load_class('Security', 'core');
298
299/*
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500301 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 * ------------------------------------------------------
303 */
Barry Mienydd671972010-10-04 16:33:58 +0200304 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000305
Derek Jones218876c2010-03-02 13:11:00 -0600306/*
307 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500308 * Load the Language class
Derek Jones218876c2010-03-02 13:11:00 -0600309 * ------------------------------------------------------
310 */
311 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000312
313/*
314 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500315 * Load the app controller and local controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 * ------------------------------------------------------
317 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 */
Derek Jones218876c2010-03-02 13:11:00 -0600319 // Load the base controller class
Andrey Andreev30d53242014-01-16 14:41:46 +0200320 require_once BASEPATH.'core/Controller.php';
Barry Mienydd671972010-10-04 16:33:58 +0200321
Timothy Warrenad475052012-04-19 13:21:06 -0400322 /**
323 * Reference to the CI_Controller method.
324 *
325 * Returns current CI instance object
326 *
327 * @return object
328 */
Greg Aker4abfa682010-11-10 14:44:26 -0600329 function &get_instance()
330 {
331 return CI_Controller::get_instance();
332 }
333
Greg Aker3a746652011-04-19 10:59:47 -0500334 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
Greg Akerfa281352010-03-22 14:41:27 -0500335 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200336 require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
Greg Akerfa281352010-03-22 14:41:27 -0500337 }
Barry Mienydd671972010-10-04 16:33:58 +0200338
Derek Jones218876c2010-03-02 13:11:00 -0600339 // Set a mark point for benchmarking
340 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000341
342/*
343 * ------------------------------------------------------
Andrey Andreev30d53242014-01-16 14:41:46 +0200344 * Sanity checks
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 * ------------------------------------------------------
346 *
Andrey Andreev30d53242014-01-16 14:41:46 +0200347 * The Router class has already validated the request,
348 * leaving us with 3 options here:
349 *
350 * 1) an empty class name, if we reached the default
351 * controller, but it didn't exist;
352 * 2) a query string which doesn't go through a
353 * file_exists() check
354 * 3) a regular request for a non-existing page
355 *
356 * We handle all of these as a 404 error.
357 *
358 * Furthermore, none of the methods in the app controller
359 * or the loader class can be called via the URI, nor can
Andrey Andreev20292312013-07-22 14:29:10 +0300360 * controller methods that begin with an underscore.
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 */
Barry Mienydd671972010-10-04 16:33:58 +0200362
Andrey Andreev30d53242014-01-16 14:41:46 +0200363 $e404 = FALSE;
364 $class = ucfirst($RTR->class);
365 $method = $RTR->method;
366
367 if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
Derek Jones218876c2010-03-02 13:11:00 -0600368 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200369 $e404 = TRUE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200370 }
371 else
372 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200373 require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
374
375 if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
376 {
377 $e404 = TRUE;
378 }
379 elseif (method_exists($class, '_remap'))
380 {
381 $params = array($method, array_slice($URI->rsegments, 2));
382 $method = '_remap';
383 }
Andrey Andreev522c7362012-11-05 16:40:32 +0200384 // WARNING: It appears that there are issues with is_callable() even in PHP 5.2!
385 // Furthermore, there are bug reports and feature/change requests related to it
386 // that make it unreliable to use in this context. Please, DO NOT change this
387 // work-around until a better alternative is available.
Andrey Andreev30d53242014-01-16 14:41:46 +0200388 elseif ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200389 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200390 $e404 = TRUE;
391 }
392 }
393
394 if ($e404)
395 {
396 if ( ! empty($RTR->routes['404_override']))
397 {
398 if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
Andrey Andreev38e32f62012-11-03 00:16:47 +0200399 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200400 $error_method = 'index';
Andrey Andreev38e32f62012-11-03 00:16:47 +0200401 }
402
Andrey Andreev30d53242014-01-16 14:41:46 +0200403 $error_class = ucfirst($error_class);
Andrey Andreev20292312013-07-22 14:29:10 +0300404
Andrey Andreev30d53242014-01-16 14:41:46 +0200405 if ( ! class_exists($error_class, FALSE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200406 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200407 if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200408 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200409 require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
410 $e404 = ! class_exists($error_class, FALSE);
Andrey Andreev38e32f62012-11-03 00:16:47 +0200411 }
Andrey Andreev30d53242014-01-16 14:41:46 +0200412 // Were we in a directory? If so, check for a global override
413 elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
414 {
415 require_once(APPPATH.'controllers/'.$error_class.'.php');
416 if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
417 {
418 $RTR->directory = '';
419 }
420 }
421 }
422 else
423 {
424 $e404 = FALSE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200425 }
426 }
427
Andrey Andreev30d53242014-01-16 14:41:46 +0200428 // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
429 if ( ! $e404)
430 {
431 $class = $error_class;
432 $method = $error_method;
433
434 $URI->rsegments = array(
435 1 => $class,
436 2 => $method
437 );
438 }
439 else
440 {
441 show_404($RTR->directory.$class.'/'.$method);
442 }
443 }
444
445 if ($method !== '_remap')
446 {
Andrey Andreev38e32f62012-11-03 00:16:47 +0200447 $params = array_slice($URI->rsegments, 2);
448 }
449
Derek Allard2067d1a2008-11-13 22:59:24 +0000450/*
451 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500452 * Is there a "pre_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 * ------------------------------------------------------
454 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300455 $EXT->call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000456
457/*
458 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500459 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 * ------------------------------------------------------
461 */
Derek Jones218876c2010-03-02 13:11:00 -0600462 // Mark a start point so we can benchmark the controller
463 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200464
Derek Jones218876c2010-03-02 13:11:00 -0600465 $CI = new $class();
466
467/*
468 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500469 * Is there a "post_controller_constructor" hook?
Derek Jones218876c2010-03-02 13:11:00 -0600470 * ------------------------------------------------------
471 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300472 $EXT->call_hook('post_controller_constructor');
Derek Jones218876c2010-03-02 13:11:00 -0600473
474/*
475 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500476 * Call the requested method
Derek Jones218876c2010-03-02 13:11:00 -0600477 * ------------------------------------------------------
478 */
Andrey Andreev38e32f62012-11-03 00:16:47 +0200479 call_user_func_array(array(&$CI, $method), $params);
Derek Allard2067d1a2008-11-13 22:59:24 +0000480
Derek Jones218876c2010-03-02 13:11:00 -0600481 // Mark a benchmark end point
482 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000483
484/*
485 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500486 * Is there a "post_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 * ------------------------------------------------------
488 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300489 $EXT->call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000490
491/*
492 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500493 * Send the final rendered output to the browser
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 * ------------------------------------------------------
495 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300496 if ($EXT->call_hook('display_override') === FALSE)
Derek Jones218876c2010-03-02 13:11:00 -0600497 {
498 $OUT->_display();
499 }
Barry Mienydd671972010-10-04 16:33:58 +0200500
Derek Allard2067d1a2008-11-13 22:59:24 +0000501/*
502 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500503 * Is there a "post_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 * ------------------------------------------------------
505 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300506 $EXT->call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000507
Derek Allard2067d1a2008-11-13 22:59:24 +0000508/* End of file CodeIgniter.php */
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +0200509/* Location: ./system/core/CodeIgniter.php */