CodeIgniter.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * System Front Controller
00020  *
00021  * Loads the base classes and executes the request.
00022  *
00023  * @package             CodeIgniter
00024  * @subpackage  codeigniter
00025  * @category    Front-controller
00026  * @author              ExpressionEngine Dev Team
00027  * @link                http://codeigniter.com/user_guide/
00028  */
00029 
00030 // CI Version
00031 define('CI_VERSION',    '1.6.3');
00032 
00033 /*
00034  * ------------------------------------------------------
00035  *  Load the global functions
00036  * ------------------------------------------------------
00037  */
00038 require(BASEPATH.'codeigniter/Common'.EXT);
00039 
00040 /*
00041  * ------------------------------------------------------
00042  *  Load the compatibility override functions
00043  * ------------------------------------------------------
00044  */
00045 require(BASEPATH.'codeigniter/Compat'.EXT);
00046 
00047 /*
00048  * ------------------------------------------------------
00049  *  Load the framework constants
00050  * ------------------------------------------------------
00051  */
00052 require(APPPATH.'config/constants'.EXT);
00053 
00054 /*
00055  * ------------------------------------------------------
00056  *  Define a custom error handler so we can log PHP errors
00057  * ------------------------------------------------------
00058  */
00059 set_error_handler('_exception_handler');
00060 set_magic_quotes_runtime(0); // Kill magic quotes
00061 
00062 /*
00063  * ------------------------------------------------------
00064  *  Start the timer... tick tock tick tock...
00065  * ------------------------------------------------------
00066  */
00067 
00068 $BM =& load_class('Benchmark');
00069 $BM->mark('total_execution_time_start');
00070 $BM->mark('loading_time_base_classes_start');
00071 
00072 /*
00073  * ------------------------------------------------------
00074  *  Instantiate the hooks class
00075  * ------------------------------------------------------
00076  */
00077 
00078 $EXT =& load_class('Hooks');
00079 
00080 /*
00081  * ------------------------------------------------------
00082  *  Is there a "pre_system" hook?
00083  * ------------------------------------------------------
00084  */
00085 $EXT->_call_hook('pre_system');
00086 
00087 /*
00088  * ------------------------------------------------------
00089  *  Instantiate the base classes
00090  * ------------------------------------------------------
00091  */
00092 
00093 $CFG =& load_class('Config');
00094 $URI =& load_class('URI');
00095 $RTR =& load_class('Router');
00096 $OUT =& load_class('Output');
00097 
00098 /*
00099  * ------------------------------------------------------
00100  *      Is there a valid cache file?  If so, we're done...
00101  * ------------------------------------------------------
00102  */
00103 
00104 if ($EXT->_call_hook('cache_override') === FALSE)
00105 {
00106         if ($OUT->_display_cache($CFG, $URI) == TRUE)
00107         {
00108                 exit;
00109         }
00110 }
00111 
00112 /*
00113  * ------------------------------------------------------
00114  *  Load the remaining base classes
00115  * ------------------------------------------------------
00116  */
00117 
00118 $IN             =& load_class('Input');
00119 $LANG   =& load_class('Language');
00120 
00121 /*
00122  * ------------------------------------------------------
00123  *  Load the app controller and local controller
00124  * ------------------------------------------------------
00125  *
00126  *  Note: Due to the poor object handling in PHP 4 we'll
00127  *  conditionally load different versions of the base
00128  *  class.  Retaining PHP 4 compatibility requires a bit of a hack.
00129  *
00130  *  Note: The Loader class needs to be included first
00131  *
00132  */
00133 if (floor(phpversion()) < 5)
00134 {
00135         load_class('Loader', FALSE);
00136         require(BASEPATH.'codeigniter/Base4'.EXT);
00137 }
00138 else
00139 {
00140         require(BASEPATH.'codeigniter/Base5'.EXT);
00141 }
00142 
00143 // Load the base controller class
00144 load_class('Controller', FALSE);
00145 
00146 // Load the local application controller
00147 // Note: The Router class automatically validates the controller path.  If this include fails it 
00148 // means that the default controller in the Routes.php file is not resolving to something valid.
00149 if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
00150 {
00151         show_error('Unable to load your default controller.  Please make sure the controller specified in your Routes.php file is valid.');
00152 }
00153 
00154 include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
00155 
00156 // Set a mark point for benchmarking
00157 $BM->mark('loading_time_base_classes_end');
00158 
00159 
00160 /*
00161  * ------------------------------------------------------
00162  *  Security check
00163  * ------------------------------------------------------
00164  *
00165  *  None of the functions in the app controller or the
00166  *  loader class can be called via the URI, nor can
00167  *  controller functions that begin with an underscore
00168  */
00169 $class  = $RTR->fetch_class();
00170 $method = $RTR->fetch_method();
00171 
00172 
00173 if ( ! class_exists($class)
00174         OR $method == 'controller'
00175         OR strncmp($method, '_', 1) == 0
00176         OR in_array($method, get_class_methods('Controller'), TRUE)
00177         )
00178 {
00179         show_404("{$class}/{$method}");
00180 }
00181 
00182 /*
00183  * ------------------------------------------------------
00184  *  Is there a "pre_controller" hook?
00185  * ------------------------------------------------------
00186  */
00187 $EXT->_call_hook('pre_controller');
00188 
00189 /*
00190  * ------------------------------------------------------
00191  *  Instantiate the controller and call requested method
00192  * ------------------------------------------------------
00193  */
00194 
00195 // Mark a start point so we can benchmark the controller
00196 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
00197 
00198 $CI = new $class();
00199 
00200 // Is this a scaffolding request?
00201 if ($RTR->scaffolding_request === TRUE)
00202 {
00203         if ($EXT->_call_hook('scaffolding_override') === FALSE)
00204         {
00205                 $CI->_ci_scaffolding();
00206         }
00207 }
00208 else
00209 {
00210         /*
00211          * ------------------------------------------------------
00212          *  Is there a "post_controller_constructor" hook?
00213          * ------------------------------------------------------
00214          */
00215         $EXT->_call_hook('post_controller_constructor');
00216         
00217         // Is there a "remap" function?
00218         if (method_exists($CI, '_remap'))
00219         {
00220                 $CI->_remap($method);
00221         }
00222         else
00223         {
00224                 // is_callable() returns TRUE on some versions of PHP 5 for private and protected
00225                 // methods, so we'll use this workaround for consistent behavior
00226                 if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
00227                 {
00228                         show_404("{$class}/{$method}");
00229                 }
00230 
00231                 // Call the requested method.
00232                 // Any URI segments present (besides the class/function) will be passed to the method for convenience
00233                 call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
00234         }
00235 }
00236 
00237 // Mark a benchmark end point
00238 $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
00239 
00240 /*
00241  * ------------------------------------------------------
00242  *  Is there a "post_controller" hook?
00243  * ------------------------------------------------------
00244  */
00245 $EXT->_call_hook('post_controller');
00246 
00247 /*
00248  * ------------------------------------------------------
00249  *  Send the final rendered output to the browser
00250  * ------------------------------------------------------
00251  */
00252 
00253 if ($EXT->_call_hook('display_override') === FALSE)
00254 {
00255         $OUT->_display();
00256 }
00257 
00258 /*
00259  * ------------------------------------------------------
00260  *  Is there a "post_system" hook?
00261  * ------------------------------------------------------
00262  */
00263 $EXT->_call_hook('post_system');
00264 
00265 /*
00266  * ------------------------------------------------------
00267  *  Close the DB connection if one exists
00268  * ------------------------------------------------------
00269  */
00270 if (class_exists('CI_DB') AND isset($CI->db))
00271 {
00272         $CI->db->close();
00273 }
00274 
00275 
00276 /* End of file CodeIgniter.php */
00277 /* Location: ./system/codeigniter/CodeIgniter.php */