Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
| 2 | /**
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 3 | * CodeIgniter
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 4 | *
|
| 5 | * An open source application development framework for PHP 4.3.2 or newer
|
| 6 | *
|
| 7 | * @package CodeIgniter
|
| 8 | * @author Rick Ellis
|
Derek Allard | d2df9bc | 2007-04-15 17:41:17 +0000 | [diff] [blame] | 9 | * @copyright Copyright (c) 2006, EllisLab, Inc.
|
Derek Allard | 6838f00 | 2007-10-04 19:29:59 +0000 | [diff] [blame^] | 10 | * @license http://www.codeigniter.com/user_guide/license.html
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 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 |
|
| 30 | // CI Version
|
Derek Allard | 60ca9b7 | 2007-07-12 19:53:27 +0000 | [diff] [blame] | 31 | define('CI_VERSION', '1.5.4');
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 32 |
|
| 33 | /*
|
| 34 | * ------------------------------------------------------
|
| 35 | * Load the global functions
|
| 36 | * ------------------------------------------------------
|
| 37 | */
|
| 38 | require(BASEPATH.'codeigniter/Common'.EXT);
|
| 39 |
|
| 40 | /*
|
| 41 | * ------------------------------------------------------
|
| 42 | * Define a custom error handler so we can log PHP errors
|
| 43 | * ------------------------------------------------------
|
| 44 | */
|
| 45 | set_error_handler('_exception_handler');
|
| 46 | set_magic_quotes_runtime(0); // Kill magic quotes
|
| 47 |
|
| 48 | /*
|
| 49 | * ------------------------------------------------------
|
| 50 | * Start the timer... tick tock tick tock...
|
| 51 | * ------------------------------------------------------
|
| 52 | */
|
| 53 |
|
| 54 | $BM =& load_class('Benchmark');
|
| 55 | $BM->mark('total_execution_time_start');
|
| 56 | $BM->mark('loading_time_base_classes_start');
|
| 57 |
|
| 58 | /*
|
| 59 | * ------------------------------------------------------
|
| 60 | * Instantiate the hooks class
|
| 61 | * ------------------------------------------------------
|
| 62 | */
|
| 63 |
|
| 64 | $EXT =& load_class('Hooks');
|
| 65 |
|
| 66 | /*
|
| 67 | * ------------------------------------------------------
|
| 68 | * Is there a "pre_system" hook?
|
| 69 | * ------------------------------------------------------
|
| 70 | */
|
| 71 | $EXT->_call_hook('pre_system');
|
| 72 |
|
| 73 | /*
|
| 74 | * ------------------------------------------------------
|
| 75 | * Instantiate the base classes
|
| 76 | * ------------------------------------------------------
|
| 77 | */
|
| 78 |
|
| 79 | $CFG =& load_class('Config');
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 80 | $URI =& load_class('URI');
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 81 | $RTR =& load_class('Router');
|
| 82 | $OUT =& load_class('Output');
|
| 83 |
|
| 84 | /*
|
| 85 | * ------------------------------------------------------
|
| 86 | * Is there a valid cache file? If so, we're done...
|
| 87 | * ------------------------------------------------------
|
| 88 | */
|
| 89 |
|
| 90 | if ($EXT->_call_hook('cache_override') === FALSE)
|
| 91 | {
|
| 92 | if ($OUT->_display_cache($CFG, $RTR) == TRUE)
|
| 93 | {
|
| 94 | exit;
|
| 95 | }
|
| 96 | }
|
| 97 |
|
| 98 | /*
|
| 99 | * ------------------------------------------------------
|
| 100 | * Load the remaining base classes
|
| 101 | * ------------------------------------------------------
|
| 102 | */
|
| 103 |
|
| 104 | $IN =& load_class('Input');
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 105 | $LANG =& load_class('Language');
|
| 106 |
|
| 107 | /*
|
| 108 | * ------------------------------------------------------
|
| 109 | * Load the app controller and local controller
|
| 110 | * ------------------------------------------------------
|
| 111 | *
|
| 112 | * Note: Due to the poor object handling in PHP 4 we'll
|
| 113 | * conditionally load different versions of the base
|
| 114 | * class. Retaining PHP 4 compatibility requires a bit of a hack.
|
| 115 | *
|
| 116 | * Note: The Loader class needs to be included first
|
| 117 | *
|
| 118 | */
|
| 119 | if (floor(phpversion()) < 5)
|
| 120 | {
|
| 121 | load_class('Loader', FALSE);
|
| 122 | require(BASEPATH.'codeigniter/Base4'.EXT);
|
| 123 | }
|
| 124 | else
|
| 125 | {
|
| 126 | require(BASEPATH.'codeigniter/Base5'.EXT);
|
| 127 | }
|
| 128 |
|
| 129 | // Load the base controller class
|
| 130 | load_class('Controller', FALSE);
|
| 131 |
|
| 132 | // 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.
|
Rick Ellis | 6a47c11 | 2007-07-21 17:42:35 +0000 | [diff] [blame] | 135 | if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 136 | {
|
| 137 | show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
|
| 138 | }
|
| 139 |
|
Rick Ellis | 6a47c11 | 2007-07-21 17:42:35 +0000 | [diff] [blame] | 140 | include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
|
| 141 |
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 142 | // Set a mark point for benchmarking
|
| 143 | $BM->mark('loading_time_base_classes_end');
|
| 144 |
|
| 145 |
|
| 146 | /*
|
| 147 | * ------------------------------------------------------
|
| 148 | * Security check
|
| 149 | * ------------------------------------------------------
|
| 150 | *
|
| 151 | * None of the functions in the app controller or the
|
| 152 | * loader class can be called via the URI, nor can
|
| 153 | * controller functions that begin with an underscore
|
| 154 | */
|
| 155 | $class = $RTR->fetch_class();
|
| 156 | $method = $RTR->fetch_method();
|
| 157 |
|
| 158 |
|
| 159 | if ( ! class_exists($class)
|
| 160 | OR $method == 'controller'
|
| 161 | OR substr($method, 0, 1) == '_'
|
| 162 | OR in_array($method, get_class_methods('Controller'), TRUE)
|
| 163 | )
|
| 164 | {
|
| 165 | show_404();
|
| 166 | }
|
| 167 |
|
| 168 | /*
|
| 169 | * ------------------------------------------------------
|
| 170 | * Is there a "pre_controller" hook?
|
| 171 | * ------------------------------------------------------
|
| 172 | */
|
| 173 | $EXT->_call_hook('pre_controller');
|
| 174 |
|
| 175 | /*
|
| 176 | * ------------------------------------------------------
|
| 177 | * Instantiate the controller and call requested method
|
| 178 | * ------------------------------------------------------
|
| 179 | */
|
| 180 |
|
| 181 | // Mark a start point so we can benchmark the controller
|
| 182 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
|
| 183 |
|
Rick Ellis | e0a4cc0 | 2007-07-22 18:14:32 +0000 | [diff] [blame] | 184 | // Instantiate the Controller and pass any global data that might exist
|
Rick Ellis | f66c71b | 2007-07-22 18:22:56 +0000 | [diff] [blame] | 185 | $assign_to_controller = ( ! isset($assign_to_controller)) ? NULL : $assign_to_controller;
|
Rick Ellis | e0a4cc0 | 2007-07-22 18:14:32 +0000 | [diff] [blame] | 186 |
|
Rick Ellis | f66c71b | 2007-07-22 18:22:56 +0000 | [diff] [blame] | 187 | $CI = new $class($assign_to_controller);
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 188 |
|
Rick Ellis | d8de26e | 2007-07-22 18:24:25 +0000 | [diff] [blame] | 189 | unset($assign_to_controller);
|
| 190 |
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 191 | // Is this a scaffolding request?
|
| 192 | if ($RTR->scaffolding_request === TRUE)
|
| 193 | {
|
| 194 | if ($EXT->_call_hook('scaffolding_override') === FALSE)
|
| 195 | {
|
| 196 | $CI->_ci_scaffolding();
|
| 197 | }
|
| 198 | }
|
| 199 | else
|
| 200 | {
|
| 201 | /*
|
| 202 | * ------------------------------------------------------
|
| 203 | * Is there a "post_controller_constructor" hook?
|
| 204 | * ------------------------------------------------------
|
| 205 | */
|
| 206 | $EXT->_call_hook('post_controller_constructor');
|
| 207 |
|
| 208 | // Is there a "remap" function?
|
| 209 | if (method_exists($CI, '_remap'))
|
| 210 | {
|
| 211 | $CI->_remap($method);
|
| 212 | }
|
| 213 | else
|
| 214 | {
|
| 215 | if ( ! method_exists($CI, $method))
|
| 216 | {
|
| 217 | show_404();
|
| 218 | }
|
| 219 |
|
| 220 | // Call the requested method.
|
| 221 | // Any URI segments present (besides the class/function) will be passed to the method for convenience
|
Rick Ellis | 30b4015 | 2007-07-20 00:01:13 +0000 | [diff] [blame] | 222 | call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, (($RTR->fetch_directory() == '') ? 2 : 3)));
|
Derek Allard | 320f3df | 2007-02-06 04:06:08 +0000 | [diff] [blame] | 223 | }
|
| 224 | }
|
| 225 |
|
| 226 | // Mark a benchmark end point
|
| 227 | $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
|
| 228 |
|
| 229 | /*
|
| 230 | * ------------------------------------------------------
|
| 231 | * Is there a "post_controller" hook?
|
| 232 | * ------------------------------------------------------
|
| 233 | */
|
| 234 | $EXT->_call_hook('post_controller');
|
| 235 |
|
| 236 | /*
|
| 237 | * ------------------------------------------------------
|
| 238 | * Send the final rendered output to the browser
|
| 239 | * ------------------------------------------------------
|
| 240 | */
|
| 241 |
|
| 242 | if ($EXT->_call_hook('display_override') === FALSE)
|
| 243 | {
|
| 244 | $OUT->_display();
|
| 245 | }
|
| 246 |
|
| 247 | /*
|
| 248 | * ------------------------------------------------------
|
| 249 | * Is there a "post_system" hook?
|
| 250 | * ------------------------------------------------------
|
| 251 | */
|
| 252 | $EXT->_call_hook('post_system');
|
| 253 |
|
| 254 | /*
|
| 255 | * ------------------------------------------------------
|
| 256 | * Close the DB connection if one exists
|
| 257 | * ------------------------------------------------------
|
| 258 | */
|
| 259 | if (class_exists('CI_DB') AND isset($CI->db))
|
| 260 | {
|
| 261 | $CI->db->close();
|
| 262 | }
|
| 263 |
|
| 264 |
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 265 | ?> |