blob: 1c06488f0dab44d99151a3273d5daa57b41630b7 [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 * ------------------------------------------------------
Phil Sturgeonbabfb292011-03-08 21:56:08 +000039 * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
40 * ------------------------------------------------------
41 */
42 define('CI_CORE', FALSE);
43
44/*
45 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000046 * Load the global functions
47 * ------------------------------------------------------
48 */
Derek Jones218876c2010-03-02 13:11:00 -060049 require(BASEPATH.'core/Common'.EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +000050
51/*
52 * ------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000053 * 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');
Barry Mienydd671972010-10-04 16:33:58 +020064
Derek Jones218876c2010-03-02 13:11:00 -060065 if ( ! is_php('5.3'))
66 {
Barry Mienydd671972010-10-04 16:33:58 +020067 @set_magic_quotes_runtime(0); // Kill magic quotes
Derek Jones218876c2010-03-02 13:11:00 -060068 }
Derek Jones962d2252009-08-05 04:26:11 +000069
Derek Jones218876c2010-03-02 13:11:00 -060070/*
71 * ------------------------------------------------------
72 * Set the subclass_prefix
73 * ------------------------------------------------------
74 *
Barry Mienydd671972010-10-04 16:33:58 +020075 * Normally the "subclass_prefix" is set in the config file.
76 * The subclass prefix allows CI to know if a core class is
Derek Jones218876c2010-03-02 13:11:00 -060077 * being extended via a library in the local application
Barry Mienydd671972010-10-04 16:33:58 +020078 * "libraries" folder. Since CI allows config items to be
79 * overriden via data set in the main index. php file,
80 * before proceeding we need to know if a subclass_prefix
Derek Jones218876c2010-03-02 13:11:00 -060081 * override exists. If so, we will set this value now,
82 * before any classes are loaded
Barry Mienydd671972010-10-04 16:33:58 +020083 * Note: Since the config file data is cached it doesn't
Derek Jones218876c2010-03-02 13:11:00 -060084 * hurt to load it here.
85 */
Barry Mienydd671972010-10-04 16:33:58 +020086 if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
Derek Jones218876c2010-03-02 13:11:00 -060087 {
88 get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
89 }
Pascal Krietef566af52010-11-09 13:03:26 -050090
91/*
92 * ------------------------------------------------------
93 * Set a liberal script execution time limit
94 * ------------------------------------------------------
95 */
96 if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
97 {
98 @set_time_limit(300);
99 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000100
101/*
102 * ------------------------------------------------------
103 * Start the timer... tick tock tick tock...
104 * ------------------------------------------------------
105 */
Derek Jones218876c2010-03-02 13:11:00 -0600106 $BM =& load_class('Benchmark', 'core');
107 $BM->mark('total_execution_time_start');
108 $BM->mark('loading_time:_base_classes_start');
Derek Allard2067d1a2008-11-13 22:59:24 +0000109
110/*
111 * ------------------------------------------------------
112 * Instantiate the hooks class
113 * ------------------------------------------------------
114 */
Derek Jones218876c2010-03-02 13:11:00 -0600115 $EXT =& load_class('Hooks', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000116
117/*
118 * ------------------------------------------------------
119 * Is there a "pre_system" hook?
120 * ------------------------------------------------------
121 */
Derek Jones218876c2010-03-02 13:11:00 -0600122 $EXT->_call_hook('pre_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000123
124/*
125 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600126 * Instantiate the config class
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200128 */
Derek Jones218876c2010-03-02 13:11:00 -0600129 $CFG =& load_class('Config', 'core');
130
131 // Do we have any manually set config items in the index.php file?
132 if (isset($assign_to_config))
Barry Mienydd671972010-10-04 16:33:58 +0200133 {
Derek Jones218876c2010-03-02 13:11:00 -0600134 $CFG->_assign_to_config($assign_to_config);
135 }
136
137/*
138 * ------------------------------------------------------
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500139 * Instantiate the UTF-8 class
Derek Jones218876c2010-03-02 13:11:00 -0600140 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200141 *
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500142 * Note: Order here is rather important as the UTF-8
Derek Jones218876c2010-03-02 13:11:00 -0600143 * class needs to be used very early on, but it cannot
Barry Mienydd671972010-10-04 16:33:58 +0200144 * properly determine if UTf-8 can be supported until
Derek Jones218876c2010-03-02 13:11:00 -0600145 * after the Config class is instantiated.
Barry Mienydd671972010-10-04 16:33:58 +0200146 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 */
148
Pascal Krieteaaec1e42011-01-20 00:01:21 -0500149 $UNI =& load_class('Utf8', 'core');
Barry Mienydd671972010-10-04 16:33:58 +0200150
Derek Jones218876c2010-03-02 13:11:00 -0600151/*
152 * ------------------------------------------------------
153 * Instantiate the URI class
154 * ------------------------------------------------------
155 */
156 $URI =& load_class('URI', 'core');
157
158/*
159 * ------------------------------------------------------
160 * Instantiate the routing class and set the routing
161 * ------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200162 */
Derek Jones218876c2010-03-02 13:11:00 -0600163 $RTR =& load_class('Router', 'core');
164 $RTR->_set_routing();
Barry Mienydd671972010-10-04 16:33:58 +0200165
Derek Jones218876c2010-03-02 13:11:00 -0600166 // Set any routing overrides that may exist in the main index file
167 if (isset($routing))
168 {
169 $RTR->_set_overrides($routing);
170 }
171
172/*
173 * ------------------------------------------------------
174 * Instantiate the output class
175 * ------------------------------------------------------
176 */
177 $OUT =& load_class('Output', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000178
179/*
180 * ------------------------------------------------------
181 * Is there a valid cache file? If so, we're done...
182 * ------------------------------------------------------
183 */
Derek Jones218876c2010-03-02 13:11:00 -0600184 if ($EXT->_call_hook('cache_override') === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 {
Derek Jones218876c2010-03-02 13:11:00 -0600186 if ($OUT->_display_cache($CFG, $URI) == TRUE)
187 {
188 exit;
189 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000191
192/*
193 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600194 * Load the Input class and sanitize globals
Derek Allard2067d1a2008-11-13 22:59:24 +0000195 * ------------------------------------------------------
196 */
Barry Mienydd671972010-10-04 16:33:58 +0200197 $IN =& load_class('Input', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
Derek Jones218876c2010-03-02 13:11:00 -0600199/*
200 * ------------------------------------------------------
201 * Load the Language class
202 * ------------------------------------------------------
203 */
204 $LANG =& load_class('Lang', 'core');
Derek Allard2067d1a2008-11-13 22:59:24 +0000205
206/*
207 * ------------------------------------------------------
208 * Load the app controller and local controller
209 * ------------------------------------------------------
210 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 */
Derek Jones218876c2010-03-02 13:11:00 -0600212 // Load the base controller class
213 require BASEPATH.'core/Controller'.EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200214
Greg Aker4abfa682010-11-10 14:44:26 -0600215 function &get_instance()
216 {
217 return CI_Controller::get_instance();
218 }
219
220
Greg Akerfa281352010-03-22 14:41:27 -0500221 if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
222 {
223 require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
224 }
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Jones218876c2010-03-02 13:11:00 -0600226 // Load the local application controller
Barry Mienydd671972010-10-04 16:33:58 +0200227 // Note: The Router class automatically validates the controller path using the router->_validate_request().
Derek Jones218876c2010-03-02 13:11:00 -0600228 // 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 {
Pascal Krieteebb6f4b2010-11-10 17:09:21 -0500231 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 -0600232 }
Barry Mienydd671972010-10-04 16:33:58 +0200233
Derek Jones218876c2010-03-02 13:11:00 -0600234 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
Barry Mienydd671972010-10-04 16:33:58 +0200235
Derek Jones218876c2010-03-02 13:11:00 -0600236 // 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();
Barry Mienydd671972010-10-04 16:33:58 +0200250
Derek Jones218876c2010-03-02 13:11:00 -0600251 if ( ! class_exists($class)
Derek Jones218876c2010-03-02 13:11:00 -0600252 OR strncmp($method, '_', 1) == 0
Greg Aker63277b82010-11-09 13:46:13 -0600253 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
Derek Jones218876c2010-03-02 13:11:00 -0600254 )
255 {
256 show_404("{$class}/{$method}");
257 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000258
259/*
260 * ------------------------------------------------------
261 * Is there a "pre_controller" hook?
262 * ------------------------------------------------------
263 */
Derek Jones218876c2010-03-02 13:11:00 -0600264 $EXT->_call_hook('pre_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000265
266/*
267 * ------------------------------------------------------
Derek Jones218876c2010-03-02 13:11:00 -0600268 * Instantiate the requested controller
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 * ------------------------------------------------------
270 */
Derek Jones218876c2010-03-02 13:11:00 -0600271 // Mark a start point so we can benchmark the controller
272 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Jones218876c2010-03-02 13:11:00 -0600274 $CI = new $class();
275
276/*
277 * ------------------------------------------------------
278 * Is there a "post_controller_constructor" hook?
279 * ------------------------------------------------------
280 */
281 $EXT->_call_hook('post_controller_constructor');
282
283/*
284 * ------------------------------------------------------
285 * Call the requested method
286 * ------------------------------------------------------
287 */
288 // Is there a "remap" function? If so, we call it instead
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 if (method_exists($CI, '_remap'))
290 {
Pascal Kriete3431ae32010-11-09 15:19:50 -0500291 $CI->_remap($method, array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 }
293 else
294 {
295 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
296 // methods, so we'll use this workaround for consistent behavior
297 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
298 {
299 show_404("{$class}/{$method}");
300 }
301
302 // Call the requested method.
Barry Mienydd671972010-10-04 16:33:58 +0200303 // Any URI segments present (besides the class/function) will be passed to the method for convenience
304 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000306
Barry Mienydd671972010-10-04 16:33:58 +0200307
Derek Jones218876c2010-03-02 13:11:00 -0600308 // Mark a benchmark end point
309 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
Derek Allard2067d1a2008-11-13 22:59:24 +0000310
311/*
312 * ------------------------------------------------------
313 * Is there a "post_controller" hook?
314 * ------------------------------------------------------
315 */
Derek Jones218876c2010-03-02 13:11:00 -0600316 $EXT->_call_hook('post_controller');
Derek Allard2067d1a2008-11-13 22:59:24 +0000317
318/*
319 * ------------------------------------------------------
320 * Send the final rendered output to the browser
321 * ------------------------------------------------------
322 */
Derek Jones218876c2010-03-02 13:11:00 -0600323 if ($EXT->_call_hook('display_override') === FALSE)
324 {
325 $OUT->_display();
326 }
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328/*
329 * ------------------------------------------------------
330 * Is there a "post_system" hook?
331 * ------------------------------------------------------
332 */
Derek Jones218876c2010-03-02 13:11:00 -0600333 $EXT->_call_hook('post_system');
Derek Allard2067d1a2008-11-13 22:59:24 +0000334
335/*
336 * ------------------------------------------------------
337 * Close the DB connection if one exists
338 * ------------------------------------------------------
339 */
Derek Jones218876c2010-03-02 13:11:00 -0600340 if (class_exists('CI_DB') AND isset($CI->db))
341 {
342 $CI->db->close();
343 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000344
345
346/* End of file CodeIgniter.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -0600347/* Location: ./system/core/CodeIgniter.php */