blob: 3e2b99deaabb0932e04a718f163eb44bf61d1eec [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
admine334c472006-10-21 19:44:22 +000010 * @license http://www.codeignitor.com/user_guide/license.html
adminb0dd10f2006-08-25 17:25:49 +000011 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
admine334c472006-10-21 19:44:22 +000015
adminb0dd10f2006-08-25 17:25:49 +000016// ------------------------------------------------------------------------
17
18/**
19 * System Front Controller
20 *
admine334c472006-10-21 19:44:22 +000021 * Loads the base classes and executes the request.
22 *
adminb0dd10f2006-08-25 17:25:49 +000023 * @package CodeIgniter
24 * @subpackage codeigniter
25 * @category Front-controller
26 * @author Rick Ellis
27 * @link http://www.codeigniter.com/user_guide/
28 */
admine334c472006-10-21 19:44:22 +000029
admin41a16852006-09-26 18:17:19 +000030define('APPVER', '1.5.0');
adminb0dd10f2006-08-25 17:25:49 +000031
32/*
33 * ------------------------------------------------------
34 * Load the global functions
35 * ------------------------------------------------------
36 */
37require(BASEPATH.'codeigniter/Common'.EXT);
38
39/*
40 * ------------------------------------------------------
admin8f0a8f62006-10-07 01:17:25 +000041 * Define a custom error handler so we can log PHP errors
adminb0dd10f2006-08-25 17:25:49 +000042 * ------------------------------------------------------
43 */
44set_error_handler('_exception_handler');
45set_magic_quotes_runtime(0); // Kill magic quotes
46
47/*
48 * ------------------------------------------------------
49 * Start the timer... tick tock tick tock...
50 * ------------------------------------------------------
51 */
52
admin7099a582006-10-10 17:47:59 +000053$BM =& load_class('Benchmark');
admine26611f2006-10-02 21:59:12 +000054$BM->mark('total_execution_time_start');
adminafe3aaa2006-10-20 22:22:55 +000055$BM->mark('loading_time_base_classes_start');
adminb0dd10f2006-08-25 17:25:49 +000056
57/*
58 * ------------------------------------------------------
adminafe3aaa2006-10-20 22:22:55 +000059 * Instantiate the hooks class
adminb0dd10f2006-08-25 17:25:49 +000060 * ------------------------------------------------------
61 */
62
admin7099a582006-10-10 17:47:59 +000063$EXT =& load_class('Hooks');
adminb0dd10f2006-08-25 17:25:49 +000064
65/*
66 * ------------------------------------------------------
67 * Is there a "pre_system" hook?
68 * ------------------------------------------------------
69 */
adminaf436d72006-09-15 20:02:14 +000070$EXT->_call_hook('pre_system');
adminb0dd10f2006-08-25 17:25:49 +000071
72/*
73 * ------------------------------------------------------
74 * Instantiate the base classes
75 * ------------------------------------------------------
76 */
77
admin7099a582006-10-10 17:47:59 +000078$CFG =& load_class('Config');
79$RTR =& load_class('Router');
80$OUT =& load_class('Output');
adminb0dd10f2006-08-25 17:25:49 +000081
82/*
83 * ------------------------------------------------------
84 * Is there a valid cache file? If so, we're done...
85 * ------------------------------------------------------
86 */
admine334c472006-10-21 19:44:22 +000087
adminaf436d72006-09-15 20:02:14 +000088if ($EXT->_call_hook('cache_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +000089{
admin06508c42006-09-18 08:18:08 +000090 if ($OUT->_display_cache($CFG, $RTR) == TRUE)
adminb0dd10f2006-08-25 17:25:49 +000091 {
92 exit;
93 }
94}
95
96/*
97 * ------------------------------------------------------
adminb0dd10f2006-08-25 17:25:49 +000098 * Load the remaining base classes
99 * ------------------------------------------------------
100 */
101
admin7099a582006-10-10 17:47:59 +0000102$IN =& load_class('Input');
103$URI =& load_class('URI');
104$LANG =& load_class('Language');
adminb0dd10f2006-08-25 17:25:49 +0000105
106/*
107 * ------------------------------------------------------
108 * Load the app controller and local controller
109 * ------------------------------------------------------
admine334c472006-10-21 19:44:22 +0000110 *
adminb0dd10f2006-08-25 17:25:49 +0000111 * Note: Due to the poor object handling in PHP 4 we'll
adminafe3aaa2006-10-20 22:22:55 +0000112 * conditionally load different versions of the base
adminb0dd10f2006-08-25 17:25:49 +0000113 * class. Retaining PHP 4 compatibility requires a bit of a hack.
114 *
115 * Note: The Loader class needs to be included first
admine334c472006-10-21 19:44:22 +0000116 *
adminb0dd10f2006-08-25 17:25:49 +0000117 */
adminb0dd10f2006-08-25 17:25:49 +0000118if (floor(phpversion()) < 5)
119{
admincef21062006-10-30 17:13:13 +0000120 load_class('Loader', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000121 require(BASEPATH.'codeigniter/Base4'.EXT);
122}
123else
124{
125 require(BASEPATH.'codeigniter/Base5'.EXT);
126}
127
adminb93464d2006-10-31 00:36:32 +0000128// Load the base controller class
admine334c472006-10-21 19:44:22 +0000129load_class('Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000130
adminb93464d2006-10-31 00:36:32 +0000131// Load the local application controller
132// Note: The Router class automatically validates the controller path. If this include fails it
133// means that the default controller in the Routes.php file is not resolving to something valid.
134if ( ! @include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
135{
136 show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
137}
adminb0dd10f2006-08-25 17:25:49 +0000138
admin8f0a8f62006-10-07 01:17:25 +0000139// Set a mark point for benchmarking
adminafe3aaa2006-10-20 22:22:55 +0000140$BM->mark('loading_time_base_classes_end');
adminf6edc532006-10-03 05:28:09 +0000141
142
adminb0dd10f2006-08-25 17:25:49 +0000143/*
144 * ------------------------------------------------------
145 * Security check
146 * ------------------------------------------------------
admine334c472006-10-21 19:44:22 +0000147 *
adminb0dd10f2006-08-25 17:25:49 +0000148 * None of the functions in the app controller or the
admine334c472006-10-21 19:44:22 +0000149 * loader class can be called via the URI, nor can
adminb0dd10f2006-08-25 17:25:49 +0000150 * controller functions that begin with an underscore
151 */
152$class = $RTR->fetch_class();
153$method = $RTR->fetch_method();
154
adminf6edc532006-10-03 05:28:09 +0000155
adminb0dd10f2006-08-25 17:25:49 +0000156if ( ! class_exists($class)
157 OR $method == 'controller'
admine334c472006-10-21 19:44:22 +0000158 OR substr($method, 0, 1) == '_'
adminee54c112006-09-28 17:13:38 +0000159 OR in_array($method, get_class_methods('Controller'), TRUE)
adminb0dd10f2006-08-25 17:25:49 +0000160 )
161{
162 show_404();
163}
164
165/*
166 * ------------------------------------------------------
167 * Is there a "pre_controller" hook?
168 * ------------------------------------------------------
169 */
adminaf436d72006-09-15 20:02:14 +0000170$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000171
172/*
173 * ------------------------------------------------------
174 * Instantiate the controller and call requested method
175 * ------------------------------------------------------
176 */
adminf6edc532006-10-03 05:28:09 +0000177
178// Mark a start point so we can benchmark the controller
179$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
180
adminb3ab70b2006-10-07 03:07:29 +0000181// Instantiate the Controller
adminb0dd10f2006-08-25 17:25:49 +0000182$CI = new $class();
183
adminb3ab70b2006-10-07 03:07:29 +0000184// Is this a scaffolding request?
adminb0dd10f2006-08-25 17:25:49 +0000185if ($RTR->scaffolding_request === TRUE)
186{
adminaf436d72006-09-15 20:02:14 +0000187 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000188 {
adminb3ab70b2006-10-07 03:07:29 +0000189 $CI->_ci_scaffolding();
adminb0dd10f2006-08-25 17:25:49 +0000190 }
191}
192else
193{
admineb567c72006-09-06 02:48:47 +0000194 /*
195 * ------------------------------------------------------
196 * Is there a "post_controller_constructor" hook?
197 * ------------------------------------------------------
198 */
adminaf436d72006-09-15 20:02:14 +0000199 $EXT->_call_hook('post_controller_constructor');
adminb0dd10f2006-08-25 17:25:49 +0000200
adminb3ab70b2006-10-07 03:07:29 +0000201 // Is there a "remap" function?
admin1cf89aa2006-09-03 18:24:39 +0000202 if (method_exists($CI, '_remap'))
203 {
204 $CI->_remap($method);
205 }
206 else
207 {
208 if ( ! method_exists($CI, $method))
209 {
210 show_404();
211 }
admin8407cca2006-09-23 01:22:56 +0000212
admine334c472006-10-21 19:44:22 +0000213 // Call the requested method.
admin83b05a82006-09-25 21:06:46 +0000214 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000215 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000216 }
adminb0dd10f2006-08-25 17:25:49 +0000217}
218
adminf6edc532006-10-03 05:28:09 +0000219// Mark a benchmark end point
220$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
221
adminb0dd10f2006-08-25 17:25:49 +0000222/*
223 * ------------------------------------------------------
224 * Is there a "post_controller" hook?
225 * ------------------------------------------------------
226 */
adminaf436d72006-09-15 20:02:14 +0000227$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000228
229/*
230 * ------------------------------------------------------
231 * Send the final rendered output to the browser
232 * ------------------------------------------------------
233 */
admine334c472006-10-21 19:44:22 +0000234
adminaf436d72006-09-15 20:02:14 +0000235if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000236{
237 $OUT->_display();
238}
239
240/*
241 * ------------------------------------------------------
242 * Is there a "post_system" hook?
243 * ------------------------------------------------------
244 */
adminaf436d72006-09-15 20:02:14 +0000245$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000246
247/*
248 * ------------------------------------------------------
admin606f99c2006-10-11 23:48:41 +0000249 * Close the DB connection if one exists
adminb0dd10f2006-08-25 17:25:49 +0000250 * ------------------------------------------------------
251 */
admin5a14ea12006-10-12 20:42:55 +0000252if (class_exists('CI_DB') AND isset($CI->db))
adminb0dd10f2006-08-25 17:25:49 +0000253{
254 $CI->db->close();
255}
256
257
258?>