1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
19 * System Front Controller
\r
21 * Loads the base classes and executes the request.
\r
23 * @package CodeIgniter
\r
24 * @subpackage codeigniter
\r
25 * @category Front-controller
\r
26 * @author ExpressionEngine Dev Team
\r
27 * @link http://codeigniter.com/user_guide/
\r
31 define('CI_VERSION', '1.7.0');
\r
34 * ------------------------------------------------------
\r
35 * Load the global functions
\r
36 * ------------------------------------------------------
\r
38 require(BASEPATH.'codeigniter/Common'.EXT);
\r
41 * ------------------------------------------------------
\r
42 * Load the compatibility override functions
\r
43 * ------------------------------------------------------
\r
45 require(BASEPATH.'codeigniter/Compat'.EXT);
\r
48 * ------------------------------------------------------
\r
49 * Load the framework constants
\r
50 * ------------------------------------------------------
\r
52 require(APPPATH.'config/constants'.EXT);
\r
55 * ------------------------------------------------------
\r
56 * Define a custom error handler so we can log PHP errors
\r
57 * ------------------------------------------------------
\r
59 set_error_handler('_exception_handler');
\r
60 set_magic_quotes_runtime(0); // Kill magic quotes
\r
63 * ------------------------------------------------------
\r
64 * Start the timer... tick tock tick tock...
\r
65 * ------------------------------------------------------
\r
68 $BM =& load_class('Benchmark');
\r
69 $BM->mark('total_execution_time_start');
\r
70 $BM->mark('loading_time_base_classes_start');
\r
73 * ------------------------------------------------------
\r
74 * Instantiate the hooks class
\r
75 * ------------------------------------------------------
\r
78 $EXT =& load_class('Hooks');
\r
81 * ------------------------------------------------------
\r
82 * Is there a "pre_system" hook?
\r
83 * ------------------------------------------------------
\r
85 $EXT->_call_hook('pre_system');
\r
88 * ------------------------------------------------------
\r
89 * Instantiate the base classes
\r
90 * ------------------------------------------------------
\r
93 $CFG =& load_class('Config');
\r
94 $URI =& load_class('URI');
\r
95 $RTR =& load_class('Router');
\r
96 $OUT =& load_class('Output');
\r
99 * ------------------------------------------------------
\r
100 * Is there a valid cache file? If so, we're done...
\r
101 * ------------------------------------------------------
\r
104 if ($EXT->_call_hook('cache_override') === FALSE)
\r
106 if ($OUT->_display_cache($CFG, $URI) == TRUE)
\r
113 * ------------------------------------------------------
\r
114 * Load the remaining base classes
\r
115 * ------------------------------------------------------
\r
118 $IN =& load_class('Input');
\r
119 $LANG =& load_class('Language');
\r
122 * ------------------------------------------------------
\r
123 * Load the app controller and local controller
\r
124 * ------------------------------------------------------
\r
126 * Note: Due to the poor object handling in PHP 4 we'll
\r
127 * conditionally load different versions of the base
\r
128 * class. Retaining PHP 4 compatibility requires a bit of a hack.
\r
130 * Note: The Loader class needs to be included first
\r
133 if (floor(phpversion()) < 5)
\r
135 load_class('Loader', FALSE);
\r
136 require(BASEPATH.'codeigniter/Base4'.EXT);
\r
140 require(BASEPATH.'codeigniter/Base5'.EXT);
\r
143 // Load the base controller class
\r
144 load_class('Controller', FALSE);
\r
146 // Load the local application controller
\r
147 // Note: The Router class automatically validates the controller path. If this include fails it
\r
148 // means that the default controller in the Routes.php file is not resolving to something valid.
\r
149 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
\r
151 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
\r
154 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
\r
156 // Set a mark point for benchmarking
\r
157 $BM->mark('loading_time_base_classes_end');
\r
161 * ------------------------------------------------------
\r
163 * ------------------------------------------------------
\r
165 * None of the functions in the app controller or the
\r
166 * loader class can be called via the URI, nor can
\r
167 * controller functions that begin with an underscore
\r
169 $class = $RTR->fetch_class();
\r
170 $method = $RTR->fetch_method();
\r
172 if ( ! class_exists($class)
\r
173 OR $method == 'controller'
\r
174 OR strncmp($method, '_', 1) == 0
\r
175 OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
\r
178 show_404("{$class}/{$method}");
\r
182 * ------------------------------------------------------
\r
183 * Is there a "pre_controller" hook?
\r
184 * ------------------------------------------------------
\r
186 $EXT->_call_hook('pre_controller');
\r
189 * ------------------------------------------------------
\r
190 * Instantiate the controller and call requested method
\r
191 * ------------------------------------------------------
\r
194 // Mark a start point so we can benchmark the controller
\r
195 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
\r
197 $CI = new $class();
\r
199 // Is this a scaffolding request?
\r
200 if ($RTR->scaffolding_request === TRUE)
\r
202 if ($EXT->_call_hook('scaffolding_override') === FALSE)
\r
204 $CI->_ci_scaffolding();
\r
210 * ------------------------------------------------------
\r
211 * Is there a "post_controller_constructor" hook?
\r
212 * ------------------------------------------------------
\r
214 $EXT->_call_hook('post_controller_constructor');
\r
216 // Is there a "remap" function?
\r
217 if (method_exists($CI, '_remap'))
\r
219 $CI->_remap($method);
\r
223 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
\r
224 // methods, so we'll use this workaround for consistent behavior
\r
225 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
\r
227 show_404("{$class}/{$method}");
\r
230 // Call the requested method.
\r
231 // Any URI segments present (besides the class/function) will be passed to the method for convenience
\r
232 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
\r
236 // Mark a benchmark end point
\r
237 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
\r
240 * ------------------------------------------------------
\r
241 * Is there a "post_controller" hook?
\r
242 * ------------------------------------------------------
\r
244 $EXT->_call_hook('post_controller');
\r
247 * ------------------------------------------------------
\r
248 * Send the final rendered output to the browser
\r
249 * ------------------------------------------------------
\r
252 if ($EXT->_call_hook('display_override') === FALSE)
\r
258 * ------------------------------------------------------
\r
259 * Is there a "post_system" hook?
\r
260 * ------------------------------------------------------
\r
262 $EXT->_call_hook('post_system');
\r
265 * ------------------------------------------------------
\r
266 * Close the DB connection if one exists
\r
267 * ------------------------------------------------------
\r
269 if (class_exists('CI_DB') AND isset($CI->db))
\r
275 /* End of file CodeIgniter.php */
\r
276 /* Location: ./system/codeigniter/CodeIgniter.php */