blob: 488f9f3ce7765cbd2e6a670b864ba2ca680e63dd [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 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, 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 * ------------------------------------------------------
46 * Load the compatibility override functions
47 * ------------------------------------------------------
48 */
Derek Jones218876c2010-03-02 13:11:00 -060049 require(BASEPATH.'core/Compat'.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51/*
52 * ------------------------------------------------------
53 * Load the framework constants
54 * ------------------------------------------------------
55 */
Derek Jones218876c2010-03-02 13:11:00 -060056 require(APPPATH.'config/constants'.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +000057
58/*
59 * ------------------------------------------------------
60 * Define a custom error handler so we can log PHP errors
61 * ------------------------------------------------------
62 */
Derek Jones218876c2010-03-02 13:11:00 -060063 set_error_handler('_exception_handler');
64
65 if ( ! is_php('5.3'))
66 {
67 @set_magic_quotes_runtime(0); // Kill magic quotes
68 }
Derek Jones962d2252009-08-05 04:26:11 +000069
Derek Jones218876c2010-03-02 13:11:00 -060070 // Set a liberal script execution time limit
71 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
72 {
73 @set_time_limit(300);
74 }
75
76/*
77 * ------------------------------------------------------
78 * Set the subclass_prefix
79 * ------------------------------------------------------
80 *
81 * Normally the "subclass_prefix" is set in the config file.
82 * The subclass prefix allows CI to know if a core class is
83 * being extended via a library in the local application
84 * "libraries" folder. Since CI allows config items to be
85 * overriden via data set in the main index. php file,
86 * before proceeding we need to know if a subclass_prefix
87 * override exists. If so, we will set this value now,
88 * before any classes are loaded
89 * Note: Since the config file data is cached it doesn't
90 * hurt to load it here.
91 */
92 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
93 {
94 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
95 }
Derek Allard2067d1a2008-11-13 22:59:24 +000096
97/*
98 * ------------------------------------------------------
99 * Start the timer... tick tock tick tock...
100 * ------------------------------------------------------
101 */
Derek Jones218876c2010-03-02 13:11:00 -0600102 $BM =& load_class('Benchmark', 'core');
103 $BM->mark('total_execution_time_start');
104 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000105
106/*
107 * ------------------------------------------------------
108 * Instantiate the hooks class
109 * ------------------------------------------------------
110 */
Derek Jones218876c2010-03-02 13:11:00 -0600111 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000112
113/*
114 * ------------------------------------------------------
115 * Is there a "pre_system" hook?
116 * ------------------------------------------------------
117 */
Derek Jones218876c2010-03-02 13:11:00 -0600118 $EXT->_call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000119
120/*
121 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600122 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600124 */
125 $CFG =& load_class('Config', 'core');
126
127 // Do we have any manually set config items in the index.php file?
128 if (isset($assign_to_config))
129 {
130 $CFG->_assign_to_config($assign_to_config);
131 }
132
133/*
134 * ------------------------------------------------------
135 * Instantiate the Unicode class
136 * ------------------------------------------------------
137 *
138 * Note: Order here is rather important as the Unicode
139 * class needs to be used very early on, but it cannot
140 * properly determine if UTf-8 can be supported until
141 * after the Config class is instantiated.
142 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 */
144
Derek Jones218876c2010-03-02 13:11:00 -0600145 $UNI =& load_class('Unicode', 'core');
146
147/*
148 * ------------------------------------------------------
149 * Instantiate the URI class
150 * ------------------------------------------------------
151 */
152 $URI =& load_class('URI', 'core');
153
154/*
155 * ------------------------------------------------------
156 * Instantiate the routing class and set the routing
157 * ------------------------------------------------------
158 */
159 $RTR =& load_class('Router', 'core');
160 $RTR->_set_routing();
161
162 // Set any routing overrides that may exist in the main index file
163 if (isset($routing))
164 {
165 $RTR->_set_overrides($routing);
166 }
167
168/*
169 * ------------------------------------------------------
170 * Instantiate the output class
171 * ------------------------------------------------------
172 */
173 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000174
175/*
176 * ------------------------------------------------------
177 * Is there a valid cache file? If so, we're done...
178 * ------------------------------------------------------
179 */
Derek Jones218876c2010-03-02 13:11:00 -0600180 if ($EXT->_call_hook('cache_override') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000181 {
Derek Jones218876c2010-03-02 13:11:00 -0600182 if ($OUT->_display_cache($CFG, $URI) == TRUE)
183 {
184 exit;
185 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000187
188/*
189 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600190 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 * ------------------------------------------------------
192 */
Derek Jones218876c2010-03-02 13:11:00 -0600193 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000194
Derek Jones218876c2010-03-02 13:11:00 -0600195/*
196 * ------------------------------------------------------
197 * Load the Language class
198 * ------------------------------------------------------
199 */
200 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000201
202/*
203 * ------------------------------------------------------
204 * Load the app controller and local controller
205 * ------------------------------------------------------
206 *
207 * Note: Due to the poor object handling in PHP 4 we'll
208 * conditionally load different versions of the base
209 * class. Retaining PHP 4 compatibility requires a bit of a hack.
Derek Jones1efda7b2010-03-02 13:30:20 -0600210 * @PHP4
211 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 */
Derek Jones218876c2010-03-02 13:11:00 -0600213 if (is_php('5.0.0') == TRUE)
214 {
215 require(BASEPATH.'core/Base5'.EXT);
216 }
217 else
218 {
219 // The Loader class needs to be included first when running PHP 4.x
220 load_class('Loader', 'core');
221 require(BASEPATH.'core/Base4'.EXT);
222 }
223
224 // Load the base controller class
225 require BASEPATH.'core/Controller'.EXT;
226
227 // Load the local application controller
228 // Note: The Router class automatically validates the controller path using the router->_validate_request().
229 // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
230 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
231 {
232 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
233 }
234
235 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
236
237 // Set a mark point for benchmarking
238 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000239
240/*
241 * ------------------------------------------------------
242 * Security check
243 * ------------------------------------------------------
244 *
245 * None of the functions in the app controller or the
246 * loader class can be called via the URI, nor can
247 * controller functions that begin with an underscore
248 */
Derek Jones218876c2010-03-02 13:11:00 -0600249 $class = $RTR->fetch_class();
250 $method = $RTR->fetch_method();
251
252 if ( ! class_exists($class)
253 OR $method == 'controller'
254 OR strncmp($method, '_', 1) == 0
255 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
256 )
257 {
258 show_404("{$class}/{$method}");
259 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000260
261/*
262 * ------------------------------------------------------
263 * Is there a "pre_controller" hook?
264 * ------------------------------------------------------
265 */
Derek Jones218876c2010-03-02 13:11:00 -0600266 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000267
268/*
269 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600270 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 * ------------------------------------------------------
272 */
Derek Jones218876c2010-03-02 13:11:00 -0600273 // Mark a start point so we can benchmark the controller
274 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000275
Derek Jones218876c2010-03-02 13:11:00 -0600276 $CI = new $class();
277
278/*
279 * ------------------------------------------------------
280 * Is there a "post_controller_constructor" hook?
281 * ------------------------------------------------------
282 */
283 $EXT->_call_hook('post_controller_constructor');
284
285/*
286 * ------------------------------------------------------
287 * Call the requested method
288 * ------------------------------------------------------
289 */
290 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 if (method_exists($CI, '_remap'))
292 {
293 $CI->_remap($method);
294 }
295 else
296 {
297 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
298 // methods, so we'll use this workaround for consistent behavior
299 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
300 {
301 show_404("{$class}/{$method}");
302 }
303
304 // Call the requested method.
Derek Jones218876c2010-03-02 13:11:00 -0600305 // Any URI segments present (besides the class/function) will be passed to the method for convenience
306 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000308
Derek Jones218876c2010-03-02 13:11:00 -0600309
310 // Mark a benchmark end point
311 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000312
313/*
314 * ------------------------------------------------------
315 * Is there a "post_controller" hook?
316 * ------------------------------------------------------
317 */
Derek Jones218876c2010-03-02 13:11:00 -0600318 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000319
320/*
321 * ------------------------------------------------------
322 * Send the final rendered output to the browser
323 * ------------------------------------------------------
324 */
Derek Jones218876c2010-03-02 13:11:00 -0600325 if ($EXT->_call_hook('display_override') === FALSE)
326 {
327 $OUT->_display();
328 }
329
Derek Allard2067d1a2008-11-13 22:59:24 +0000330/*
331 * ------------------------------------------------------
332 * Is there a "post_system" hook?
333 * ------------------------------------------------------
334 */
Derek Jones218876c2010-03-02 13:11:00 -0600335 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000336
337/*
338 * ------------------------------------------------------
339 * Close the DB connection if one exists
340 * ------------------------------------------------------
341 */
Derek Jones218876c2010-03-02 13:11:00 -0600342 if (class_exists('CI_DB') AND isset($CI->db))
343 {
344 $CI->db->close();
345 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000346
347
348/* End of file CodeIgniter.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600349/* Location: ./system/core/CodeIgniter.php */