Provide better error reporting and error checking when updating a network
[www-register-wizard.git] / codeigniter / CodeIgniter.php
1 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
2 /**\r
3  * CodeIgniter\r
4  *\r
5  * An open source application development framework for PHP 4.3.2 or newer\r
6  *\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
13  * @filesource\r
14  */\r
15 \r
16 // ------------------------------------------------------------------------\r
17 \r
18 /**\r
19  * System Front Controller\r
20  *\r
21  * Loads the base classes and executes the request.\r
22  *\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
28  */\r
29 \r
30 // CI Version\r
31 define('CI_VERSION',    '1.7.0');\r
32 \r
33 /*\r
34  * ------------------------------------------------------\r
35  *  Load the global functions\r
36  * ------------------------------------------------------\r
37  */\r
38 require(BASEPATH.'codeigniter/Common'.EXT);\r
39 \r
40 /*\r
41  * ------------------------------------------------------\r
42  *  Load the compatibility override functions\r
43  * ------------------------------------------------------\r
44  */\r
45 require(BASEPATH.'codeigniter/Compat'.EXT);\r
46 \r
47 /*\r
48  * ------------------------------------------------------\r
49  *  Load the framework constants\r
50  * ------------------------------------------------------\r
51  */\r
52 require(APPPATH.'config/constants'.EXT);\r
53 \r
54 /*\r
55  * ------------------------------------------------------\r
56  *  Define a custom error handler so we can log PHP errors\r
57  * ------------------------------------------------------\r
58  */\r
59 set_error_handler('_exception_handler');\r
60 set_magic_quotes_runtime(0); // Kill magic quotes\r
61 \r
62 /*\r
63  * ------------------------------------------------------\r
64  *  Start the timer... tick tock tick tock...\r
65  * ------------------------------------------------------\r
66  */\r
67 \r
68 $BM =& load_class('Benchmark');\r
69 $BM->mark('total_execution_time_start');\r
70 $BM->mark('loading_time_base_classes_start');\r
71 \r
72 /*\r
73  * ------------------------------------------------------\r
74  *  Instantiate the hooks class\r
75  * ------------------------------------------------------\r
76  */\r
77 \r
78 $EXT =& load_class('Hooks');\r
79 \r
80 /*\r
81  * ------------------------------------------------------\r
82  *  Is there a "pre_system" hook?\r
83  * ------------------------------------------------------\r
84  */\r
85 $EXT->_call_hook('pre_system');\r
86 \r
87 /*\r
88  * ------------------------------------------------------\r
89  *  Instantiate the base classes\r
90  * ------------------------------------------------------\r
91  */\r
92 \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
97 \r
98 /*\r
99  * ------------------------------------------------------\r
100  *      Is there a valid cache file?  If so, we're done...\r
101  * ------------------------------------------------------\r
102  */\r
103 \r
104 if ($EXT->_call_hook('cache_override') === FALSE)\r
105 {\r
106         if ($OUT->_display_cache($CFG, $URI) == TRUE)\r
107         {\r
108                 exit;\r
109         }\r
110 }\r
111 \r
112 /*\r
113  * ------------------------------------------------------\r
114  *  Load the remaining base classes\r
115  * ------------------------------------------------------\r
116  */\r
117 \r
118 $IN             =& load_class('Input');\r
119 $LANG   =& load_class('Language');\r
120 \r
121 /*\r
122  * ------------------------------------------------------\r
123  *  Load the app controller and local controller\r
124  * ------------------------------------------------------\r
125  *\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
129  *\r
130  *  Note: The Loader class needs to be included first\r
131  *\r
132  */\r
133 if (floor(phpversion()) < 5)\r
134 {\r
135         load_class('Loader', FALSE);\r
136         require(BASEPATH.'codeigniter/Base4'.EXT);\r
137 }\r
138 else\r
139 {\r
140         require(BASEPATH.'codeigniter/Base5'.EXT);\r
141 }\r
142 \r
143 // Load the base controller class\r
144 load_class('Controller', FALSE);\r
145 \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
150 {\r
151         show_error('Unable to load your default controller.  Please make sure the controller specified in your Routes.php file is valid.');\r
152 }\r
153 \r
154 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);\r
155 \r
156 // Set a mark point for benchmarking\r
157 $BM->mark('loading_time_base_classes_end');\r
158 \r
159 \r
160 /*\r
161  * ------------------------------------------------------\r
162  *  Security check\r
163  * ------------------------------------------------------\r
164  *\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
168  */\r
169 $class  = $RTR->fetch_class();\r
170 $method = $RTR->fetch_method();\r
171 \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
176         )\r
177 {\r
178         show_404("{$class}/{$method}");\r
179 }\r
180 \r
181 /*\r
182  * ------------------------------------------------------\r
183  *  Is there a "pre_controller" hook?\r
184  * ------------------------------------------------------\r
185  */\r
186 $EXT->_call_hook('pre_controller');\r
187 \r
188 /*\r
189  * ------------------------------------------------------\r
190  *  Instantiate the controller and call requested method\r
191  * ------------------------------------------------------\r
192  */\r
193 \r
194 // Mark a start point so we can benchmark the controller\r
195 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');\r
196 \r
197 $CI = new $class();\r
198 \r
199 // Is this a scaffolding request?\r
200 if ($RTR->scaffolding_request === TRUE)\r
201 {\r
202         if ($EXT->_call_hook('scaffolding_override') === FALSE)\r
203         {\r
204                 $CI->_ci_scaffolding();\r
205         }\r
206 }\r
207 else\r
208 {\r
209         /*\r
210          * ------------------------------------------------------\r
211          *  Is there a "post_controller_constructor" hook?\r
212          * ------------------------------------------------------\r
213          */\r
214         $EXT->_call_hook('post_controller_constructor');\r
215         \r
216         // Is there a "remap" function?\r
217         if (method_exists($CI, '_remap'))\r
218         {\r
219                 $CI->_remap($method);\r
220         }\r
221         else\r
222         {\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
226                 {\r
227                         show_404("{$class}/{$method}");\r
228                 }\r
229 \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
233         }\r
234 }\r
235 \r
236 // Mark a benchmark end point\r
237 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');\r
238 \r
239 /*\r
240  * ------------------------------------------------------\r
241  *  Is there a "post_controller" hook?\r
242  * ------------------------------------------------------\r
243  */\r
244 $EXT->_call_hook('post_controller');\r
245 \r
246 /*\r
247  * ------------------------------------------------------\r
248  *  Send the final rendered output to the browser\r
249  * ------------------------------------------------------\r
250  */\r
251 \r
252 if ($EXT->_call_hook('display_override') === FALSE)\r
253 {\r
254         $OUT->_display();\r
255 }\r
256 \r
257 /*\r
258  * ------------------------------------------------------\r
259  *  Is there a "post_system" hook?\r
260  * ------------------------------------------------------\r
261  */\r
262 $EXT->_call_hook('post_system');\r
263 \r
264 /*\r
265  * ------------------------------------------------------\r
266  *  Close the DB connection if one exists\r
267  * ------------------------------------------------------\r
268  */\r
269 if (class_exists('CI_DB') AND isset($CI->db))\r
270 {\r
271         $CI->db->close();\r
272 }\r
273 \r
274 \r
275 /* End of file CodeIgniter.php */\r
276 /* Location: ./system/codeigniter/CodeIgniter.php */