PageRenderTime 56ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/system/codeigniter/CodeIgniter.php

https://github.com/ibnoe/Microweber
PHP | 280 lines | 91 code | 42 blank | 147 comment | 16 complexity | 0f65b86e8af303cb64b2a04eab31a48c 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) 2008 - 2009, 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.7.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. if ( ! is_php('5.3'))
  54. {
  55. @set_magic_quotes_runtime(0); // Kill magic quotes
  56. }
  57. /*
  58. * ------------------------------------------------------
  59. * Start the timer... tick tock tick tock...
  60. * ------------------------------------------------------
  61. */
  62. $BM = load_class('Benchmark');
  63. $BM->mark('total_execution_time_start');
  64. $BM->mark('loading_time_base_classes_start');
  65. /*
  66. * ------------------------------------------------------
  67. * Instantiate the hooks class
  68. * ------------------------------------------------------
  69. */
  70. $EXT = load_class('Hooks');
  71. /*
  72. * ------------------------------------------------------
  73. * Is there a "pre_system" hook?
  74. * ------------------------------------------------------
  75. */
  76. $EXT->_call_hook('pre_system');
  77. /*
  78. * ------------------------------------------------------
  79. * Instantiate the base classes
  80. * ------------------------------------------------------
  81. */
  82. $CFG = load_class('Config');
  83. $URI = load_class('URI');
  84. $RTR = load_class('Router');
  85. $OUT = load_class('Output');
  86. /*
  87. * ------------------------------------------------------
  88. * Is there a valid cache file? If so, we're done...
  89. * ------------------------------------------------------
  90. */
  91. if ($EXT->_call_hook('cache_override') === FALSE)
  92. {
  93. if ($OUT->_display_cache($CFG, $URI) == TRUE)
  94. {
  95. exit;
  96. }
  97. }
  98. /*
  99. * ------------------------------------------------------
  100. * Load the remaining base classes
  101. * ------------------------------------------------------
  102. */
  103. $IN = load_class('Input');
  104. $LANG = load_class('Language');
  105. /*
  106. * ------------------------------------------------------
  107. * Load the app controller and local controller
  108. * ------------------------------------------------------
  109. *
  110. * Note: Due to the poor object handling in PHP 4 we'll
  111. * conditionally load different versions of the base
  112. * class. Retaining PHP 4 compatibility requires a bit of a hack.
  113. *
  114. * Note: The Loader class needs to be included first
  115. *
  116. */
  117. if ( ! is_php('5.0.0'))
  118. {
  119. load_class('Loader', FALSE);
  120. require(BASEPATH.'codeigniter/Base4'.EXT);
  121. }
  122. else
  123. {
  124. require(BASEPATH.'codeigniter/Base5'.EXT);
  125. }
  126. // Load the base controller class
  127. load_class('Controller', FALSE);
  128. // Load the local application controller
  129. // Note: The Router class automatically validates the controller path. If this include fails it
  130. // means that the default controller in the Routes.php file is not resolving to something valid.
  131. if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
  132. {
  133. show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
  134. }
  135. include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
  136. // Set a mark point for benchmarking
  137. $BM->mark('loading_time_base_classes_end');
  138. /*
  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. if ( ! class_exists($class)
  150. OR $method == 'controller'
  151. OR strncmp($method, '_', 1) == 0
  152. OR in_array(strtolower($method), array_map('strtolower', get_class_methods('Controller')))
  153. )
  154. {
  155. show_404("{$class}/{$method}");
  156. }
  157. /*
  158. * ------------------------------------------------------
  159. * Is there a "pre_controller" hook?
  160. * ------------------------------------------------------
  161. */
  162. $EXT->_call_hook('pre_controller');
  163. /*
  164. * ------------------------------------------------------
  165. * Instantiate the controller and call requested method
  166. * ------------------------------------------------------
  167. */
  168. // Mark a start point so we can benchmark the controller
  169. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
  170. $CI = new $class();
  171. // Is this a scaffolding request?
  172. if ($RTR->scaffolding_request === TRUE)
  173. {
  174. if ($EXT->_call_hook('scaffolding_override') === FALSE)
  175. {
  176. $CI->_ci_scaffolding();
  177. }
  178. }
  179. else
  180. {
  181. /*
  182. * ------------------------------------------------------
  183. * Is there a "post_controller_constructor" hook?
  184. * ------------------------------------------------------
  185. */
  186. $EXT->_call_hook('post_controller_constructor');
  187. // Is there a "remap" function?
  188. if (method_exists($CI, '_remap'))
  189. {
  190. $CI->_remap($method);
  191. }
  192. else
  193. {
  194. // is_callable() returns TRUE on some versions of PHP 5 for private and protected
  195. // methods, so we'll use this workaround for consistent behavior
  196. if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
  197. {
  198. show_404("{$class}/{$method}");
  199. }
  200. // Call the requested method.
  201. // Any URI segments present (besides the class/function) will be passed to the method for convenience
  202. call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
  203. }
  204. }
  205. // Mark a benchmark end point
  206. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
  207. /*
  208. * ------------------------------------------------------
  209. * Is there a "post_controller" hook?
  210. * ------------------------------------------------------
  211. */
  212. $EXT->_call_hook('post_controller');
  213. /*
  214. * ------------------------------------------------------
  215. * Send the final rendered output to the browser
  216. * ------------------------------------------------------
  217. */
  218. if ($EXT->_call_hook('display_override') === FALSE)
  219. {
  220. $OUT->_display();
  221. }
  222. /*
  223. * ------------------------------------------------------
  224. * Is there a "post_system" hook?
  225. * ------------------------------------------------------
  226. */
  227. $EXT->_call_hook('post_system');
  228. /*
  229. * ------------------------------------------------------
  230. * Close the DB connection if one exists
  231. * ------------------------------------------------------
  232. */
  233. if (class_exists('CI_DB') AND isset($CI->db))
  234. {
  235. $CI->db->close();
  236. }
  237. /* End of file CodeIgniter.php */
  238. /* Location: ./system/codeigniter/CodeIgniter.php */