blob: 5b3f54ae365f00df9461fca1ba7ba16eb1f5df27 [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
admine334c472006-10-21 19:44:22 +0000128load_class('Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000129
admin45c872b2006-08-26 04:51:38 +0000130require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
adminb0dd10f2006-08-25 17:25:49 +0000131
admin8f0a8f62006-10-07 01:17:25 +0000132// Set a mark point for benchmarking
adminafe3aaa2006-10-20 22:22:55 +0000133$BM->mark('loading_time_base_classes_end');
adminf6edc532006-10-03 05:28:09 +0000134
135
adminb0dd10f2006-08-25 17:25:49 +0000136/*
137 * ------------------------------------------------------
138 * Security check
139 * ------------------------------------------------------
admine334c472006-10-21 19:44:22 +0000140 *
adminb0dd10f2006-08-25 17:25:49 +0000141 * None of the functions in the app controller or the
admine334c472006-10-21 19:44:22 +0000142 * loader class can be called via the URI, nor can
adminb0dd10f2006-08-25 17:25:49 +0000143 * controller functions that begin with an underscore
144 */
145$class = $RTR->fetch_class();
146$method = $RTR->fetch_method();
147
adminf6edc532006-10-03 05:28:09 +0000148
adminb0dd10f2006-08-25 17:25:49 +0000149if ( ! class_exists($class)
150 OR $method == 'controller'
admine334c472006-10-21 19:44:22 +0000151 OR substr($method, 0, 1) == '_'
adminee54c112006-09-28 17:13:38 +0000152 OR in_array($method, get_class_methods('Controller'), TRUE)
adminb0dd10f2006-08-25 17:25:49 +0000153 )
154{
155 show_404();
156}
157
158/*
159 * ------------------------------------------------------
160 * Is there a "pre_controller" hook?
161 * ------------------------------------------------------
162 */
adminaf436d72006-09-15 20:02:14 +0000163$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000164
165/*
166 * ------------------------------------------------------
167 * Instantiate the controller and call requested method
168 * ------------------------------------------------------
169 */
adminf6edc532006-10-03 05:28:09 +0000170
171// Mark a start point so we can benchmark the controller
172$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
173
adminb3ab70b2006-10-07 03:07:29 +0000174// Instantiate the Controller
adminb0dd10f2006-08-25 17:25:49 +0000175$CI = new $class();
176
adminb3ab70b2006-10-07 03:07:29 +0000177// Is this a scaffolding request?
adminb0dd10f2006-08-25 17:25:49 +0000178if ($RTR->scaffolding_request === TRUE)
179{
adminaf436d72006-09-15 20:02:14 +0000180 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000181 {
adminb3ab70b2006-10-07 03:07:29 +0000182 $CI->_ci_scaffolding();
adminb0dd10f2006-08-25 17:25:49 +0000183 }
184}
185else
186{
admineb567c72006-09-06 02:48:47 +0000187 /*
188 * ------------------------------------------------------
189 * Is there a "post_controller_constructor" hook?
190 * ------------------------------------------------------
191 */
adminaf436d72006-09-15 20:02:14 +0000192 $EXT->_call_hook('post_controller_constructor');
adminb0dd10f2006-08-25 17:25:49 +0000193
adminb3ab70b2006-10-07 03:07:29 +0000194 // Is there a "remap" function?
admin1cf89aa2006-09-03 18:24:39 +0000195 if (method_exists($CI, '_remap'))
196 {
197 $CI->_remap($method);
198 }
199 else
200 {
201 if ( ! method_exists($CI, $method))
202 {
203 show_404();
204 }
admin8407cca2006-09-23 01:22:56 +0000205
admine334c472006-10-21 19:44:22 +0000206 // Call the requested method.
admin83b05a82006-09-25 21:06:46 +0000207 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000208 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000209 }
adminb0dd10f2006-08-25 17:25:49 +0000210}
211
adminf6edc532006-10-03 05:28:09 +0000212// Mark a benchmark end point
213$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
214
adminb0dd10f2006-08-25 17:25:49 +0000215/*
216 * ------------------------------------------------------
217 * Is there a "post_controller" hook?
218 * ------------------------------------------------------
219 */
adminaf436d72006-09-15 20:02:14 +0000220$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000221
222/*
223 * ------------------------------------------------------
224 * Send the final rendered output to the browser
225 * ------------------------------------------------------
226 */
admine334c472006-10-21 19:44:22 +0000227
adminaf436d72006-09-15 20:02:14 +0000228if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000229{
230 $OUT->_display();
231}
232
233/*
234 * ------------------------------------------------------
235 * Is there a "post_system" hook?
236 * ------------------------------------------------------
237 */
adminaf436d72006-09-15 20:02:14 +0000238$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000239
240/*
241 * ------------------------------------------------------
admin606f99c2006-10-11 23:48:41 +0000242 * Close the DB connection if one exists
adminb0dd10f2006-08-25 17:25:49 +0000243 * ------------------------------------------------------
244 */
admin5a14ea12006-10-12 20:42:55 +0000245if (class_exists('CI_DB') AND isset($CI->db))
adminb0dd10f2006-08-25 17:25:49 +0000246{
247 $CI->db->close();
248}
249
250
251?>