PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/codeigniter/CodeIgniter.php

https://github.com/marcoliverteschke/redesign.marcoliverteschke.de
PHP | 277 lines | 88 code | 42 blank | 147 comment | 15 complexity | b8f89b893c70cd2619ab80b54b0f1f36 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2006, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * System Front Controller
  18. *
  19. * Loads the base classes and executes the request.
  20. *
  21. * @package CodeIgniter
  22. * @subpackage codeigniter
  23. * @category Front-controller
  24. * @author ExpressionEngine Dev Team
  25. * @link http://codeigniter.com/user_guide/
  26. */
  27. // CI Version
  28. define('CI_VERSION', '1.6.2');
  29. /*
  30. * ------------------------------------------------------
  31. * Load the global functions
  32. * ------------------------------------------------------
  33. */
  34. require(BASEPATH.'codeigniter/Common'.EXT);
  35. /*
  36. * ------------------------------------------------------
  37. * Load the compatibility override functions
  38. * ------------------------------------------------------
  39. */
  40. require(BASEPATH.'codeigniter/Compat'.EXT);
  41. /*
  42. * ------------------------------------------------------
  43. * Load the framework constants
  44. * ------------------------------------------------------
  45. */
  46. require(APPPATH.'config/constants'.EXT);
  47. /*
  48. * ------------------------------------------------------
  49. * Define a custom error handler so we can log PHP errors
  50. * ------------------------------------------------------
  51. */
  52. set_error_handler('_exception_handler');
  53. set_magic_quotes_runtime(0); // Kill magic quotes
  54. /*
  55. * ------------------------------------------------------
  56. * Start the timer... tick tock tick tock...
  57. * ------------------------------------------------------
  58. */
  59. $BM =& load_class('Benchmark');
  60. $BM->mark('total_execution_time_start');
  61. $BM->mark('loading_time_base_classes_start');
  62. /*
  63. * ------------------------------------------------------
  64. * Instantiate the hooks class
  65. * ------------------------------------------------------
  66. */
  67. $EXT =& load_class('Hooks');
  68. /*
  69. * ------------------------------------------------------
  70. * Is there a "pre_system" hook?
  71. * ------------------------------------------------------
  72. */
  73. $EXT->_call_hook('pre_system');
  74. /*
  75. * ------------------------------------------------------
  76. * Instantiate the base classes
  77. * ------------------------------------------------------
  78. */
  79. $CFG =& load_class('Config');
  80. $URI =& load_class('URI');
  81. $RTR =& load_class('Router');
  82. $OUT =& load_class('Output');
  83. /*
  84. * ------------------------------------------------------
  85. * Is there a valid cache file? If so, we're done...
  86. * ------------------------------------------------------
  87. */
  88. if ($EXT->_call_hook('cache_override') === FALSE)
  89. {
  90. if ($OUT->_display_cache($CFG, $RTR) == TRUE)
  91. {
  92. exit;
  93. }
  94. }
  95. /*
  96. * ------------------------------------------------------
  97. * Load the remaining base classes
  98. * ------------------------------------------------------
  99. */
  100. $IN =& load_class('Input');
  101. $LANG =& load_class('Language');
  102. /*
  103. * ------------------------------------------------------
  104. * Load the app controller and local controller
  105. * ------------------------------------------------------
  106. *
  107. * Note: Due to the poor object handling in PHP 4 we'll
  108. * conditionally load different versions of the base
  109. * class. Retaining PHP 4 compatibility requires a bit of a hack.
  110. *
  111. * Note: The Loader class needs to be included first
  112. *
  113. */
  114. if (floor(phpversion()) < 5)
  115. {
  116. load_class('Loader', FALSE);
  117. require(BASEPATH.'codeigniter/Base4'.EXT);
  118. }
  119. else
  120. {
  121. require(BASEPATH.'codeigniter/Base5'.EXT);
  122. }
  123. // Load the base controller class
  124. load_class('Controller', FALSE);
  125. // Load the local application controller
  126. // Note: The Router class automatically validates the controller path. If this include fails it
  127. // means that the default controller in the Routes.php file is not resolving to something valid.
  128. if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
  129. {
  130. show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
  131. }
  132. include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
  133. // Set a mark point for benchmarking
  134. $BM->mark('loading_time_base_classes_end');
  135. /*
  136. * ------------------------------------------------------
  137. * Security check
  138. * ------------------------------------------------------
  139. *
  140. * None of the functions in the app controller or the
  141. * loader class can be called via the URI, nor can
  142. * controller functions that begin with an underscore
  143. */
  144. $class = $RTR->fetch_class();
  145. $method = $RTR->fetch_method();
  146. if ( ! class_exists($class)
  147. OR $method == 'controller'
  148. OR strncmp($method, '_', 1) == 0
  149. OR in_array($method, get_class_methods('Controller'), TRUE)
  150. )
  151. {
  152. show_404("{$class}/{$method}");
  153. }
  154. /*
  155. * ------------------------------------------------------
  156. * Is there a "pre_controller" hook?
  157. * ------------------------------------------------------
  158. */
  159. $EXT->_call_hook('pre_controller');
  160. /*
  161. * ------------------------------------------------------
  162. * Instantiate the controller and call requested method
  163. * ------------------------------------------------------
  164. */
  165. // Mark a start point so we can benchmark the controller
  166. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
  167. $CI = new $class();
  168. // Is this a scaffolding request?
  169. if ($RTR->scaffolding_request === TRUE)
  170. {
  171. if ($EXT->_call_hook('scaffolding_override') === FALSE)
  172. {
  173. $CI->_ci_scaffolding();
  174. }
  175. }
  176. else
  177. {
  178. /*
  179. * ------------------------------------------------------
  180. * Is there a "post_controller_constructor" hook?
  181. * ------------------------------------------------------
  182. */
  183. $EXT->_call_hook('post_controller_constructor');
  184. // Is there a "remap" function?
  185. if (method_exists($CI, '_remap'))
  186. {
  187. $CI->_remap($method);
  188. }
  189. else
  190. {
  191. // is_callable() returns TRUE on some versions of PHP 5 for private and protected
  192. // methods, so we'll use this workaround for consistent behavior
  193. if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
  194. {
  195. show_404("{$class}/{$method}");
  196. }
  197. // Call the requested method.
  198. // Any URI segments present (besides the class/function) will be passed to the method for convenience
  199. call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
  200. }
  201. }
  202. // Mark a benchmark end point
  203. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
  204. /*
  205. * ------------------------------------------------------
  206. * Is there a "post_controller" hook?
  207. * ------------------------------------------------------
  208. */
  209. $EXT->_call_hook('post_controller');
  210. /*
  211. * ------------------------------------------------------
  212. * Send the final rendered output to the browser
  213. * ------------------------------------------------------
  214. */
  215. if ($EXT->_call_hook('display_override') === FALSE)
  216. {
  217. $OUT->_display();
  218. }
  219. /*
  220. * ------------------------------------------------------
  221. * Is there a "post_system" hook?
  222. * ------------------------------------------------------
  223. */
  224. $EXT->_call_hook('post_system');
  225. /*
  226. * ------------------------------------------------------
  227. * Close the DB connection if one exists
  228. * ------------------------------------------------------
  229. */
  230. if (class_exists('CI_DB') AND isset($CI->db))
  231. {
  232. $CI->db->close();
  233. }
  234. /* End of file CodeIgniter.php */
  235. /* Location: ./system/codeigniter/CodeIgniter.php */