blob: 65ca354385d8adcb4b993465bb4ee10b3a258192 [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.
10 * @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
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 * ------------------------------------------------------
41 * Define a custom error handler so we can log errors
42 * ------------------------------------------------------
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
admin33de9a12006-09-28 06:50:16 +000053$BM =& _load_class('Benchmark');
admine26611f2006-10-02 21:59:12 +000054$BM->mark('total_execution_time_start');
adminf6edc532006-10-03 05:28:09 +000055$BM->mark('loading_time_base_clases_start');
adminb0dd10f2006-08-25 17:25:49 +000056
57/*
58 * ------------------------------------------------------
59 * Instantiate the hooks classe
60 * ------------------------------------------------------
61 */
62
admin33de9a12006-09-28 06:50:16 +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
admin33de9a12006-09-28 06:50:16 +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 */
87
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
admin33de9a12006-09-28 06:50:16 +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 * ------------------------------------------------------
110 *
111 * Note: Due to the poor object handling in PHP 4 we'll
112 * contditionally load different versions of the base
113 * class. Retaining PHP 4 compatibility requires a bit of a hack.
114 *
115 * Note: The Loader class needs to be included first
116 *
117 */
118
admin33de9a12006-09-28 06:50:16 +0000119_load_class('Loader', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000120
121if (floor(phpversion()) < 5)
122{
123 require(BASEPATH.'codeigniter/Base4'.EXT);
124}
125else
126{
127 require(BASEPATH.'codeigniter/Base5'.EXT);
128}
129
admin33de9a12006-09-28 06:50:16 +0000130_load_class('Controller', FALSE);
adminb0dd10f2006-08-25 17:25:49 +0000131
admin45c872b2006-08-26 04:51:38 +0000132require(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
adminb0dd10f2006-08-25 17:25:49 +0000133
adminf6edc532006-10-03 05:28:09 +0000134$BM->mark('loading_time_base_clases_end');
135
136
adminb0dd10f2006-08-25 17:25:49 +0000137/*
138 * ------------------------------------------------------
139 * Security check
140 * ------------------------------------------------------
141 *
142 * None of the functions in the app controller or the
143 * loader class can be called via the URI, nor can
144 * controller functions that begin with an underscore
145 */
146$class = $RTR->fetch_class();
147$method = $RTR->fetch_method();
148
adminf6edc532006-10-03 05:28:09 +0000149
adminb0dd10f2006-08-25 17:25:49 +0000150if ( ! class_exists($class)
151 OR $method == 'controller'
152 OR substr($method, 0, 1) == '_'
adminee54c112006-09-28 17:13:38 +0000153 OR in_array($method, get_class_methods('Controller'), TRUE)
adminb0dd10f2006-08-25 17:25:49 +0000154 )
155{
156 show_404();
157}
158
159/*
160 * ------------------------------------------------------
161 * Is there a "pre_controller" hook?
162 * ------------------------------------------------------
163 */
adminaf436d72006-09-15 20:02:14 +0000164$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000165
166/*
167 * ------------------------------------------------------
168 * Instantiate the controller and call requested method
169 * ------------------------------------------------------
170 */
adminf6edc532006-10-03 05:28:09 +0000171
172// Mark a start point so we can benchmark the controller
173$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
174
adminb0dd10f2006-08-25 17:25:49 +0000175$CI = new $class();
176
177if ($RTR->scaffolding_request === TRUE)
178{
adminaf436d72006-09-15 20:02:14 +0000179 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000180 {
181 $CI->_ci_scaffolding();
182 }
183}
184else
185{
admineb567c72006-09-06 02:48:47 +0000186 /*
187 * ------------------------------------------------------
188 * Is there a "post_controller_constructor" hook?
189 * ------------------------------------------------------
190 */
adminaf436d72006-09-15 20:02:14 +0000191 $EXT->_call_hook('post_controller_constructor');
adminb0dd10f2006-08-25 17:25:49 +0000192
admin1cf89aa2006-09-03 18:24:39 +0000193 if (method_exists($CI, '_remap'))
194 {
195 $CI->_remap($method);
196 }
197 else
198 {
199 if ( ! method_exists($CI, $method))
200 {
201 show_404();
202 }
admin8407cca2006-09-23 01:22:56 +0000203
admin83b05a82006-09-25 21:06:46 +0000204 // Call the requested method.
205 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000206 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000207 }
adminb0dd10f2006-08-25 17:25:49 +0000208}
209
adminf6edc532006-10-03 05:28:09 +0000210// Mark a benchmark end point
211$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
212
adminb0dd10f2006-08-25 17:25:49 +0000213/*
214 * ------------------------------------------------------
215 * Is there a "post_controller" hook?
216 * ------------------------------------------------------
217 */
adminaf436d72006-09-15 20:02:14 +0000218$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000219
220/*
221 * ------------------------------------------------------
222 * Send the final rendered output to the browser
223 * ------------------------------------------------------
224 */
225
adminaf436d72006-09-15 20:02:14 +0000226if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000227{
228 $OUT->_display();
229}
230
231/*
232 * ------------------------------------------------------
233 * Is there a "post_system" hook?
234 * ------------------------------------------------------
235 */
adminaf436d72006-09-15 20:02:14 +0000236$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000237
238/*
239 * ------------------------------------------------------
240 * Close the DB connection of one exists
241 * ------------------------------------------------------
242 */
243if ($CI->_ci_is_loaded('db'))
244{
245 $CI->db->close();
246}
247
248
249?>