blob: 611b1a621fb4150472dd85a380e9d5d6ef1841fc [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 * ------------------------------------------------------
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');
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
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 */
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
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 * ------------------------------------------------------
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
admin7099a582006-10-10 17:47:59 +0000119load_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
admin7099a582006-10-10 17:47:59 +0000130load_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
admin8f0a8f62006-10-07 01:17:25 +0000134// Set a mark point for benchmarking
adminf6edc532006-10-03 05:28:09 +0000135$BM->mark('loading_time_base_clases_end');
136
137
adminb0dd10f2006-08-25 17:25:49 +0000138/*
139 * ------------------------------------------------------
140 * Security check
141 * ------------------------------------------------------
142 *
143 * None of the functions in the app controller or the
144 * loader class can be called via the URI, nor can
145 * controller functions that begin with an underscore
146 */
147$class = $RTR->fetch_class();
148$method = $RTR->fetch_method();
149
adminf6edc532006-10-03 05:28:09 +0000150
adminb0dd10f2006-08-25 17:25:49 +0000151if ( ! class_exists($class)
152 OR $method == 'controller'
153 OR substr($method, 0, 1) == '_'
adminee54c112006-09-28 17:13:38 +0000154 OR in_array($method, get_class_methods('Controller'), TRUE)
adminb0dd10f2006-08-25 17:25:49 +0000155 )
156{
157 show_404();
158}
159
160/*
161 * ------------------------------------------------------
162 * Is there a "pre_controller" hook?
163 * ------------------------------------------------------
164 */
adminaf436d72006-09-15 20:02:14 +0000165$EXT->_call_hook('pre_controller');
adminb0dd10f2006-08-25 17:25:49 +0000166
167/*
168 * ------------------------------------------------------
169 * Instantiate the controller and call requested method
170 * ------------------------------------------------------
171 */
adminf6edc532006-10-03 05:28:09 +0000172
173// Mark a start point so we can benchmark the controller
174$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
175
adminb3ab70b2006-10-07 03:07:29 +0000176// Instantiate the Controller
adminb0dd10f2006-08-25 17:25:49 +0000177$CI = new $class();
178
adminb3ab70b2006-10-07 03:07:29 +0000179// Is this a scaffolding request?
adminb0dd10f2006-08-25 17:25:49 +0000180if ($RTR->scaffolding_request === TRUE)
181{
adminaf436d72006-09-15 20:02:14 +0000182 if ($EXT->_call_hook('scaffolding_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000183 {
adminb3ab70b2006-10-07 03:07:29 +0000184 $CI->_ci_scaffolding();
adminb0dd10f2006-08-25 17:25:49 +0000185 }
186}
187else
188{
admineb567c72006-09-06 02:48:47 +0000189 /*
190 * ------------------------------------------------------
191 * Is there a "post_controller_constructor" hook?
192 * ------------------------------------------------------
193 */
adminaf436d72006-09-15 20:02:14 +0000194 $EXT->_call_hook('post_controller_constructor');
adminb0dd10f2006-08-25 17:25:49 +0000195
adminb3ab70b2006-10-07 03:07:29 +0000196 // Is there a "remap" function?
admin1cf89aa2006-09-03 18:24:39 +0000197 if (method_exists($CI, '_remap'))
198 {
199 $CI->_remap($method);
200 }
201 else
202 {
203 if ( ! method_exists($CI, $method))
204 {
205 show_404();
206 }
admin8407cca2006-09-23 01:22:56 +0000207
admin83b05a82006-09-25 21:06:46 +0000208 // Call the requested method.
209 // Any URI segments present (besides the class/function) will be passed to the method for convenience
admin7d852882006-09-24 01:33:56 +0000210 call_user_func_array(array(&$CI, $method), array_slice($RTR->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
admin1cf89aa2006-09-03 18:24:39 +0000211 }
adminb0dd10f2006-08-25 17:25:49 +0000212}
213
adminf6edc532006-10-03 05:28:09 +0000214// Mark a benchmark end point
215$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
216
adminb0dd10f2006-08-25 17:25:49 +0000217/*
218 * ------------------------------------------------------
219 * Is there a "post_controller" hook?
220 * ------------------------------------------------------
221 */
adminaf436d72006-09-15 20:02:14 +0000222$EXT->_call_hook('post_controller');
adminb0dd10f2006-08-25 17:25:49 +0000223
224/*
225 * ------------------------------------------------------
226 * Send the final rendered output to the browser
227 * ------------------------------------------------------
228 */
229
adminaf436d72006-09-15 20:02:14 +0000230if ($EXT->_call_hook('display_override') === FALSE)
adminb0dd10f2006-08-25 17:25:49 +0000231{
232 $OUT->_display();
233}
234
235/*
236 * ------------------------------------------------------
237 * Is there a "post_system" hook?
238 * ------------------------------------------------------
239 */
adminaf436d72006-09-15 20:02:14 +0000240$EXT->_call_hook('post_system');
adminb0dd10f2006-08-25 17:25:49 +0000241
242/*
243 * ------------------------------------------------------
244 * Close the DB connection of one exists
245 * ------------------------------------------------------
246 */
admin8f0a8f62006-10-07 01:17:25 +0000247if (class_exists('CI_DB'))
adminb0dd10f2006-08-25 17:25:49 +0000248{
249 $CI->db->close();
250}
251
252
253?>