blob: 5d5bb144b43e084af95fceb6b41ed94b34da36d0 [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/**
19 * System Front Controller
20 *
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
30// CI Version
Derek Jonesbbedc762009-09-11 14:47:37 +000031define('CI_VERSION', '1.7.2');
Derek Allard2067d1a2008-11-13 22:59:24 +000032
33/*
34 * ------------------------------------------------------
35 * Load the global functions
36 * ------------------------------------------------------
37 */
38require(BASEPATH.'codeigniter/Common'.EXT);
39
40/*
41 * ------------------------------------------------------
42 * Load the compatibility override functions
43 * ------------------------------------------------------
44 */
45require(BASEPATH.'codeigniter/Compat'.EXT);
46
47/*
48 * ------------------------------------------------------
49 * Load the framework constants
50 * ------------------------------------------------------
51 */
52require(APPPATH.'config/constants'.EXT);
53
54/*
55 * ------------------------------------------------------
56 * Define a custom error handler so we can log PHP errors
57 * ------------------------------------------------------
58 */
Derek Jones109ad992009-07-29 14:24:46 +000059set_error_handler('_exception_handler');
Derek Jones962d2252009-08-05 04:26:11 +000060
Derek Jones77b513b2009-08-06 14:39:25 +000061if ( ! is_php('5.3'))
Derek Jones962d2252009-08-05 04:26:11 +000062{
63 @set_magic_quotes_runtime(0); // Kill magic quotes
64}
Derek Allard2067d1a2008-11-13 22:59:24 +000065
66/*
67 * ------------------------------------------------------
68 * Start the timer... tick tock tick tock...
69 * ------------------------------------------------------
70 */
71
72$BM =& load_class('Benchmark');
73$BM->mark('total_execution_time_start');
74$BM->mark('loading_time_base_classes_start');
75
76/*
77 * ------------------------------------------------------
78 * Instantiate the hooks class
79 * ------------------------------------------------------
80 */
81
82$EXT =& load_class('Hooks');
83
84/*
85 * ------------------------------------------------------
86 * Is there a "pre_system" hook?
87 * ------------------------------------------------------
88 */
89$EXT->_call_hook('pre_system');
90
91/*
92 * ------------------------------------------------------
93 * Instantiate the base classes
94 * ------------------------------------------------------
95 */
96
97$CFG =& load_class('Config');
98$URI =& load_class('URI');
99$RTR =& load_class('Router');
100$OUT =& load_class('Output');
101
102/*
103 * ------------------------------------------------------
104 * Is there a valid cache file? If so, we're done...
105 * ------------------------------------------------------
106 */
107
108if ($EXT->_call_hook('cache_override') === FALSE)
109{
110 if ($OUT->_display_cache($CFG, $URI) == TRUE)
111 {
112 exit;
113 }
114}
115
116/*
117 * ------------------------------------------------------
118 * Load the remaining base classes
119 * ------------------------------------------------------
120 */
121
122$IN =& load_class('Input');
123$LANG =& load_class('Language');
124
125/*
126 * ------------------------------------------------------
127 * Load the app controller and local controller
128 * ------------------------------------------------------
129 *
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.
133 *
134 * Note: The Loader class needs to be included first
135 *
136 */
Derek Jones8f26dbe2009-08-06 14:45:07 +0000137if ( ! is_php('5.0.0'))
Derek Allard2067d1a2008-11-13 22:59:24 +0000138{
139 load_class('Loader', FALSE);
140 require(BASEPATH.'codeigniter/Base4'.EXT);
141}
142else
143{
144 require(BASEPATH.'codeigniter/Base5'.EXT);
145}
146
147// Load the base controller class
148load_class('Controller', FALSE);
149
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.
153if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
154{
155 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
156}
157
158include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
159
160// Set a mark point for benchmarking
161$BM->mark('loading_time_base_classes_end');
162
163
164/*
165 * ------------------------------------------------------
166 * Security check
167 * ------------------------------------------------------
168 *
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
172 */
173$class = $RTR->fetch_class();
174$method = $RTR->fetch_method();
175
176if ( ! 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')))
180 )
181{
182 show_404("{$class}/{$method}");
183}
184
185/*
186 * ------------------------------------------------------
187 * Is there a "pre_controller" hook?
188 * ------------------------------------------------------
189 */
190$EXT->_call_hook('pre_controller');
191
192/*
193 * ------------------------------------------------------
194 * Instantiate the controller and call requested method
195 * ------------------------------------------------------
196 */
197
198// Mark a start point so we can benchmark the controller
199$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
200
201$CI = new $class();
202
203// Is this a scaffolding request?
204if ($RTR->scaffolding_request === TRUE)
205{
206 if ($EXT->_call_hook('scaffolding_override') === FALSE)
207 {
208 $CI->_ci_scaffolding();
209 }
210}
211else
212{
213 /*
214 * ------------------------------------------------------
215 * Is there a "post_controller_constructor" hook?
216 * ------------------------------------------------------
217 */
218 $EXT->_call_hook('post_controller_constructor');
219
220 // Is there a "remap" function?
221 if (method_exists($CI, '_remap'))
222 {
223 $CI->_remap($method);
224 }
225 else
226 {
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))))
230 {
231 show_404("{$class}/{$method}");
232 }
233
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));
237 }
238}
239
240// Mark a benchmark end point
241$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
242
243/*
244 * ------------------------------------------------------
245 * Is there a "post_controller" hook?
246 * ------------------------------------------------------
247 */
248$EXT->_call_hook('post_controller');
249
250/*
251 * ------------------------------------------------------
252 * Send the final rendered output to the browser
253 * ------------------------------------------------------
254 */
255
256if ($EXT->_call_hook('display_override') === FALSE)
257{
258 $OUT->_display();
259}
260
261/*
262 * ------------------------------------------------------
263 * Is there a "post_system" hook?
264 * ------------------------------------------------------
265 */
266$EXT->_call_hook('post_system');
267
268/*
269 * ------------------------------------------------------
270 * Close the DB connection if one exists
271 * ------------------------------------------------------
272 */
273if (class_exists('CI_DB') AND isset($CI->db))
274{
275 $CI->db->close();
276}
277
278
279/* End of file CodeIgniter.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000280/* Location: ./system/codeigniter/CodeIgniter.php */