1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * System Initialization File
21 * Loads the base classes and executes the request.
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Front-controller
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
31 * ------------------------------------------------------
32 * Define the CodeIgniter Version
33 * ------------------------------------------------------
35 define('CI_VERSION', '2.0.2');
38 * ------------------------------------------------------
39 * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
40 * ------------------------------------------------------
42 define('CI_CORE', FALSE);
45 * ------------------------------------------------------
46 * Load the global functions
47 * ------------------------------------------------------
49 require(BASEPATH.'core/Common'.EXT);
52 * ------------------------------------------------------
53 * Load the framework constants
54 * ------------------------------------------------------
56 if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT))
58 require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT);
62 require(APPPATH.'config/constants'.EXT);
66 * ------------------------------------------------------
67 * Define a custom error handler so we can log PHP errors
68 * ------------------------------------------------------
70 set_error_handler('_exception_handler');
74 @set_magic_quotes_runtime(0); // Kill magic quotes
78 * ------------------------------------------------------
79 * Set the subclass_prefix
80 * ------------------------------------------------------
82 * Normally the "subclass_prefix" is set in the config file.
83 * The subclass prefix allows CI to know if a core class is
84 * being extended via a library in the local application
85 * "libraries" folder. Since CI allows config items to be
86 * overriden via data set in the main index. php file,
87 * before proceeding we need to know if a subclass_prefix
88 * override exists. If so, we will set this value now,
89 * before any classes are loaded
90 * Note: Since the config file data is cached it doesn't
91 * hurt to load it here.
93 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
95 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
99 * ------------------------------------------------------
100 * Set a liberal script execution time limit
101 * ------------------------------------------------------
103 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
105 @set_time_limit(300);
109 * ------------------------------------------------------
110 * Start the timer... tick tock tick tock...
111 * ------------------------------------------------------
113 $BM =& load_class('Benchmark', 'core');
114 $BM->mark('total_execution_time_start');
115 $BM->mark('loading_time:_base_classes_start');
118 * ------------------------------------------------------
119 * Instantiate the hooks class
120 * ------------------------------------------------------
122 $EXT =& load_class('Hooks', 'core');
125 * ------------------------------------------------------
126 * Is there a "pre_system" hook?
127 * ------------------------------------------------------
129 $EXT->_call_hook('pre_system');
132 * ------------------------------------------------------
133 * Instantiate the config class
134 * ------------------------------------------------------
136 $CFG =& load_class('Config', 'core');
138 // Do we have any manually set config items in the index.php file?
139 if (isset($assign_to_config))
141 $CFG->_assign_to_config($assign_to_config);
145 * ------------------------------------------------------
146 * Instantiate the UTF-8 class
147 * ------------------------------------------------------
149 * Note: Order here is rather important as the UTF-8
150 * class needs to be used very early on, but it cannot
151 * properly determine if UTf-8 can be supported until
152 * after the Config class is instantiated.
156 $UNI =& load_class('Utf8', 'core');
159 * ------------------------------------------------------
160 * Instantiate the URI class
161 * ------------------------------------------------------
163 $URI =& load_class('URI', 'core');
166 * ------------------------------------------------------
167 * Instantiate the routing class and set the routing
168 * ------------------------------------------------------
170 $RTR =& load_class('Router', 'core');
171 $RTR->_set_routing();
173 // Set any routing overrides that may exist in the main index file
176 $RTR->_set_overrides($routing);
180 * ------------------------------------------------------
181 * Instantiate the output class
182 * ------------------------------------------------------
184 $OUT =& load_class('Output', 'core');
187 * ------------------------------------------------------
188 * Is there a valid cache file? If so, we're done...
189 * ------------------------------------------------------
191 if ($EXT->_call_hook('cache_override') === FALSE)
193 if ($OUT->_display_cache($CFG, $URI) == TRUE)
200 * -----------------------------------------------------
201 * Load the security class for xss and csrf support
202 * -----------------------------------------------------
204 $SEC =& load_class('Security', 'core');
207 * ------------------------------------------------------
208 * Load the Input class and sanitize globals
209 * ------------------------------------------------------
211 $IN =& load_class('Input', 'core');
214 * ------------------------------------------------------
215 * Load the Language class
216 * ------------------------------------------------------
218 $LANG =& load_class('Lang', 'core');
221 * ------------------------------------------------------
222 * Load the app controller and local controller
223 * ------------------------------------------------------
226 // Load the base controller class
227 require BASEPATH.'core/Controller'.EXT;
229 function &get_instance()
231 return CI_Controller::get_instance();
235 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
237 require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
240 // Load the local application controller
241 // Note: The Router class automatically validates the controller path using the router->_validate_request().
242 // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
243 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
245 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
248 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
250 // Set a mark point for benchmarking
251 $BM->mark('loading_time:_base_classes_end');
254 * ------------------------------------------------------
256 * ------------------------------------------------------
258 * None of the functions in the app controller or the
259 * loader class can be called via the URI, nor can
260 * controller functions that begin with an underscore
262 $class = $RTR->fetch_class();
263 $method = $RTR->fetch_method();
265 if ( ! class_exists($class)
266 OR strncmp($method, '_', 1) == 0
267 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
270 show_404("{$class}/{$method}");
274 * ------------------------------------------------------
275 * Is there a "pre_controller" hook?
276 * ------------------------------------------------------
278 $EXT->_call_hook('pre_controller');
281 * ------------------------------------------------------
282 * Instantiate the requested controller
283 * ------------------------------------------------------
285 // Mark a start point so we can benchmark the controller
286 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
291 * ------------------------------------------------------
292 * Is there a "post_controller_constructor" hook?
293 * ------------------------------------------------------
295 $EXT->_call_hook('post_controller_constructor');
298 * ------------------------------------------------------
299 * Call the requested method
300 * ------------------------------------------------------
302 // Is there a "remap" function? If so, we call it instead
303 if (method_exists($CI, '_remap'))
305 $CI->_remap($method, array_slice($URI->rsegments, 2));
309 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
310 // methods, so we'll use this workaround for consistent behavior
311 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
313 // Check and see if we are using a 404 override and use it.
314 if ( ! empty($RTR->routes['404_override']))
316 $x = explode('/', $RTR->routes['404_override']);
318 $method = (isset($x[1]) ? $x[1] : 'index');
319 if ( ! class_exists($class))
321 if ( ! file_exists(APPPATH.'controllers/'.$class.EXT))
323 show_404("{$class}/{$method}");
326 include_once(APPPATH.'controllers/'.$class.EXT);
333 show_404("{$class}/{$method}");
337 // Call the requested method.
338 // Any URI segments present (besides the class/function) will be passed to the method for convenience
339 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
343 // Mark a benchmark end point
344 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
347 * ------------------------------------------------------
348 * Is there a "post_controller" hook?
349 * ------------------------------------------------------
351 $EXT->_call_hook('post_controller');
354 * ------------------------------------------------------
355 * Send the final rendered output to the browser
356 * ------------------------------------------------------
358 if ($EXT->_call_hook('display_override') === FALSE)
364 * ------------------------------------------------------
365 * Is there a "post_system" hook?
366 * ------------------------------------------------------
368 $EXT->_call_hook('post_system');
371 * ------------------------------------------------------
372 * Close the DB connection if one exists
373 * ------------------------------------------------------
375 if (class_exists('CI_DB') AND isset($CI->db))
381 /* End of file CodeIgniter.php */
382 /* Location: ./system/core/CodeIgniter.php */