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