blob: 367d5eaac7a043bb8808fedfc64392fd130eef39 [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
admin1b90c272006-10-31 18:22:29 +000030// CI Version
31define('APPVER', '1.5.0.1');
adminb0dd10f2006-08-25 17:25:49 +000032
33/*
34 * ------------------------------------------------------
35 * Load the global functions
36 * ------------------------------------------------------
37 */
38require(BASEPATH.'codeigniter/Common'.EXT);
39
40/*
41 * ------------------------------------------------------
admin8f0a8f62006-10-07 01:17:25 +000042 * Define a custom error handler so we can log PHP errors
adminb0dd10f2006-08-25 17:25:49 +000043 * ------------------------------------------------------
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
admin7099a582006-10-10 17:47:59 +000054$BM =& load_class('Benchmark');
admine26611f2006-10-02 21:59:12 +000055$BM->mark('total_execution_time_start');
adminafe3aaa2006-10-20 22:22:55 +000056$BM->mark('loading_time_base_classes_start');
adminb0dd10f2006-08-25 17:25:49 +000057
58/*
59 * ------------------------------------------------------
adminafe3aaa2006-10-20 22:22:55 +000060 * Instantiate the hooks class
adminb0dd10f2006-08-25 17:25:49 +000061 * ------------------------------------------------------
62 */
63
admin7099a582006-10-10 17:47:59 +000064$EXT =& load_class('Hooks');
adminb0dd10f2006-08-25 17:25:49 +000065
66/*
67 * ------------------------------------------------------
68 * Is there a "pre_system" hook?
69 * ------------------------------------------------------
70 */
adminaf436d72006-09-15 20:02:14 +000071$EXT->_call_hook('pre_system');
adminb0dd10f2006-08-25 17:25:49 +000072
73/*
74 * ------------------------------------------------------
75 * Instantiate the base classes
76 * ------------------------------------------------------
77 */
78
admin7099a582006-10-10 17:47:59 +000079$CFG =& load_class('Config');
80$RTR =& load_class('Router');
81$OUT =& load_class('Output');
adminb0dd10f2006-08-25 17:25:49 +000082
83/*
84 * ------------------------------------------------------
85 * Is there a valid cache file? If so, we're done...
86 * ------------------------------------------------------
87 */
admine334c472006-10-21 19:44:22 +000088
adminaf436d72006-09-15 20:02:14 +000089if ($EXT->_call_hook('cache_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +000090{
admin06508c42006-09-18 08:18:08 +000091 if ($OUT->_display_cache($CFG, $RTR) == TRUE)
adminb0dd10f2006-08-25 17:25:49 +000092 {
93 exit;
94 }
95}
96
97/*
98 * ------------------------------------------------------
adminb0dd10f2006-08-25 17:25:49 +000099 * Load the remaining base classes
100 * ------------------------------------------------------
101 */
102
admin7099a582006-10-10 17:47:59 +0000103$IN =& load_class('Input');
104$URI =& load_class('URI');
105$LANG =& load_class('Language');
adminb0dd10f2006-08-25 17:25:49 +0000106
107/*
108 * ------------------------------------------------------
109 * Load the app controller and local controller
110 * ------------------------------------------------------
admine334c472006-10-21 19:44:22 +0000111 *
adminb0dd10f2006-08-25 17:25:49 +0000112 * Note: Due to the poor object handling in PHP 4 we'll
adminafe3aaa2006-10-20 22:22:55 +0000113 * conditionally load different versions of the base
adminb0dd10f2006-08-25 17:25:49 +0000114 * class. Retaining PHP 4 compatibility requires a bit of a hack.
115 *
116 * Note: The Loader class needs to be included first
admine334c472006-10-21 19:44:22 +0000117 *
adminb0dd10f2006-08-25 17:25:49 +0000118 */
adminb0dd10f2006-08-25 17:25:49 +0000119if (floor(phpversion()) < 5)
120{
admincef21062006-10-30 17:13:13 +0000121 load_class('Loader', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000122 require(BASEPATH.'codeigniter/Base4'.EXT);
123}
124else
125{
126 require(BASEPATH.'codeigniter/Base5'.EXT);
127}
128
adminb93464d2006-10-31 00:36:32 +0000129// Load the base controller class
admine334c472006-10-21 19:44:22 +0000130load_class('Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000131
adminb93464d2006-10-31 00:36:32 +0000132// 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}
adminb0dd10f2006-08-25 17:25:49 +0000139
admin8f0a8f62006-10-07 01:17:25 +0000140// Set a mark point for benchmarking
adminafe3aaa2006-10-20 22:22:55 +0000141$BM->mark('loading_time_base_classes_end');
adminf6edc532006-10-03 05:28:09 +0000142
143
adminb0dd10f2006-08-25 17:25:49 +0000144/*
145 * ------------------------------------------------------
146 * Security check
147 * ------------------------------------------------------
admine334c472006-10-21 19:44:22 +0000148 *
adminb0dd10f2006-08-25 17:25:49 +0000149 * None of the functions in the app controller or the
admine334c472006-10-21 19:44:22 +0000150 * loader class can be called via the URI, nor can
adminb0dd10f2006-08-25 17:25:49 +0000151 * controller functions that begin with an underscore
152 */
153$class = $RTR->fetch_class();
154$method = $RTR->fetch_method();
155
adminf6edc532006-10-03 05:28:09 +0000156
adminb0dd10f2006-08-25 17:25:49 +0000157if ( ! class_exists($class)
158 OR $method == 'controller'
admine334c472006-10-21 19:44:22 +0000159 OR substr($method, 0, 1) == '_'
adminee54c112006-09-28 17:13:38 +0000160 OR in_array($method, get_class_methods('Controller'), TRUE)
adminb0dd10f2006-08-25 17:25:49 +0000161 )
162{
163 show_404();
164}
165
166/*
167 * ------------------------------------------------------
168 * Is there a "pre_controller" hook?
169 * ------------------------------------------------------
170 */
adminaf436d72006-09-15 20:02:14 +0000171$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000172
173/*
174 * ------------------------------------------------------
175 * Instantiate the controller and call requested method
176 * ------------------------------------------------------
177 */
adminf6edc532006-10-03 05:28:09 +0000178
179// Mark a start point so we can benchmark the controller
180$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
181
adminb3ab70b2006-10-07 03:07:29 +0000182// Instantiate the Controller
adminb0dd10f2006-08-25 17:25:49 +0000183$CI = new $class();
184
adminb3ab70b2006-10-07 03:07:29 +0000185// Is this a scaffolding request?
adminb0dd10f2006-08-25 17:25:49 +0000186if ($RTR->scaffolding_request === TRUE)
187{
adminaf436d72006-09-15 20:02:14 +0000188 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000189 {
adminb3ab70b2006-10-07 03:07:29 +0000190 $CI->_ci_scaffolding();
adminb0dd10f2006-08-25 17:25:49 +0000191 }
192}
193else
194{
admineb567c72006-09-06 02:48:47 +0000195 /*
196 * ------------------------------------------------------
197 * Is there a "post_controller_constructor" hook?
198 * ------------------------------------------------------
199 */
adminaf436d72006-09-15 20:02:14 +0000200 $EXT->_call_hook('post_controller_constructor');
adminb0dd10f2006-08-25 17:25:49 +0000201
adminb3ab70b2006-10-07 03:07:29 +0000202 // Is there a "remap" function?
admin1cf89aa2006-09-03 18:24:39 +0000203 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 }
admin8407cca2006-09-23 01:22:56 +0000213
admine334c472006-10-21 19:44:22 +0000214 // Call the requested method.
admin83b05a82006-09-25 21:06:46 +0000215 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000216 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000217 }
adminb0dd10f2006-08-25 17:25:49 +0000218}
219
adminf6edc532006-10-03 05:28:09 +0000220// Mark a benchmark end point
221$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
222
adminb0dd10f2006-08-25 17:25:49 +0000223/*
224 * ------------------------------------------------------
225 * Is there a "post_controller" hook?
226 * ------------------------------------------------------
227 */
adminaf436d72006-09-15 20:02:14 +0000228$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000229
230/*
231 * ------------------------------------------------------
232 * Send the final rendered output to the browser
233 * ------------------------------------------------------
234 */
admine334c472006-10-21 19:44:22 +0000235
adminaf436d72006-09-15 20:02:14 +0000236if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000237{
238 $OUT->_display();
239}
240
241/*
242 * ------------------------------------------------------
243 * Is there a "post_system" hook?
244 * ------------------------------------------------------
245 */
adminaf436d72006-09-15 20:02:14 +0000246$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000247
248/*
249 * ------------------------------------------------------
admin606f99c2006-10-11 23:48:41 +0000250 * Close the DB connection if one exists
adminb0dd10f2006-08-25 17:25:49 +0000251 * ------------------------------------------------------
252 */
admin5a14ea12006-10-12 20:42:55 +0000253if (class_exists('CI_DB') AND isset($CI->db))
adminb0dd10f2006-08-25 17:25:49 +0000254{
255 $CI->db->close();
256}
257
258
259?>