blob: 2d3f2495896fda3417b175a81bcd22ae2baedb40 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
Derek Jones218876c2010-03-02 13:11:00 -060019 * System Initialization File
Derek Allard2067d1a2008-11-13 22:59:24 +000020 *
21 * Loads the base classes and executes the request.
22 *
23 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Front-controller
26 * @author ExpressionEngine Dev Team
27 * @link http://codeigniter.com/user_guide/
28 */
29
Derek Jones218876c2010-03-02 13:11:00 -060030/*
31 * ------------------------------------------------------
32 * Define the CodeIgniter Version
33 * ------------------------------------------------------
34 */
35 define('CI_VERSION', '2.0');
Derek Allard2067d1a2008-11-13 22:59:24 +000036
37/*
38 * ------------------------------------------------------
39 * Load the global functions
40 * ------------------------------------------------------
41 */
Derek Jones218876c2010-03-02 13:11:00 -060042 require(BASEPATH.'core/Common'.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +000043
44/*
45 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000046 * Load the framework constants
47 * ------------------------------------------------------
48 */
Derek Jones218876c2010-03-02 13:11:00 -060049 require(APPPATH.'config/constants'.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51/*
52 * ------------------------------------------------------
53 * Define a custom error handler so we can log PHP errors
54 * ------------------------------------------------------
55 */
Derek Jones218876c2010-03-02 13:11:00 -060056 set_error_handler('_exception_handler');
Barry Mienydd671972010-10-04 16:33:58 +020057
Derek Jones218876c2010-03-02 13:11:00 -060058 if ( ! is_php('5.3'))
59 {
Barry Mienydd671972010-10-04 16:33:58 +020060 @set_magic_quotes_runtime(0); // Kill magic quotes
Derek Jones218876c2010-03-02 13:11:00 -060061 }
Derek Jones962d2252009-08-05 04:26:11 +000062
Derek Jones218876c2010-03-02 13:11:00 -060063/*
64 * ------------------------------------------------------
65 * Set the subclass_prefix
66 * ------------------------------------------------------
67 *
Barry Mienydd671972010-10-04 16:33:58 +020068 * Normally the "subclass_prefix" is set in the config file.
69 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -060070 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +020071 * "libraries" folder. Since CI allows config items to be
72 * overriden via data set in the main index. php file,
73 * before proceeding we need to know if a subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -060074 * override exists. If so, we will set this value now,
75 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +020076 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -060077 * hurt to load it here.
78 */
Barry Mienydd671972010-10-04 16:33:58 +020079 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
Derek Jones218876c2010-03-02 13:11:00 -060080 {
81 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
82 }
Pascal Krietef566af52010-11-09 13:03:26 -050083
84/*
85 * ------------------------------------------------------
86 * Set a liberal script execution time limit
87 * ------------------------------------------------------
88 */
89 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
90 {
91 @set_time_limit(300);
92 }
Derek Allard2067d1a2008-11-13 22:59:24 +000093
94/*
95 * ------------------------------------------------------
96 * Start the timer... tick tock tick tock...
97 * ------------------------------------------------------
98 */
Derek Jones218876c2010-03-02 13:11:00 -060099 $BM =& load_class('Benchmark', 'core');
100 $BM->mark('total_execution_time_start');
101 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000102
103/*
104 * ------------------------------------------------------
105 * Instantiate the hooks class
106 * ------------------------------------------------------
107 */
Derek Jones218876c2010-03-02 13:11:00 -0600108 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000109
110/*
111 * ------------------------------------------------------
112 * Is there a "pre_system" hook?
113 * ------------------------------------------------------
114 */
Derek Jones218876c2010-03-02 13:11:00 -0600115 $EXT->_call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000116
117/*
118 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600119 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200121 */
Derek Jones218876c2010-03-02 13:11:00 -0600122 $CFG =& load_class('Config', 'core');
123
124 // Do we have any manually set config items in the index.php file?
125 if (isset($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200126 {
Derek Jones218876c2010-03-02 13:11:00 -0600127 $CFG->_assign_to_config($assign_to_config);
128 }
129
130/*
131 * ------------------------------------------------------
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500132 * Instantiate the UTF-8 class
Derek Jones218876c2010-03-02 13:11:00 -0600133 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200134 *
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500135 * Note: Order here is rather important as the UTF-8
Derek Jones218876c2010-03-02 13:11:00 -0600136 * class needs to be used very early on, but it cannot
Barry Mienydd671972010-10-04 16:33:58 +0200137 * properly determine if UTf-8 can be supported until
Derek Jones218876c2010-03-02 13:11:00 -0600138 * after the Config class is instantiated.
Barry Mienydd671972010-10-04 16:33:58 +0200139 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 */
141
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500142 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200143
Derek Jones218876c2010-03-02 13:11:00 -0600144/*
145 * ------------------------------------------------------
146 * Instantiate the URI class
147 * ------------------------------------------------------
148 */
149 $URI =& load_class('URI', 'core');
150
151/*
152 * ------------------------------------------------------
153 * Instantiate the routing class and set the routing
154 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200155 */
Derek Jones218876c2010-03-02 13:11:00 -0600156 $RTR =& load_class('Router', 'core');
157 $RTR->_set_routing();
Barry Mienydd671972010-10-04 16:33:58 +0200158
Derek Jones218876c2010-03-02 13:11:00 -0600159 // Set any routing overrides that may exist in the main index file
160 if (isset($routing))
161 {
162 $RTR->_set_overrides($routing);
163 }
164
165/*
166 * ------------------------------------------------------
167 * Instantiate the output class
168 * ------------------------------------------------------
169 */
170 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000171
172/*
173 * ------------------------------------------------------
174 * Is there a valid cache file? If so, we're done...
175 * ------------------------------------------------------
176 */
Derek Jones218876c2010-03-02 13:11:00 -0600177 if ($EXT->_call_hook('cache_override') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000178 {
Derek Jones218876c2010-03-02 13:11:00 -0600179 if ($OUT->_display_cache($CFG, $URI) == TRUE)
180 {
181 exit;
182 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000184
185/*
186 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600187 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 * ------------------------------------------------------
189 */
Barry Mienydd671972010-10-04 16:33:58 +0200190 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000191
Derek Jones218876c2010-03-02 13:11:00 -0600192/*
193 * ------------------------------------------------------
194 * Load the Language class
195 * ------------------------------------------------------
196 */
197 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
199/*
200 * ------------------------------------------------------
201 * Load the app controller and local controller
202 * ------------------------------------------------------
203 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 */
Derek Jones218876c2010-03-02 13:11:00 -0600205 // Load the base controller class
206 require BASEPATH.'core/Controller'.EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200207
Greg Aker4abfa682010-11-10 14:44:26 -0600208 function &get_instance()
209 {
210 return CI_Controller::get_instance();
211 }
212
213
Greg Akerfa281352010-03-22 14:41:27 -0500214 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
215 {
216 require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
217 }
Barry Mienydd671972010-10-04 16:33:58 +0200218
Derek Jones218876c2010-03-02 13:11:00 -0600219 // Load the local application controller
Barry Mienydd671972010-10-04 16:33:58 +0200220 // Note: The Router class automatically validates the controller path using the router->_validate_request().
Derek Jones218876c2010-03-02 13:11:00 -0600221 // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
222 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
223 {
Pascal Krieteebb6f4b2010-11-10 17:09:21 -0500224 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
Derek Jones218876c2010-03-02 13:11:00 -0600225 }
Barry Mienydd671972010-10-04 16:33:58 +0200226
Derek Jones218876c2010-03-02 13:11:00 -0600227 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
Barry Mienydd671972010-10-04 16:33:58 +0200228
Derek Jones218876c2010-03-02 13:11:00 -0600229 // Set a mark point for benchmarking
230 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000231
232/*
233 * ------------------------------------------------------
234 * Security check
235 * ------------------------------------------------------
236 *
237 * None of the functions in the app controller or the
238 * loader class can be called via the URI, nor can
239 * controller functions that begin with an underscore
240 */
Derek Jones218876c2010-03-02 13:11:00 -0600241 $class = $RTR->fetch_class();
242 $method = $RTR->fetch_method();
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Jones218876c2010-03-02 13:11:00 -0600244 if ( ! class_exists($class)
Derek Jones218876c2010-03-02 13:11:00 -0600245 OR strncmp($method, '_', 1) == 0
Greg Aker63277b82010-11-09 13:46:13 -0600246 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
Derek Jones218876c2010-03-02 13:11:00 -0600247 )
248 {
249 show_404("{$class}/{$method}");
250 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000251
252/*
253 * ------------------------------------------------------
254 * Is there a "pre_controller" hook?
255 * ------------------------------------------------------
256 */
Derek Jones218876c2010-03-02 13:11:00 -0600257 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000258
259/*
260 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600261 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 * ------------------------------------------------------
263 */
Derek Jones218876c2010-03-02 13:11:00 -0600264 // Mark a start point so we can benchmark the controller
265 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200266
Derek Jones218876c2010-03-02 13:11:00 -0600267 $CI = new $class();
268
269/*
270 * ------------------------------------------------------
271 * Is there a "post_controller_constructor" hook?
272 * ------------------------------------------------------
273 */
274 $EXT->_call_hook('post_controller_constructor');
275
276/*
277 * ------------------------------------------------------
278 * Call the requested method
279 * ------------------------------------------------------
280 */
281 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 if (method_exists($CI, '_remap'))
283 {
Pascal Kriete3431ae32010-11-09 15:19:50 -0500284 $CI->_remap($method, array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 }
286 else
287 {
288 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
289 // methods, so we'll use this workaround for consistent behavior
290 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
291 {
292 show_404("{$class}/{$method}");
293 }
294
295 // Call the requested method.
Barry Mienydd671972010-10-04 16:33:58 +0200296 // Any URI segments present (besides the class/function) will be passed to the method for convenience
297 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000299
Barry Mienydd671972010-10-04 16:33:58 +0200300
Derek Jones218876c2010-03-02 13:11:00 -0600301 // Mark a benchmark end point
302 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000303
304/*
305 * ------------------------------------------------------
306 * Is there a "post_controller" hook?
307 * ------------------------------------------------------
308 */
Derek Jones218876c2010-03-02 13:11:00 -0600309 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000310
311/*
312 * ------------------------------------------------------
313 * Send the final rendered output to the browser
314 * ------------------------------------------------------
315 */
Derek Jones218876c2010-03-02 13:11:00 -0600316 if ($EXT->_call_hook('display_override') === FALSE)
317 {
318 $OUT->_display();
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321/*
322 * ------------------------------------------------------
323 * Is there a "post_system" hook?
324 * ------------------------------------------------------
325 */
Derek Jones218876c2010-03-02 13:11:00 -0600326 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000327
328/*
329 * ------------------------------------------------------
330 * Close the DB connection if one exists
331 * ------------------------------------------------------
332 */
Derek Jones218876c2010-03-02 13:11:00 -0600333 if (class_exists('CI_DB') AND isset($CI->db))
334 {
335 $CI->db->close();
336 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000337
338
339/* End of file CodeIgniter.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600340/* Location: ./system/core/CodeIgniter.php */