blob: 74e5e8b44ea0846ccb5886a621320e0d91e09e48 [file] [log] [blame]
Derek Jones0b59f272008-05-13 04:22:33 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard3d879d52008-01-18 19:41:32 +00002/**
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 Allardf9f9f662008-05-06 17:03:57 +000031define('CI_VERSION', '1.6.2');
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);
Derek Jones3ad8efe2008-04-04 18:56:04 +000046
47/*
48 * ------------------------------------------------------
Derek Jonese146ed72008-04-08 20:29:53 +000049 * Load the framework constants
Derek Jones3ad8efe2008-04-04 18:56:04 +000050 * ------------------------------------------------------
51 */
52require(APPPATH.'config/constants'.EXT);
53
Derek Allard3d879d52008-01-18 19:41:32 +000054/*
55 * ------------------------------------------------------
56 * Define a custom error handler so we can log PHP errors
57 * ------------------------------------------------------
58 */
59set_error_handler('_exception_handler');
60set_magic_quotes_runtime(0); // Kill magic quotes
61
62/*
63 * ------------------------------------------------------
64 * Start the timer... tick tock tick tock...
65 * ------------------------------------------------------
66 */
67
68$BM =& load_class('Benchmark');
69$BM->mark('total_execution_time_start');
70$BM->mark('loading_time_base_classes_start');
71
72/*
73 * ------------------------------------------------------
74 * Instantiate the hooks class
75 * ------------------------------------------------------
76 */
77
78$EXT =& load_class('Hooks');
79
80/*
81 * ------------------------------------------------------
82 * Is there a "pre_system" hook?
83 * ------------------------------------------------------
84 */
85$EXT->_call_hook('pre_system');
86
87/*
88 * ------------------------------------------------------
89 * Instantiate the base classes
90 * ------------------------------------------------------
91 */
92
93$CFG =& load_class('Config');
94$URI =& load_class('URI');
95$RTR =& load_class('Router');
96$OUT =& load_class('Output');
97
98/*
99 * ------------------------------------------------------
100 * Is there a valid cache file? If so, we're done...
101 * ------------------------------------------------------
102 */
103
104if ($EXT->_call_hook('cache_override') === FALSE)
105{
Derek Allard57aea152008-06-06 14:17:57 +0000106 if ($OUT->_display_cache($CFG, $URI) == TRUE)
Derek Allard3d879d52008-01-18 19:41:32 +0000107 {
108 exit;
109 }
110}
111
112/*
113 * ------------------------------------------------------
114 * Load the remaining base classes
115 * ------------------------------------------------------
116 */
117
118$IN =& load_class('Input');
119$LANG =& load_class('Language');
120
121/*
122 * ------------------------------------------------------
123 * Load the app controller and local controller
124 * ------------------------------------------------------
125 *
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.
129 *
130 * Note: The Loader class needs to be included first
131 *
132 */
133if (floor(phpversion()) < 5)
134{
135 load_class('Loader', FALSE);
136 require(BASEPATH.'codeigniter/Base4'.EXT);
137}
138else
139{
140 require(BASEPATH.'codeigniter/Base5'.EXT);
141}
142
143// Load the base controller class
144load_class('Controller', FALSE);
145
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.
Derek Jones0b59f272008-05-13 04:22:33 +0000149if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
Derek Allard3d879d52008-01-18 19:41:32 +0000150{
151 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
152}
153
154include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
155
156// Set a mark point for benchmarking
157$BM->mark('loading_time_base_classes_end');
158
159
160/*
161 * ------------------------------------------------------
162 * Security check
163 * ------------------------------------------------------
164 *
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
168 */
169$class = $RTR->fetch_class();
170$method = $RTR->fetch_method();
171
172
Derek Jones0b59f272008-05-13 04:22:33 +0000173if ( ! class_exists($class)
Derek Allard3d879d52008-01-18 19:41:32 +0000174 OR $method == 'controller'
Derek Allard15dcf492008-05-12 21:37:04 +0000175 OR strncmp($method, '_', 1) == 0
Derek Allard3d879d52008-01-18 19:41:32 +0000176 OR in_array($method, get_class_methods('Controller'), TRUE)
177 )
178{
Derek Jones8a160772008-02-27 05:19:50 +0000179 show_404("{$class}/{$method}");
Derek Allard3d879d52008-01-18 19:41:32 +0000180}
181
182/*
183 * ------------------------------------------------------
184 * Is there a "pre_controller" hook?
185 * ------------------------------------------------------
186 */
187$EXT->_call_hook('pre_controller');
188
189/*
190 * ------------------------------------------------------
191 * Instantiate the controller and call requested method
192 * ------------------------------------------------------
193 */
194
195// Mark a start point so we can benchmark the controller
196$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
197
198$CI = new $class();
199
200// Is this a scaffolding request?
201if ($RTR->scaffolding_request === TRUE)
202{
203 if ($EXT->_call_hook('scaffolding_override') === FALSE)
204 {
205 $CI->_ci_scaffolding();
206 }
207}
208else
209{
210 /*
211 * ------------------------------------------------------
212 * Is there a "post_controller_constructor" hook?
213 * ------------------------------------------------------
214 */
215 $EXT->_call_hook('post_controller_constructor');
216
217 // Is there a "remap" function?
218 if (method_exists($CI, '_remap'))
219 {
220 $CI->_remap($method);
221 }
222 else
223 {
Derek Jones8a160772008-02-27 05:19:50 +0000224 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
225 // methods, so we'll use this workaround for consistent behavior
Derek Jones0b59f272008-05-13 04:22:33 +0000226 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
Derek Allard3d879d52008-01-18 19:41:32 +0000227 {
Derek Jones8a160772008-02-27 05:19:50 +0000228 show_404("{$class}/{$method}");
Derek Allard3d879d52008-01-18 19:41:32 +0000229 }
230
231 // Call the requested method.
Derek Allard0fd8f022008-05-13 02:01:47 +0000232 // Any URI segments present (besides the class/function) will be passed to the method for convenience
233 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
Derek Allard3d879d52008-01-18 19:41:32 +0000234 }
235}
236
237// Mark a benchmark end point
238$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
239
240/*
241 * ------------------------------------------------------
242 * Is there a "post_controller" hook?
243 * ------------------------------------------------------
244 */
245$EXT->_call_hook('post_controller');
246
247/*
248 * ------------------------------------------------------
249 * Send the final rendered output to the browser
250 * ------------------------------------------------------
251 */
252
253if ($EXT->_call_hook('display_override') === FALSE)
254{
255 $OUT->_display();
256}
257
258/*
259 * ------------------------------------------------------
260 * Is there a "post_system" hook?
261 * ------------------------------------------------------
262 */
263$EXT->_call_hook('post_system');
264
265/*
266 * ------------------------------------------------------
267 * Close the DB connection if one exists
268 * ------------------------------------------------------
269 */
270if (class_exists('CI_DB') AND isset($CI->db))
271{
272 $CI->db->close();
273}
274
275
Derek Allard15dcf492008-05-12 21:37:04 +0000276/* End of file CodeIgniter.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000277/* Location: ./system/codeigniter/CodeIgniter.php */