blob: e3d3a1ffbefcb46c37320f028ae7d40bfd6b1d46 [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 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev9c5c24a2012-01-07 18:51:21 +02008 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02009 * Copyright (c) 2014, British Columbia Institute of Technology
Andrey Andreev9c5c24a2012-01-07 18:51:21 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
Derek Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 * @package CodeIgniter
30 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020032 * @copyright Copyright (c) 2014, British Columbia Institute of Technology (http://bcit.ca/)
33 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 1.0.0
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @filesource
37 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
Derek Jones218876c2010-03-02 13:11:00 -060041 * System Initialization File
Derek Allard2067d1a2008-11-13 22:59:24 +000042 *
43 * Loads the base classes and executes the request.
44 *
45 * @package CodeIgniter
Andrey Andreev92ebfb62012-05-17 12:49:24 +030046 * @subpackage CodeIgniter
Derek Allard2067d1a2008-11-13 22:59:24 +000047 * @category Front-controller
Derek Jonesf4a4bd82011-10-20 12:18:42 -050048 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000049 * @link http://codeigniter.com/user_guide/
50 */
51
Phil Sturgeond8ef6302011-08-14 12:10:55 -060052/**
53 * CodeIgniter Version
54 *
Timothy Warren48a7fbb2012-04-23 11:58:16 -040055 * @var string
Phil Sturgeond8ef6302011-08-14 12:10:55 -060056 *
Derek Jones218876c2010-03-02 13:11:00 -060057 */
Derek Jonesf4a4bd82011-10-20 12:18:42 -050058 define('CI_VERSION', '3.0-dev');
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +020059
Derek Allard2067d1a2008-11-13 22:59:24 +000060/*
61 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -050062 * Load the framework constants
Derek Allard2067d1a2008-11-13 22:59:24 +000063 * ------------------------------------------------------
64 */
Andrey Andreevdb529ca2013-01-28 11:00:02 +020065 if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
Greg Akerd96f8822011-12-27 16:23:47 -060066 {
Andrey Andreev30d53242014-01-16 14:41:46 +020067 require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
Greg Akerd96f8822011-12-27 16:23:47 -060068 }
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +020069
Andrey Andreev30d53242014-01-16 14:41:46 +020070 require_once(APPPATH.'config/constants.php');
Derek Allard2067d1a2008-11-13 22:59:24 +000071
72/*
73 * ------------------------------------------------------
josephok1095d112013-11-16 09:33:37 +080074 * Load the global functions
75 * ------------------------------------------------------
76 */
77 require_once(BASEPATH.'core/Common.php');
78
Andrey Andreevb78a8c72014-04-15 17:21:16 +030079
80/*
81 * ------------------------------------------------------
82 * Security procedures
83 * ------------------------------------------------------
84 */
85
86if ( ! is_php('5.4'))
87{
88 ini_set('magic_quotes_runtime', 0);
89
90 if ((bool) ini_get('register_globals'))
91 {
92 $_protected = array(
93 '_SERVER',
94 '_GET',
95 '_POST',
96 '_FILES',
97 '_REQUEST',
98 '_SESSION',
99 '_ENV',
100 '_COOKIE',
101 'GLOBALS',
102 'HTTP_RAW_POST_DATA',
vlakoffde70dbb2014-04-15 16:46:03 +0200103 'system_path',
Andrey Andreevb78a8c72014-04-15 17:21:16 +0300104 'application_folder',
105 'view_folder',
106 '_protected',
107 '_registered'
108 );
109
110 $_registered = ini_get('variables_order');
111 foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal)
112 {
113 if (strpos($_registered, $key) === FALSE)
114 {
115 continue;
116 }
117
118 foreach (array_keys($$superglobal) as $var)
119 {
120 if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE))
121 {
122 $GLOBALS[$var] = NULL;
123 }
124 }
125 }
126 }
127}
128
129
josephok1095d112013-11-16 09:33:37 +0800130/*
131 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500132 * Define a custom error handler so we can log PHP errors
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 * ------------------------------------------------------
134 */
Derek Jones218876c2010-03-02 13:11:00 -0600135 set_error_handler('_exception_handler');
Kaiwang Chen21fe9da2013-09-11 13:09:41 +0800136 register_shutdown_function('_shutdown_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200137
Derek Jones218876c2010-03-02 13:11:00 -0600138/*
139 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500140 * Set the subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -0600141 * ------------------------------------------------------
142 *
Barry Mienydd671972010-10-04 16:33:58 +0200143 * Normally the "subclass_prefix" is set in the config file.
144 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -0600145 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +0200146 * "libraries" folder. Since CI allows config items to be
vlakoff8d70c0a2013-08-17 07:31:29 +0200147 * overriden via data set in the main index.php file,
Barry Mienydd671972010-10-04 16:33:58 +0200148 * before proceeding we need to know if a subclass_prefix
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200149 * override exists. If so, we will set this value now,
Derek Jones218876c2010-03-02 13:11:00 -0600150 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +0200151 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -0600152 * hurt to load it here.
153 */
Andrey Andreev9ba661b2012-06-04 14:44:34 +0300154 if ( ! empty($assign_to_config['subclass_prefix']))
Derek Jones218876c2010-03-02 13:11:00 -0600155 {
156 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
157 }
Eric Barnesc5bf6162011-01-30 21:17:11 -0500158
Pascal Krietef566af52010-11-09 13:03:26 -0500159/*
160 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500161 * Start the timer... tick tock tick tock...
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 * ------------------------------------------------------
163 */
Derek Jones218876c2010-03-02 13:11:00 -0600164 $BM =& load_class('Benchmark', 'core');
165 $BM->mark('total_execution_time_start');
166 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000167
168/*
169 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500170 * Instantiate the hooks class
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 * ------------------------------------------------------
172 */
Derek Jones218876c2010-03-02 13:11:00 -0600173 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000174
175/*
176 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500177 * Is there a "pre_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 * ------------------------------------------------------
179 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300180 $EXT->call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000181
182/*
183 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500184 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200186 *
187 * Note: It is important that Config is loaded first as
188 * most other classes depend on it either directly or by
189 * depending on another class that uses it.
190 *
Barry Mienydd671972010-10-04 16:33:58 +0200191 */
Derek Jones218876c2010-03-02 13:11:00 -0600192 $CFG =& load_class('Config', 'core');
193
194 // Do we have any manually set config items in the index.php file?
Andrey Andreev5232ba02012-10-27 15:25:05 +0300195 if (isset($assign_to_config) && is_array($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200196 {
Andrey Andreev5232ba02012-10-27 15:25:05 +0300197 foreach ($assign_to_config as $key => $value)
198 {
199 $CFG->set_item($key, $value);
200 }
Derek Jones218876c2010-03-02 13:11:00 -0600201 }
202
203/*
204 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200205 * Important charset-related stuff
Derek Jones218876c2010-03-02 13:11:00 -0600206 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200207 *
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200208 * Configure mbstring and/or iconv if they are enabled
209 * and set MB_ENABLED and ICONV_ENABLED constants, so
210 * that we don't repeatedly do extension_loaded() or
211 * function_exists() calls.
Barry Mienydd671972010-10-04 16:33:58 +0200212 *
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200213 * Note: UTF-8 class depends on this. It used to be done
214 * in it's constructor, but it's _not_ class-specific.
215 *
216 */
217 $charset = strtoupper(config_item('charset'));
Andrey Andreev51593f42014-05-07 00:06:31 +0300218 ini_set('default_charset', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200219
220 if (extension_loaded('mbstring'))
221 {
222 define('MB_ENABLED', TRUE);
Andrey Andreev1ffa2232014-05-09 12:30:59 +0300223 // mbstring.internal_encoding is deprecated starting with PHP 5.6
224 // and it's usage triggers E_DEPRECATED messages.
225 @ini_set('mbstring.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200226 // This is required for mb_convert_encoding() to strip invalid characters.
227 // That's utilized by CI_Utf8, but it's also done for consistency with iconv.
228 mb_substitute_character('none');
229 }
230 else
231 {
232 define('MB_ENABLED', FALSE);
233 }
234
235 // There's an ICONV_IMPL constant, but the PHP manual says that using
236 // iconv's predefined constants is "strongly discouraged".
237 if (extension_loaded('iconv'))
238 {
239 define('ICONV_ENABLED', TRUE);
Andrey Andreev51593f42014-05-07 00:06:31 +0300240 // iconv.internal_encoding is deprecated starting with PHP 5.6
241 // and it's usage triggers E_DEPRECATED messages.
242 @ini_set('iconv.internal_encoding', $charset);
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200243 }
244 else
245 {
246 define('ICONV_ENABLED', FALSE);
247 }
248
Andrey Andreev51593f42014-05-07 00:06:31 +0300249 if (is_php('5.6'))
250 {
251 ini_set('php.internal_encoding', $charset);
252 }
253
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200254/*
255 * ------------------------------------------------------
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200256 * Load compatibility features
257 * ------------------------------------------------------
258 */
259
Andrey Andreev376b2152014-02-13 12:35:52 +0200260 require_once(BASEPATH.'core/compat/mbstring.php');
Andrey Andreev9a152a92014-02-18 16:29:53 +0200261 require_once(BASEPATH.'core/compat/hash.php');
Andrey Andreev376b2152014-02-13 12:35:52 +0200262 require_once(BASEPATH.'core/compat/password.php');
Andrey Andreev5b3fe7c2014-07-07 10:55:53 +0300263 require_once(BASEPATH.'core/compat/standard.php');
Andrey Andreev3fd1b382014-02-13 03:01:31 +0200264
265/*
266 * ------------------------------------------------------
Andrey Andreeveb555ed2014-02-12 19:25:01 +0200267 * Instantiate the UTF-8 class
268 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 */
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500270 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200271
Derek Jones218876c2010-03-02 13:11:00 -0600272/*
273 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500274 * Instantiate the URI class
Derek Jones218876c2010-03-02 13:11:00 -0600275 * ------------------------------------------------------
276 */
277 $URI =& load_class('URI', 'core');
278
279/*
280 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500281 * Instantiate the routing class and set the routing
Derek Jones218876c2010-03-02 13:11:00 -0600282 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200283 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200284 $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
Barry Mienydd671972010-10-04 16:33:58 +0200285
Derek Jones218876c2010-03-02 13:11:00 -0600286/*
287 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500288 * Instantiate the output class
Derek Jones218876c2010-03-02 13:11:00 -0600289 * ------------------------------------------------------
290 */
291 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000292
293/*
294 * ------------------------------------------------------
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200295 * Is there a valid cache file? If so, we're done...
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 * ------------------------------------------------------
297 */
Andrey Andreevc26b9eb2014-02-24 11:31:36 +0200298 if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 {
Andrey Andreev9c5c24a2012-01-07 18:51:21 +0200300 exit;
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000302
303/*
Pascal Kriete14a0ac62011-04-05 14:55:56 -0400304 * -----------------------------------------------------
305 * Load the security class for xss and csrf support
306 * -----------------------------------------------------
307 */
308 $SEC =& load_class('Security', 'core');
309
310/*
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500312 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 * ------------------------------------------------------
314 */
Barry Mienydd671972010-10-04 16:33:58 +0200315 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000316
Derek Jones218876c2010-03-02 13:11:00 -0600317/*
318 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500319 * Load the Language class
Derek Jones218876c2010-03-02 13:11:00 -0600320 * ------------------------------------------------------
321 */
322 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000323
324/*
325 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500326 * Load the app controller and local controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 * ------------------------------------------------------
328 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 */
Derek Jones218876c2010-03-02 13:11:00 -0600330 // Load the base controller class
Andrey Andreev30d53242014-01-16 14:41:46 +0200331 require_once BASEPATH.'core/Controller.php';
Barry Mienydd671972010-10-04 16:33:58 +0200332
Timothy Warrenad475052012-04-19 13:21:06 -0400333 /**
334 * Reference to the CI_Controller method.
335 *
336 * Returns current CI instance object
337 *
338 * @return object
339 */
Greg Aker4abfa682010-11-10 14:44:26 -0600340 function &get_instance()
341 {
342 return CI_Controller::get_instance();
343 }
344
Greg Aker3a746652011-04-19 10:59:47 -0500345 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
Greg Akerfa281352010-03-22 14:41:27 -0500346 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200347 require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
Greg Akerfa281352010-03-22 14:41:27 -0500348 }
Barry Mienydd671972010-10-04 16:33:58 +0200349
Derek Jones218876c2010-03-02 13:11:00 -0600350 // Set a mark point for benchmarking
351 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000352
353/*
354 * ------------------------------------------------------
Andrey Andreev30d53242014-01-16 14:41:46 +0200355 * Sanity checks
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 * ------------------------------------------------------
357 *
Andrey Andreev30d53242014-01-16 14:41:46 +0200358 * The Router class has already validated the request,
359 * leaving us with 3 options here:
360 *
361 * 1) an empty class name, if we reached the default
362 * controller, but it didn't exist;
363 * 2) a query string which doesn't go through a
364 * file_exists() check
365 * 3) a regular request for a non-existing page
366 *
367 * We handle all of these as a 404 error.
368 *
369 * Furthermore, none of the methods in the app controller
370 * or the loader class can be called via the URI, nor can
Andrey Andreev20292312013-07-22 14:29:10 +0300371 * controller methods that begin with an underscore.
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 */
Barry Mienydd671972010-10-04 16:33:58 +0200373
Andrey Andreev30d53242014-01-16 14:41:46 +0200374 $e404 = FALSE;
375 $class = ucfirst($RTR->class);
376 $method = $RTR->method;
377
378 if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
Derek Jones218876c2010-03-02 13:11:00 -0600379 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200380 $e404 = TRUE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200381 }
382 else
383 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200384 require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
385
386 if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
387 {
388 $e404 = TRUE;
389 }
390 elseif (method_exists($class, '_remap'))
391 {
392 $params = array($method, array_slice($URI->rsegments, 2));
393 $method = '_remap';
394 }
Andrey Andreev522c7362012-11-05 16:40:32 +0200395 // WARNING: It appears that there are issues with is_callable() even in PHP 5.2!
396 // Furthermore, there are bug reports and feature/change requests related to it
397 // that make it unreliable to use in this context. Please, DO NOT change this
398 // work-around until a better alternative is available.
Andrey Andreev30d53242014-01-16 14:41:46 +0200399 elseif ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($class)), TRUE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200400 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200401 $e404 = TRUE;
402 }
403 }
404
405 if ($e404)
406 {
407 if ( ! empty($RTR->routes['404_override']))
408 {
409 if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
Andrey Andreev38e32f62012-11-03 00:16:47 +0200410 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200411 $error_method = 'index';
Andrey Andreev38e32f62012-11-03 00:16:47 +0200412 }
413
Andrey Andreev30d53242014-01-16 14:41:46 +0200414 $error_class = ucfirst($error_class);
Andrey Andreev20292312013-07-22 14:29:10 +0300415
Andrey Andreev30d53242014-01-16 14:41:46 +0200416 if ( ! class_exists($error_class, FALSE))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200417 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200418 if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
Andrey Andreev38e32f62012-11-03 00:16:47 +0200419 {
Andrey Andreev30d53242014-01-16 14:41:46 +0200420 require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
421 $e404 = ! class_exists($error_class, FALSE);
Andrey Andreev38e32f62012-11-03 00:16:47 +0200422 }
Andrey Andreev30d53242014-01-16 14:41:46 +0200423 // Were we in a directory? If so, check for a global override
424 elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
425 {
426 require_once(APPPATH.'controllers/'.$error_class.'.php');
427 if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
428 {
429 $RTR->directory = '';
430 }
431 }
432 }
433 else
434 {
435 $e404 = FALSE;
Andrey Andreev38e32f62012-11-03 00:16:47 +0200436 }
437 }
438
Andrey Andreev30d53242014-01-16 14:41:46 +0200439 // Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
440 if ( ! $e404)
441 {
442 $class = $error_class;
443 $method = $error_method;
444
445 $URI->rsegments = array(
446 1 => $class,
447 2 => $method
448 );
449 }
450 else
451 {
452 show_404($RTR->directory.$class.'/'.$method);
453 }
454 }
455
456 if ($method !== '_remap')
457 {
Andrey Andreev38e32f62012-11-03 00:16:47 +0200458 $params = array_slice($URI->rsegments, 2);
459 }
460
Derek Allard2067d1a2008-11-13 22:59:24 +0000461/*
462 * ------------------------------------------------------
Andrey Andreeved86ee12014-07-11 19:48:37 +0300463 * Should we use a Composer autoloader?
464 * ------------------------------------------------------
465 */
Andrey Andreev286f9e12014-10-06 01:54:21 +0300466 if ($composer_autoload = config_item('composer_autoload'))
Andrey Andreeved86ee12014-07-11 19:48:37 +0300467 {
468 if ($composer_autoload === TRUE && file_exists(APPPATH.'vendor/autoload.php'))
469 {
470 require_once(APPPATH.'vendor/autoload.php');
471 }
472 elseif (file_exists($composer_autoload))
473 {
474 require_once($composer_autoload);
475 }
476 }
477
478/*
479 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500480 * Is there a "pre_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 * ------------------------------------------------------
482 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300483 $EXT->call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000484
485/*
486 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500487 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 * ------------------------------------------------------
489 */
Derek Jones218876c2010-03-02 13:11:00 -0600490 // Mark a start point so we can benchmark the controller
491 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Jones218876c2010-03-02 13:11:00 -0600493 $CI = new $class();
494
495/*
496 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500497 * Is there a "post_controller_constructor" hook?
Derek Jones218876c2010-03-02 13:11:00 -0600498 * ------------------------------------------------------
499 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300500 $EXT->call_hook('post_controller_constructor');
Derek Jones218876c2010-03-02 13:11:00 -0600501
502/*
503 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500504 * Call the requested method
Derek Jones218876c2010-03-02 13:11:00 -0600505 * ------------------------------------------------------
506 */
Andrey Andreev38e32f62012-11-03 00:16:47 +0200507 call_user_func_array(array(&$CI, $method), $params);
Derek Allard2067d1a2008-11-13 22:59:24 +0000508
Derek Jones218876c2010-03-02 13:11:00 -0600509 // Mark a benchmark end point
510 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000511
512/*
513 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500514 * Is there a "post_controller" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 * ------------------------------------------------------
516 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300517 $EXT->call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000518
519/*
520 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500521 * Send the final rendered output to the browser
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 * ------------------------------------------------------
523 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300524 if ($EXT->call_hook('display_override') === FALSE)
Derek Jones218876c2010-03-02 13:11:00 -0600525 {
526 $OUT->_display();
527 }
Barry Mienydd671972010-10-04 16:33:58 +0200528
Derek Allard2067d1a2008-11-13 22:59:24 +0000529/*
530 * ------------------------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500531 * Is there a "post_system" hook?
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 * ------------------------------------------------------
533 */
Andrey Andreeva5dd2972012-03-26 14:43:01 +0300534 $EXT->call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000535
Derek Allard2067d1a2008-11-13 22:59:24 +0000536/* End of file CodeIgniter.php */
Andrey Andreevb6fbcbe2013-11-17 18:06:18 +0200537/* Location: ./system/core/CodeIgniter.php */