PageRenderTime 33ms CodeModel.GetById 27ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/halogy/codeigniter/CodeIgniter.php

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