PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/system/core/CodeIgniter.php

https://bitbucket.org/rzavaleta/rm-iluminacion
PHP | 382 lines | 124 code | 49 blank | 209 comment | 24 complexity | 372c5ac3bf7853aaa4852295ca05a190 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 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, 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 Initialization File
  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. /*
  28. * ------------------------------------------------------
  29. * Define the CodeIgniter Version
  30. * ------------------------------------------------------
  31. */
  32. define('CI_VERSION', '2.0.2');
  33. /*
  34. * ------------------------------------------------------
  35. * Define the CodeIgniter Branch (Core = TRUE, Reactor = FALSE)
  36. * ------------------------------------------------------
  37. */
  38. define('CI_CORE', FALSE);
  39. /*
  40. * ------------------------------------------------------
  41. * Load the global functions
  42. * ------------------------------------------------------
  43. */
  44. require(BASEPATH.'core/Common'.EXT);
  45. /*
  46. * ------------------------------------------------------
  47. * Load the framework constants
  48. * ------------------------------------------------------
  49. */
  50. if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT))
  51. {
  52. require(APPPATH.'config/'.ENVIRONMENT.'/constants'.EXT);
  53. }
  54. else
  55. {
  56. require(APPPATH.'config/constants'.EXT);
  57. }
  58. /*
  59. * ------------------------------------------------------
  60. * Define a custom error handler so we can log PHP errors
  61. * ------------------------------------------------------
  62. */
  63. set_error_handler('_exception_handler');
  64. if ( ! is_php('5.3'))
  65. {
  66. @set_magic_quotes_runtime(0); // Kill magic quotes
  67. }
  68. /*
  69. * ------------------------------------------------------
  70. * Set the subclass_prefix
  71. * ------------------------------------------------------
  72. *
  73. * Normally the "subclass_prefix" is set in the config file.
  74. * The subclass prefix allows CI to know if a core class is
  75. * being extended via a library in the local application
  76. * "libraries" folder. Since CI allows config items to be
  77. * overriden via data set in the main index. php file,
  78. * before proceeding we need to know if a subclass_prefix
  79. * override exists. If so, we will set this value now,
  80. * before any classes are loaded
  81. * Note: Since the config file data is cached it doesn't
  82. * hurt to load it here.
  83. */
  84. if (isset($assign_to_config['subclass_prefix']) AND $assign_to_config['subclass_prefix'] != '')
  85. {
  86. get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
  87. }
  88. /*
  89. * ------------------------------------------------------
  90. * Set a liberal script execution time limit
  91. * ------------------------------------------------------
  92. */
  93. if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
  94. {
  95. @set_time_limit(300);
  96. }
  97. /*
  98. * ------------------------------------------------------
  99. * Start the timer... tick tock tick tock...
  100. * ------------------------------------------------------
  101. */
  102. $BM =& load_class('Benchmark', 'core');
  103. $BM->mark('total_execution_time_start');
  104. $BM->mark('loading_time:_base_classes_start');
  105. /*
  106. * ------------------------------------------------------
  107. * Instantiate the hooks class
  108. * ------------------------------------------------------
  109. */
  110. $EXT =& load_class('Hooks', 'core');
  111. /*
  112. * ------------------------------------------------------
  113. * Is there a "pre_system" hook?
  114. * ------------------------------------------------------
  115. */
  116. $EXT->_call_hook('pre_system');
  117. /*
  118. * ------------------------------------------------------
  119. * Instantiate the config class
  120. * ------------------------------------------------------
  121. */
  122. $CFG =& load_class('Config', 'core');
  123. // Do we have any manually set config items in the index.php file?
  124. if (isset($assign_to_config))
  125. {
  126. $CFG->_assign_to_config($assign_to_config);
  127. }
  128. /*
  129. * ------------------------------------------------------
  130. * Instantiate the UTF-8 class
  131. * ------------------------------------------------------
  132. *
  133. * Note: Order here is rather important as the UTF-8
  134. * class needs to be used very early on, but it cannot
  135. * properly determine if UTf-8 can be supported until
  136. * after the Config class is instantiated.
  137. *
  138. */
  139. $UNI =& load_class('Utf8', 'core');
  140. /*
  141. * ------------------------------------------------------
  142. * Instantiate the URI class
  143. * ------------------------------------------------------
  144. */
  145. $URI =& load_class('URI', 'core');
  146. /*
  147. * ------------------------------------------------------
  148. * Instantiate the routing class and set the routing
  149. * ------------------------------------------------------
  150. */
  151. $RTR =& load_class('Router', 'core');
  152. $RTR->_set_routing();
  153. // Set any routing overrides that may exist in the main index file
  154. if (isset($routing))
  155. {
  156. $RTR->_set_overrides($routing);
  157. }
  158. /*
  159. * ------------------------------------------------------
  160. * Instantiate the output class
  161. * ------------------------------------------------------
  162. */
  163. $OUT =& load_class('Output', 'core');
  164. /*
  165. * ------------------------------------------------------
  166. * Is there a valid cache file? If so, we're done...
  167. * ------------------------------------------------------
  168. */
  169. if ($EXT->_call_hook('cache_override') === FALSE)
  170. {
  171. if ($OUT->_display_cache($CFG, $URI) == TRUE)
  172. {
  173. exit;
  174. }
  175. }
  176. /*
  177. * -----------------------------------------------------
  178. * Load the security class for xss and csrf support
  179. * -----------------------------------------------------
  180. */
  181. $SEC =& load_class('Security', 'core');
  182. /*
  183. * ------------------------------------------------------
  184. * Load the Input class and sanitize globals
  185. * ------------------------------------------------------
  186. */
  187. $IN =& load_class('Input', 'core');
  188. /*
  189. * ------------------------------------------------------
  190. * Load the Language class
  191. * ------------------------------------------------------
  192. */
  193. $LANG =& load_class('Lang', 'core');
  194. /*
  195. * ------------------------------------------------------
  196. * Load the app controller and local controller
  197. * ------------------------------------------------------
  198. *
  199. */
  200. // Load the base controller class
  201. require BASEPATH.'core/Controller'.EXT;
  202. function &get_instance()
  203. {
  204. return CI_Controller::get_instance();
  205. }
  206. if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT))
  207. {
  208. require APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller'.EXT;
  209. }
  210. // Load the local application controller
  211. // Note: The Router class automatically validates the controller path using the router->_validate_request().
  212. // If this include fails it means that the default controller in the Routes.php file is not resolving to something valid.
  213. if ( ! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT))
  214. {
  215. show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.');
  216. }
  217. include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().EXT);
  218. // Set a mark point for benchmarking
  219. $BM->mark('loading_time:_base_classes_end');
  220. /*
  221. * ------------------------------------------------------
  222. * Security check
  223. * ------------------------------------------------------
  224. *
  225. * None of the functions in the app controller or the
  226. * loader class can be called via the URI, nor can
  227. * controller functions that begin with an underscore
  228. */
  229. $class = $RTR->fetch_class();
  230. $method = $RTR->fetch_method();
  231. if ( ! class_exists($class)
  232. OR strncmp($method, '_', 1) == 0
  233. OR in_array(strtolower($method), array_map('strtolower', get_class_methods('CI_Controller')))
  234. )
  235. {
  236. show_404("{$class}/{$method}");
  237. }
  238. /*
  239. * ------------------------------------------------------
  240. * Is there a "pre_controller" hook?
  241. * ------------------------------------------------------
  242. */
  243. $EXT->_call_hook('pre_controller');
  244. /*
  245. * ------------------------------------------------------
  246. * Instantiate the requested controller
  247. * ------------------------------------------------------
  248. */
  249. // Mark a start point so we can benchmark the controller
  250. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
  251. $CI = new $class();
  252. /*
  253. * ------------------------------------------------------
  254. * Is there a "post_controller_constructor" hook?
  255. * ------------------------------------------------------
  256. */
  257. $EXT->_call_hook('post_controller_constructor');
  258. /*
  259. * ------------------------------------------------------
  260. * Call the requested method
  261. * ------------------------------------------------------
  262. */
  263. // Is there a "remap" function? If so, we call it instead
  264. if (method_exists($CI, '_remap'))
  265. {
  266. $CI->_remap($method, array_slice($URI->rsegments, 2));
  267. }
  268. else
  269. {
  270. // is_callable() returns TRUE on some versions of PHP 5 for private and protected
  271. // methods, so we'll use this workaround for consistent behavior
  272. if ( ! in_array(strtolower($method), array_map('strtolower', get_class_methods($CI))))
  273. {
  274. // Check and see if we are using a 404 override and use it.
  275. if ( ! empty($RTR->routes['404_override']))
  276. {
  277. $x = explode('/', $RTR->routes['404_override']);
  278. $class = $x[0];
  279. $method = (isset($x[1]) ? $x[1] : 'index');
  280. if ( ! class_exists($class))
  281. {
  282. if ( ! file_exists(APPPATH.'controllers/'.$class.EXT))
  283. {
  284. show_404("{$class}/{$method}");
  285. }
  286. include_once(APPPATH.'controllers/'.$class.EXT);
  287. unset($CI);
  288. $CI = new $class();
  289. }
  290. }
  291. else
  292. {
  293. show_404("{$class}/{$method}");
  294. }
  295. }
  296. // Call the requested method.
  297. // Any URI segments present (besides the class/function) will be passed to the method for convenience
  298. call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
  299. }
  300. // Mark a benchmark end point
  301. $BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
  302. /*
  303. * ------------------------------------------------------
  304. * Is there a "post_controller" hook?
  305. * ------------------------------------------------------
  306. */
  307. $EXT->_call_hook('post_controller');
  308. /*
  309. * ------------------------------------------------------
  310. * Send the final rendered output to the browser
  311. * ------------------------------------------------------
  312. */
  313. if ($EXT->_call_hook('display_override') === FALSE)
  314. {
  315. $OUT->_display();
  316. }
  317. /*
  318. * ------------------------------------------------------
  319. * Is there a "post_system" hook?
  320. * ------------------------------------------------------
  321. */
  322. $EXT->_call_hook('post_system');
  323. /*
  324. * ------------------------------------------------------
  325. * Close the DB connection if one exists
  326. * ------------------------------------------------------
  327. */
  328. if (class_exists('CI_DB') AND isset($CI->db))
  329. {
  330. $CI->db->close();
  331. }
  332. /* End of file CodeIgniter.php */
  333. /* Location: ./system/core/CodeIgniter.php */