1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * System Front Controller
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 define('CI_VERSION', '1.7.2');
34 * ------------------------------------------------------
35 * Load the global functions
36 * ------------------------------------------------------
38 require(BASEPATH.'codeigniter/Common'.EXT);
41 * ------------------------------------------------------
42 * Load the compatibility override functions
43 * ------------------------------------------------------
45 require(BASEPATH.'codeigniter/Compat'.EXT);
48 * ------------------------------------------------------
49 * Load the framework constants
50 * ------------------------------------------------------
52 require(APPPATH.'config/constants'.EXT);
55 * ------------------------------------------------------
56 * Define a custom error handler so we can log PHP errors
57 * ------------------------------------------------------
59 set_error_handler('_exception_handler');
63 @set_magic_quotes_runtime(0); // Kill magic quotes
67 * ------------------------------------------------------
68 * Start the timer... tick tock tick tock...
69 * ------------------------------------------------------
72 $BM =& load_class('Benchmark');
73 $BM->mark('total_execution_time_start');
74 $BM->mark('loading_time_base_classes_start');
77 * ------------------------------------------------------
78 * Instantiate the hooks class
79 * ------------------------------------------------------
82 $EXT =& load_class('Hooks');
85 * ------------------------------------------------------
86 * Is there a "pre_system" hook?
87 * ------------------------------------------------------
89 $EXT->_call_hook('pre_system');
92 * ------------------------------------------------------
93 * Instantiate the base classes
94 * ------------------------------------------------------
97 $CFG =& load_class('Config');
98 $URI =& load_class('URI');
99 $RTR =& load_class('Router');
100 $OUT =& load_class('Output');
103 * ------------------------------------------------------
104 * Is there a valid cache file? If so, we're done...
105 * ------------------------------------------------------
108 if ($EXT->_call_hook('cache_override') === FALSE)
110 if ($OUT->_display_cache($CFG, $URI) == TRUE)
117 * ------------------------------------------------------
118 * Load the remaining base classes
119 * ------------------------------------------------------
122 $IN =& load_class('Input');
123 $LANG =& load_class('Language');
126 * ------------------------------------------------------
127 * Load the app controller and local controller
128 * ------------------------------------------------------
130 * Note: Due to the poor object handling in PHP 4 we'll
131 * conditionally load different versions of the base
132 * class. Retaining PHP 4 compatibility requires a bit of a hack.
134 * Note: The Loader class needs to be included first
137 if ( ! is_php('5.0.0'))
139 load_class('Loader', FALSE);
140 require(BASEPATH.'codeigniter/Base4'.EXT);
144 require(BASEPATH.'codeigniter/Base5'.EXT);
147 // Load the base controller class
148 load_class('Controller', FALSE);
150 // Load the local application controller
151 // Note: The Router class automatically validates the controller path. If this include fails it
152 // means that the default controller in the Routes.php file is not resolving to something valid.
153 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
155 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
158 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
160 // Set a mark point for benchmarking
161 $BM->mark('loading_time_base_classes_end');
165 * ------------------------------------------------------
167 * ------------------------------------------------------
169 * None of the functions in the app controller or the
170 * loader class can be called via the URI, nor can
171 * controller functions that begin with an underscore
173 $class = $RTR->fetch_class();
174 $method = $RTR->fetch_method();
176 if ( ! class_exists($class)
177 OR $method == 'controller'
178 OR strncmp($method, '_', 1) == 0
179 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
182 show_404("{$class}/{$method}");
186 * ------------------------------------------------------
187 * Is there a "pre_controller" hook?
188 * ------------------------------------------------------
190 $EXT->_call_hook('pre_controller');
193 * ------------------------------------------------------
194 * Instantiate the controller and call requested method
195 * ------------------------------------------------------
198 // Mark a start point so we can benchmark the controller
199 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
203 // Is this a scaffolding request?
204 if ($RTR->scaffolding_request === TRUE)
206 if ($EXT->_call_hook('scaffolding_override') === FALSE)
208 $CI->_ci_scaffolding();
214 * ------------------------------------------------------
215 * Is there a "post_controller_constructor" hook?
216 * ------------------------------------------------------
218 $EXT->_call_hook('post_controller_constructor');
220 // Is there a "remap" function?
221 if (method_exists($CI, '_remap'))
223 $CI->_remap($method);
227 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
228 // methods, so we'll use this workaround for consistent behavior
229 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
231 show_404("{$class}/{$method}");
234 // Call the requested method.
235 // Any URI segments present (besides the class/function) will be passed to the method for convenience
236 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
240 // Mark a benchmark end point
241 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
244 * ------------------------------------------------------
245 * Is there a "post_controller" hook?
246 * ------------------------------------------------------
248 $EXT->_call_hook('post_controller');
251 * ------------------------------------------------------
252 * Send the final rendered output to the browser
253 * ------------------------------------------------------
256 if ($EXT->_call_hook('display_override') === FALSE)
262 * ------------------------------------------------------
263 * Is there a "post_system" hook?
264 * ------------------------------------------------------
266 $EXT->_call_hook('post_system');
269 * ------------------------------------------------------
270 * Close the DB connection if one exists
271 * ------------------------------------------------------
273 if (class_exists('CI_DB') AND isset($CI->db))
279 /* End of file CodeIgniter.php */
280 /* Location: ./system/codeigniter/CodeIgniter.php */