blob: 90cce1c6ebb7ea74346ccec2895129a55f63a950 [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.
210 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 */
Derek Jones218876c2010-03-02 13:11:00 -0600212 if (is_php('5.0.0') == TRUE)
213 {
214 require(BASEPATH.'core/Base5'.EXT);
215 }
216 else
217 {
218 // The Loader class needs to be included first when running PHP 4.x
219 load_class('Loader', 'core');
220 require(BASEPATH.'core/Base4'.EXT);
221 }
222
223 // Load the base controller class
224 require BASEPATH.'core/Controller'.EXT;
225
226 // Load the local application controller
227 // Note: The Router class automatically validates the controller path using the router->_validate_request().
228 // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
229 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
230 {
231 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
232 }
233
234 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
235
236 // Set a mark point for benchmarking
237 $BM->mark('loading_time:_base_classes_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000238
239/*
240 * ------------------------------------------------------
241 * Security check
242 * ------------------------------------------------------
243 *
244 * None of the functions in the app controller or the
245 * loader class can be called via the URI, nor can
246 * controller functions that begin with an underscore
247 */
Derek Jones218876c2010-03-02 13:11:00 -0600248 $class = $RTR->fetch_class();
249 $method = $RTR->fetch_method();
250
251 if ( ! class_exists($class)
252 OR $method == 'controller'
253 OR strncmp($method, '_', 1) == 0
254 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
255 )
256 {
257 show_404("{$class}/{$method}");
258 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000259
260/*
261 * ------------------------------------------------------
262 * Is there a "pre_controller" hook?
263 * ------------------------------------------------------
264 */
Derek Jones218876c2010-03-02 13:11:00 -0600265 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000266
267/*
268 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600269 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 * ------------------------------------------------------
271 */
Derek Jones218876c2010-03-02 13:11:00 -0600272 // Mark a start point so we can benchmark the controller
273 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000274
Derek Jones218876c2010-03-02 13:11:00 -0600275 $CI = new $class();
276
277/*
278 * ------------------------------------------------------
279 * Is there a "post_controller_constructor" hook?
280 * ------------------------------------------------------
281 */
282 $EXT->_call_hook('post_controller_constructor');
283
284/*
285 * ------------------------------------------------------
286 * Call the requested method
287 * ------------------------------------------------------
288 */
289 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 if (method_exists($CI, '_remap'))
291 {
292 $CI->_remap($method);
293 }
294 else
295 {
296 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
297 // methods, so we'll use this workaround for consistent behavior
298 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
299 {
300 show_404("{$class}/{$method}");
301 }
302
303 // Call the requested method.
Derek Jones218876c2010-03-02 13:11:00 -0600304 // Any URI segments present (besides the class/function) will be passed to the method for convenience
305 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000307
Derek Jones218876c2010-03-02 13:11:00 -0600308
309 // Mark a benchmark end point
310 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000311
312/*
313 * ------------------------------------------------------
314 * Is there a "post_controller" hook?
315 * ------------------------------------------------------
316 */
Derek Jones218876c2010-03-02 13:11:00 -0600317 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000318
319/*
320 * ------------------------------------------------------
321 * Send the final rendered output to the browser
322 * ------------------------------------------------------
323 */
Derek Jones218876c2010-03-02 13:11:00 -0600324 if ($EXT->_call_hook('display_override') === FALSE)
325 {
326 $OUT->_display();
327 }
328
Derek Allard2067d1a2008-11-13 22:59:24 +0000329/*
330 * ------------------------------------------------------
331 * Is there a "post_system" hook?
332 * ------------------------------------------------------
333 */
Derek Jones218876c2010-03-02 13:11:00 -0600334 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000335
336/*
337 * ------------------------------------------------------
338 * Close the DB connection if one exists
339 * ------------------------------------------------------
340 */
Derek Jones218876c2010-03-02 13:11:00 -0600341 if (class_exists('CI_DB') AND isset($CI->db))
342 {
343 $CI->db->close();
344 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000345
346
347/* End of file CodeIgniter.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600348/* Location: ./system/core/CodeIgniter.php */