blob: d1ef965ccb7aa321d79636b6c65d40465ac5d009 [file] [log] [blame]
Derek Allard3d879d52008-01-18 19:41:32 +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
9 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard3d879d52008-01-18 19:41:32 +000012 * @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
Derek Jones7a9193a2008-01-21 18:39:20 +000027 * @link http://codeigniter.com/user_guide/
Derek Allard3d879d52008-01-18 19:41:32 +000028 */
29
30// CI Version
Derek Allard197d10b2008-02-12 04:20:38 +000031define('CI_VERSION', '1.6.1');
Derek Allard3d879d52008-01-18 19:41:32 +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 * Define a custom error handler so we can log PHP errors
50 * ------------------------------------------------------
51 */
52set_error_handler('_exception_handler');
53set_magic_quotes_runtime(0); // Kill magic quotes
54
55/*
56 * ------------------------------------------------------
57 * Start the timer... tick tock tick tock...
58 * ------------------------------------------------------
59 */
60
61$BM =& load_class('Benchmark');
62$BM->mark('total_execution_time_start');
63$BM->mark('loading_time_base_classes_start');
64
65/*
66 * ------------------------------------------------------
67 * Instantiate the hooks class
68 * ------------------------------------------------------
69 */
70
71$EXT =& load_class('Hooks');
72
73/*
74 * ------------------------------------------------------
75 * Is there a "pre_system" hook?
76 * ------------------------------------------------------
77 */
78$EXT->_call_hook('pre_system');
79
80/*
81 * ------------------------------------------------------
82 * Instantiate the base classes
83 * ------------------------------------------------------
84 */
85
86$CFG =& load_class('Config');
87$URI =& load_class('URI');
88$RTR =& load_class('Router');
89$OUT =& load_class('Output');
90
91/*
92 * ------------------------------------------------------
93 * Is there a valid cache file? If so, we're done...
94 * ------------------------------------------------------
95 */
96
97if ($EXT->_call_hook('cache_override') === FALSE)
98{
99 if ($OUT->_display_cache($CFG, $RTR) == TRUE)
100 {
101 exit;
102 }
103}
104
105/*
106 * ------------------------------------------------------
107 * Load the remaining base classes
108 * ------------------------------------------------------
109 */
110
111$IN =& load_class('Input');
112$LANG =& load_class('Language');
113
114/*
115 * ------------------------------------------------------
116 * Load the app controller and local controller
117 * ------------------------------------------------------
118 *
119 * Note: Due to the poor object handling in PHP 4 we'll
120 * conditionally load different versions of the base
121 * class. Retaining PHP 4 compatibility requires a bit of a hack.
122 *
123 * Note: The Loader class needs to be included first
124 *
125 */
126if (floor(phpversion()) < 5)
127{
128 load_class('Loader', FALSE);
129 require(BASEPATH.'codeigniter/Base4'.EXT);
130}
131else
132{
133 require(BASEPATH.'codeigniter/Base5'.EXT);
134}
135
136// Load the base controller class
137load_class('Controller', FALSE);
138
139// Load the local application controller
140// Note: The Router class automatically validates the controller path. If this include fails it
141// means that the default controller in the Routes.php file is not resolving to something valid.
142if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
143{
144 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
145}
146
147include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
148
149// Set a mark point for benchmarking
150$BM->mark('loading_time_base_classes_end');
151
152
153/*
154 * ------------------------------------------------------
155 * Security check
156 * ------------------------------------------------------
157 *
158 * None of the functions in the app controller or the
159 * loader class can be called via the URI, nor can
160 * controller functions that begin with an underscore
161 */
162$class = $RTR->fetch_class();
163$method = $RTR->fetch_method();
164
165
166if ( ! class_exists($class)
167 OR $method == 'controller'
168 OR substr($method, 0, 1) == '_'
169 OR in_array($method, get_class_methods('Controller'), TRUE)
170 )
171{
Derek Jones8a160772008-02-27 05:19:50 +0000172 show_404("{$class}/{$method}");
Derek Allard3d879d52008-01-18 19:41:32 +0000173}
174
175/*
176 * ------------------------------------------------------
177 * Is there a "pre_controller" hook?
178 * ------------------------------------------------------
179 */
180$EXT->_call_hook('pre_controller');
181
182/*
183 * ------------------------------------------------------
184 * Instantiate the controller and call requested method
185 * ------------------------------------------------------
186 */
187
188// Mark a start point so we can benchmark the controller
189$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
190
191$CI = new $class();
192
193// Is this a scaffolding request?
194if ($RTR->scaffolding_request === TRUE)
195{
196 if ($EXT->_call_hook('scaffolding_override') === FALSE)
197 {
198 $CI->_ci_scaffolding();
199 }
200}
201else
202{
203 /*
204 * ------------------------------------------------------
205 * Is there a "post_controller_constructor" hook?
206 * ------------------------------------------------------
207 */
208 $EXT->_call_hook('post_controller_constructor');
209
210 // Is there a "remap" function?
211 if (method_exists($CI, '_remap'))
212 {
213 $CI->_remap($method);
214 }
215 else
216 {
Derek Jones8a160772008-02-27 05:19:50 +0000217 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
218 // methods, so we'll use this workaround for consistent behavior
219 if (! in_array($method, get_class_methods($CI)))
Derek Allard3d879d52008-01-18 19:41:32 +0000220 {
Derek Jones8a160772008-02-27 05:19:50 +0000221 show_404("{$class}/{$method}");
Derek Allard3d879d52008-01-18 19:41:32 +0000222 }
223
224 // Call the requested method.
225 // Any URI segments present (besides the class/function) will be passed to the method for convenience
Derek Jonesf30445b2008-01-30 05:23:32 +0000226 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard3d879d52008-01-18 19:41:32 +0000227 }
228}
229
230// Mark a benchmark end point
231$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
232
233/*
234 * ------------------------------------------------------
235 * Is there a "post_controller" hook?
236 * ------------------------------------------------------
237 */
238$EXT->_call_hook('post_controller');
239
240/*
241 * ------------------------------------------------------
242 * Send the final rendered output to the browser
243 * ------------------------------------------------------
244 */
245
246if ($EXT->_call_hook('display_override') === FALSE)
247{
248 $OUT->_display();
249}
250
251/*
252 * ------------------------------------------------------
253 * Is there a "post_system" hook?
254 * ------------------------------------------------------
255 */
256$EXT->_call_hook('post_system');
257
258/*
259 * ------------------------------------------------------
260 * Close the DB connection if one exists
261 * ------------------------------------------------------
262 */
263if (class_exists('CI_DB') AND isset($CI->db))
264{
265 $CI->db->close();
266}
267
268
269?>