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, 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.0');
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');
60 set_magic_quotes_runtime(0); // Kill magic quotes
63 * ------------------------------------------------------
64 * Start the timer... tick tock tick tock...
65 * ------------------------------------------------------
68 $BM =& load_class('Benchmark');
69 $BM->mark('total_execution_time_start');
70 $BM->mark('loading_time_base_classes_start');
73 * ------------------------------------------------------
74 * Instantiate the hooks class
75 * ------------------------------------------------------
78 $EXT =& load_class('Hooks');
81 * ------------------------------------------------------
82 * Is there a "pre_system" hook?
83 * ------------------------------------------------------
85 $EXT->_call_hook('pre_system');
88 * ------------------------------------------------------
89 * Instantiate the base classes
90 * ------------------------------------------------------
93 $CFG =& load_class('Config');
94 $URI =& load_class('URI');
95 $RTR =& load_class('Router');
96 $OUT =& load_class('Output');
99 * ------------------------------------------------------
100 * Is there a valid cache file? If so, we're done...
101 * ------------------------------------------------------
104 if ($EXT->_call_hook('cache_override') === FALSE)
106 if ($OUT->_display_cache($CFG, $URI) == TRUE)
113 * ------------------------------------------------------
114 * Load the remaining base classes
115 * ------------------------------------------------------
118 $IN =& load_class('Input');
119 $LANG =& load_class('Language');
122 * ------------------------------------------------------
123 * Load the app controller and local controller
124 * ------------------------------------------------------
126 * Note: Due to the poor object handling in PHP 4 we'll
127 * conditionally load different versions of the base
128 * class. Retaining PHP 4 compatibility requires a bit of a hack.
130 * Note: The Loader class needs to be included first
133 if (floor(phpversion()) < 5)
135 load_class('Loader', FALSE);
136 require(BASEPATH.'codeigniter/Base4'.EXT);
140 require(BASEPATH.'codeigniter/Base5'.EXT);
143 // Load the base controller class
144 load_class('Controller', FALSE);
146 // Load the local application controller
147 // Note: The Router class automatically validates the controller path. If this include fails it
148 // means that the default controller in the Routes.php file is not resolving to something valid.
149 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
151 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
154 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
156 // Set a mark point for benchmarking
157 $BM->mark('loading_time_base_classes_end');
161 * ------------------------------------------------------
163 * ------------------------------------------------------
165 * None of the functions in the app controller or the
166 * loader class can be called via the URI, nor can
167 * controller functions that begin with an underscore
169 $class = $RTR->fetch_class();
170 $method = $RTR->fetch_method();
172 if ( ! class_exists($class)
173 OR $method == 'controller'
174 OR strncmp($method, '_', 1) == 0
175 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
178 show_404("{$class}/{$method}");
182 * ------------------------------------------------------
183 * Is there a "pre_controller" hook?
184 * ------------------------------------------------------
186 $EXT->_call_hook('pre_controller');
189 * ------------------------------------------------------
190 * Instantiate the controller and call requested method
191 * ------------------------------------------------------
194 // Mark a start point so we can benchmark the controller
195 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
199 // Is this a scaffolding request?
200 if ($RTR->scaffolding_request === TRUE)
202 if ($EXT->_call_hook('scaffolding_override') === FALSE)
204 $CI->_ci_scaffolding();
210 * ------------------------------------------------------
211 * Is there a "post_controller_constructor" hook?
212 * ------------------------------------------------------
214 $EXT->_call_hook('post_controller_constructor');
216 // Is there a "remap" function?
217 if (method_exists($CI, '_remap'))
219 $CI->_remap($method);
223 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
224 // methods, so we'll use this workaround for consistent behavior
225 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
227 show_404("{$class}/{$method}");
230 // Call the requested method.
231 // Any URI segments present (besides the class/function) will be passed to the method for convenience
232 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
236 // Mark a benchmark end point
237 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
240 * ------------------------------------------------------
241 * Is there a "post_controller" hook?
242 * ------------------------------------------------------
244 $EXT->_call_hook('post_controller');
247 * ------------------------------------------------------
248 * Send the final rendered output to the browser
249 * ------------------------------------------------------
252 if ($EXT->_call_hook('display_override') === FALSE)
258 * ------------------------------------------------------
259 * Is there a "post_system" hook?
260 * ------------------------------------------------------
262 $EXT->_call_hook('post_system');
265 * ------------------------------------------------------
266 * Close the DB connection if one exists
267 * ------------------------------------------------------
269 if (class_exists('CI_DB') AND isset($CI->db))
275 /* End of file CodeIgniter.php */
276 /* Location: ./system/codeigniter/CodeIgniter.php */