blob: 7003318eeb5bd305994e1b6061be7b69241add1a [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Greg Aker0711dc82011-01-05 10:49:40 -06009 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @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 * Loader Class
20 *
21 * Loads views and files
22 *
23 * @package CodeIgniter
24 * @subpackage Libraries
25 * @author ExpressionEngine Dev Team
26 * @category Loader
27 * @link http://codeigniter.com/user_guide/libraries/loader.html
28 */
29class CI_Loader {
30
31 // All these are set automatically. Don't mess with them.
32 var $_ci_ob_level;
33 var $_ci_view_path = '';
Derek Jones32bf1862010-03-02 13:46:07 -060034 var $_ci_library_paths = array();
35 var $_ci_model_paths = array();
36 var $_ci_helper_paths = array();
Derek Jones32bf1862010-03-02 13:46:07 -060037 var $_base_classes = array(); // Set by the controller class
Derek Allard2067d1a2008-11-13 22:59:24 +000038 var $_ci_cached_vars = array();
39 var $_ci_classes = array();
40 var $_ci_loaded_files = array();
41 var $_ci_models = array();
42 var $_ci_helpers = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000043 var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
Barry Mienydd671972010-10-04 16:33:58 +020044
Derek Allard2067d1a2008-11-13 22:59:24 +000045
46 /**
47 * Constructor
48 *
49 * Sets the path to the view files and gets the initial output buffering level
50 *
51 * @access public
52 */
Greg Akera9263282010-11-10 15:26:43 -060053 function __construct()
Barry Mienydd671972010-10-04 16:33:58 +020054 {
Derek Allard2067d1a2008-11-13 22:59:24 +000055 $this->_ci_view_path = APPPATH.'views/';
56 $this->_ci_ob_level = ob_get_level();
Derek Jones32bf1862010-03-02 13:46:07 -060057 $this->_ci_library_paths = array(APPPATH, BASEPATH);
58 $this->_ci_helper_paths = array(APPPATH, BASEPATH);
59 $this->_ci_model_paths = array(APPPATH);
Barry Mienydd671972010-10-04 16:33:58 +020060
Derek Allard2067d1a2008-11-13 22:59:24 +000061 log_message('debug', "Loader Class Initialized");
62 }
Barry Mienydd671972010-10-04 16:33:58 +020063
Derek Allard2067d1a2008-11-13 22:59:24 +000064 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020065
Derek Allard2067d1a2008-11-13 22:59:24 +000066 /**
67 * Class Loader
68 *
69 * This function lets users load and instantiate classes.
70 * It is designed to be called from a user's app controllers.
71 *
72 * @access public
73 * @param string the name of the class
74 * @param mixed the optional parameters
75 * @param string an optional object name
76 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020077 */
Derek Allard2067d1a2008-11-13 22:59:24 +000078 function library($library = '', $params = NULL, $object_name = NULL)
79 {
Greg Akerce433962010-10-12 09:29:35 -050080 if (is_array($library))
81 {
Pascal Kriete5d5895f2011-02-14 13:27:07 -050082 foreach ($library as $read)
Greg Akerce433962010-10-12 09:29:35 -050083 {
Phil Sturgeonde3dbc32010-12-27 17:41:02 +000084 $this->library($read);
Greg Akerce433962010-10-12 09:29:35 -050085 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +000086
Greg Akerce433962010-10-12 09:29:35 -050087 return;
88 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +000089
Derek Jones32bf1862010-03-02 13:46:07 -060090 if ($library == '' OR isset($this->_base_classes[$library]))
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
92 return FALSE;
93 }
94
Derek Jones32bf1862010-03-02 13:46:07 -060095 if ( ! is_null($params) && ! is_array($params))
Derek Allard2067d1a2008-11-13 22:59:24 +000096 {
97 $params = NULL;
98 }
99
100 if (is_array($library))
101 {
102 foreach ($library as $class)
103 {
104 $this->_ci_load_class($class, $params, $object_name);
105 }
106 }
107 else
108 {
109 $this->_ci_load_class($library, $params, $object_name);
110 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 }
112
113 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200114
Derek Allard2067d1a2008-11-13 22:59:24 +0000115 /**
116 * Model Loader
117 *
118 * This function lets users load and instantiate models.
119 *
120 * @access public
121 * @param string the name of the class
122 * @param string name for the model
123 * @param bool database connection
124 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200125 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 function model($model, $name = '', $db_conn = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200127 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 if (is_array($model))
129 {
Pascal Kriete5d5895f2011-02-14 13:27:07 -0500130 foreach ($model as $babe)
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 {
Barry Mienydd671972010-10-04 16:33:58 +0200132 $this->model($babe);
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 }
134 return;
135 }
136
137 if ($model == '')
138 {
139 return;
140 }
Barry Mienydd671972010-10-04 16:33:58 +0200141
Derek Jones32bf1862010-03-02 13:46:07 -0600142 $path = '';
Barry Mienydd671972010-10-04 16:33:58 +0200143
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 // Is the model in a sub-folder? If so, parse out the filename and path.
Derek Jones32bf1862010-03-02 13:46:07 -0600145 if (($last_slash = strrpos($model, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 {
Derek Jones32bf1862010-03-02 13:46:07 -0600147 // The path is in front of the last slash
148 $path = substr($model, 0, $last_slash + 1);
149
150 // And the model name behind it
151 $model = substr($model, $last_slash + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 }
Barry Mienydd671972010-10-04 16:33:58 +0200153
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 if ($name == '')
155 {
156 $name = $model;
157 }
Barry Mienydd671972010-10-04 16:33:58 +0200158
Derek Allard2067d1a2008-11-13 22:59:24 +0000159 if (in_array($name, $this->_ci_models, TRUE))
160 {
161 return;
162 }
Barry Mienydd671972010-10-04 16:33:58 +0200163
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 $CI =& get_instance();
165 if (isset($CI->$name))
166 {
167 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
168 }
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 $model = strtolower($model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000171
Derek Jones32bf1862010-03-02 13:46:07 -0600172 foreach ($this->_ci_model_paths as $mod_path)
173 {
174 if ( ! file_exists($mod_path.'models/'.$path.$model.EXT))
175 {
176 continue;
177 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000178
Derek Jones32bf1862010-03-02 13:46:07 -0600179 if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
180 {
181 if ($db_conn === TRUE)
Pascal Kriete287781e2010-11-10 15:43:49 -0500182 {
Derek Jones32bf1862010-03-02 13:46:07 -0600183 $db_conn = '';
Pascal Kriete287781e2010-11-10 15:43:49 -0500184 }
Derek Jones32bf1862010-03-02 13:46:07 -0600185
186 $CI->load->database($db_conn, FALSE, TRUE);
187 }
188
Greg Akerbce13482010-10-11 15:37:16 -0500189 if ( ! class_exists('CI_Model'))
Derek Jones32bf1862010-03-02 13:46:07 -0600190 {
191 load_class('Model', 'core');
192 }
193
194 require_once($mod_path.'models/'.$path.$model.EXT);
195
196 $model = ucfirst($model);
197
198 $CI->$name = new $model();
Derek Jones32bf1862010-03-02 13:46:07 -0600199
200 $this->_ci_models[] = $name;
201 return;
202 }
Barry Mienydd671972010-10-04 16:33:58 +0200203
Derek Jones32bf1862010-03-02 13:46:07 -0600204 // couldn't find the model
205 show_error('Unable to locate the model you have specified: '.$model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 }
Barry Mienydd671972010-10-04 16:33:58 +0200207
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Allard2067d1a2008-11-13 22:59:24 +0000210 /**
211 * Database Loader
212 *
213 * @access public
214 * @param string the DB credentials
215 * @param bool whether to return the DB object
216 * @param bool whether to enable active record (this allows us to override the config setting)
217 * @return object
Barry Mienydd671972010-10-04 16:33:58 +0200218 */
Derek Jonesffca6c22009-12-05 15:31:44 +0000219 function database($params = '', $return = FALSE, $active_record = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 {
221 // Grab the super object
222 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200223
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 // Do we even need to load the database class?
Derek Jones9fb6dd12009-12-05 15:32:48 +0000225 if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 {
227 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200228 }
229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 require_once(BASEPATH.'database/DB'.EXT);
231
232 if ($return === TRUE)
233 {
234 return DB($params, $active_record);
235 }
Barry Mienydd671972010-10-04 16:33:58 +0200236
237 // Initialize the db variable. Needed to prevent
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 // reference errors with some configurations
239 $CI->db = '';
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 // Load the DB class
Barry Mienydd671972010-10-04 16:33:58 +0200242 $CI->db =& DB($params, $active_record);
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 }
Barry Mienydd671972010-10-04 16:33:58 +0200244
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 // --------------------------------------------------------------------
246
247 /**
248 * Load the Utilities Class
249 *
250 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200251 * @return string
252 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 function dbutil()
254 {
255 if ( ! class_exists('CI_DB'))
256 {
257 $this->database();
258 }
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 $CI =& get_instance();
261
262 // for backwards compatibility, load dbforge so we can extend dbutils off it
263 // this use is deprecated and strongly discouraged
264 $CI->load->dbforge();
Barry Mienydd671972010-10-04 16:33:58 +0200265
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 require_once(BASEPATH.'database/DB_utility'.EXT);
267 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
268 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
269
Pascal Kriete58560022010-11-10 16:01:20 -0500270 $CI->dbutil = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 }
Barry Mienydd671972010-10-04 16:33:58 +0200272
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 // --------------------------------------------------------------------
274
275 /**
276 * Load the Database Forge Class
277 *
278 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200279 * @return string
280 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 function dbforge()
282 {
283 if ( ! class_exists('CI_DB'))
284 {
285 $this->database();
286 }
Barry Mienydd671972010-10-04 16:33:58 +0200287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200289
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 require_once(BASEPATH.'database/DB_forge'.EXT);
291 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT);
292 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
293
294 $CI->dbforge = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 }
Barry Mienydd671972010-10-04 16:33:58 +0200296
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200298
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 /**
300 * Load View
301 *
302 * This function is used to load a "view" file. It has three parameters:
303 *
304 * 1. The name of the "view" file to be included.
305 * 2. An associative array of data to be extracted for use in the view.
306 * 3. TRUE/FALSE - whether to return the data or load it. In
307 * some cases it's advantageous to be able to return data so that
308 * a developer can process it in some way.
309 *
310 * @access public
311 * @param string
312 * @param array
313 * @param bool
314 * @return void
315 */
316 function view($view, $vars = array(), $return = FALSE)
317 {
318 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 /**
324 * Load File
325 *
326 * This is a generic file loader
327 *
328 * @access public
329 * @param string
330 * @param bool
331 * @return string
332 */
333 function file($path, $return = FALSE)
334 {
335 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
336 }
Barry Mienydd671972010-10-04 16:33:58 +0200337
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200339
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 /**
341 * Set Variables
342 *
343 * Once variables are set they become available within
344 * the controller class and its "view" files.
345 *
346 * @access public
347 * @param array
348 * @return void
349 */
350 function vars($vars = array(), $val = '')
351 {
352 if ($val != '' AND is_string($vars))
353 {
354 $vars = array($vars => $val);
355 }
Barry Mienydd671972010-10-04 16:33:58 +0200356
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 $vars = $this->_ci_object_to_array($vars);
Barry Mienydd671972010-10-04 16:33:58 +0200358
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 if (is_array($vars) AND count($vars) > 0)
360 {
361 foreach ($vars as $key => $val)
362 {
363 $this->_ci_cached_vars[$key] = $val;
364 }
365 }
366 }
Barry Mienydd671972010-10-04 16:33:58 +0200367
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200369
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 /**
371 * Load Helper
372 *
373 * This function loads the specified helper file.
374 *
375 * @access public
376 * @param mixed
377 * @return void
378 */
379 function helper($helpers = array())
Barry Mienydd671972010-10-04 16:33:58 +0200380 {
Derek Jones32bf1862010-03-02 13:46:07 -0600381 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
Barry Mienydd671972010-10-04 16:33:58 +0200382 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 if (isset($this->_ci_helpers[$helper]))
384 {
385 continue;
386 }
Derek Jones32bf1862010-03-02 13:46:07 -0600387
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
389
Barry Mienydd671972010-10-04 16:33:58 +0200390 // Is this a helper extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 if (file_exists($ext_helper))
392 {
393 $base_helper = BASEPATH.'helpers/'.$helper.EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200394
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 if ( ! file_exists($base_helper))
396 {
397 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
398 }
Barry Mienydd671972010-10-04 16:33:58 +0200399
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 include_once($ext_helper);
401 include_once($base_helper);
Barry Mienydd671972010-10-04 16:33:58 +0200402
Derek Jones32bf1862010-03-02 13:46:07 -0600403 $this->_ci_helpers[$helper] = TRUE;
404 log_message('debug', 'Helper loaded: '.$helper);
405 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 }
Barry Mienydd671972010-10-04 16:33:58 +0200407
Derek Jones32bf1862010-03-02 13:46:07 -0600408 // Try to load the helper
409 foreach ($this->_ci_helper_paths as $path)
410 {
411 if (file_exists($path.'helpers/'.$helper.EXT))
Barry Mienydd671972010-10-04 16:33:58 +0200412 {
Derek Jones32bf1862010-03-02 13:46:07 -0600413 include_once($path.'helpers/'.$helper.EXT);
414
415 $this->_ci_helpers[$helper] = TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200416 log_message('debug', 'Helper loaded: '.$helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600417 break;
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 }
419 }
420
Derek Jones32bf1862010-03-02 13:46:07 -0600421 // unable to load the helper
422 if ( ! isset($this->_ci_helpers[$helper]))
423 {
Barry Mienydd671972010-10-04 16:33:58 +0200424 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
Derek Jones32bf1862010-03-02 13:46:07 -0600425 }
Barry Mienydd671972010-10-04 16:33:58 +0200426 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
Barry Mienydd671972010-10-04 16:33:58 +0200428
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200430
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 /**
432 * Load Helpers
433 *
434 * This is simply an alias to the above function in case the
435 * user has written the plural form of this function.
436 *
437 * @access public
438 * @param array
439 * @return void
440 */
441 function helpers($helpers = array())
442 {
443 $this->helper($helpers);
444 }
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200447
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 * Loads a language file
450 *
451 * @access public
452 * @param array
453 * @param string
454 * @return void
455 */
456 function language($file = array(), $lang = '')
457 {
458 $CI =& get_instance();
459
460 if ( ! is_array($file))
461 {
462 $file = array($file);
463 }
464
465 foreach ($file as $langfile)
Barry Mienydd671972010-10-04 16:33:58 +0200466 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 $CI->lang->load($langfile, $lang);
468 }
469 }
Barry Mienydd671972010-10-04 16:33:58 +0200470
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200472
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 /**
474 * Loads a config file
475 *
476 * @access public
477 * @param string
478 * @return void
479 */
480 function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200481 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 $CI =& get_instance();
483 $CI->config->load($file, $use_sections, $fail_gracefully);
484 }
485
486 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600487
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 /**
Derek Jones8dca0412010-03-05 13:01:44 -0600489 * Driver
490 *
491 * Loads a driver library
492 *
493 * @param string the name of the class
494 * @param mixed the optional parameters
495 * @param string an optional object name
496 * @return void
497 */
498 function driver($library = '', $params = NULL, $object_name = NULL)
499 {
500 if ( ! class_exists('CI_Driver_Library'))
501 {
502 // we aren't instantiating an object here, that'll be done by the Library itself
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600503 require BASEPATH.'libraries/Driver'.EXT;
504 }
Barry Mienydd671972010-10-04 16:33:58 +0200505
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600506 // We can save the loader some time since Drivers will *always* be in a subfolder,
507 // and typically identically named to the library
508 if ( ! strpos($library, '/'))
509 {
Greg Akerd25e66a2010-03-28 01:07:09 -0500510 $library = ucfirst($library).'/'.$library;
Derek Jones8dca0412010-03-05 13:01:44 -0600511 }
Barry Mienydd671972010-10-04 16:33:58 +0200512
Derek Jones8dca0412010-03-05 13:01:44 -0600513 return $this->library($library, $params, $object_name);
514 }
515
516 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200517
Derek Jones8dca0412010-03-05 13:01:44 -0600518 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600519 * Add Package Path
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 *
Derek Jones32bf1862010-03-02 13:46:07 -0600521 * Prepends a parent path to the library, model, helper, and config path arrays
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 *
523 * @access public
524 * @param string
525 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600526 */
527 function add_package_path($path)
528 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500529 $path = rtrim($path, '/').'/';
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000530
Derek Jones32bf1862010-03-02 13:46:07 -0600531 array_unshift($this->_ci_library_paths, $path);
532 array_unshift($this->_ci_model_paths, $path);
533 array_unshift($this->_ci_helper_paths, $path);
Barry Mienydd671972010-10-04 16:33:58 +0200534
Derek Jones32bf1862010-03-02 13:46:07 -0600535 // Add config file path
536 $config =& $this->_ci_get_component('config');
537 array_unshift($config->_config_paths, $path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000538 }
539
540 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600541
542 /**
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000543 * Get Package Paths
544 *
545 * Return a list of all package paths, by default it will ignore BASEPATH.
546 *
547 * @access public
548 * @param string
549 * @return void
550 */
551 function get_package_paths($include_base = FALSE)
552 {
553 return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths;
554 }
555
556 // --------------------------------------------------------------------
557
558 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600559 * Remove Package Path
560 *
561 * Remove a path from the library, model, and helper path arrays if it exists
562 * If no path is provided, the most recently added path is removed.
563 *
564 * @access public
565 * @param type
566 * @return type
567 */
568 function remove_package_path($path = '', $remove_config_path = TRUE)
569 {
570 $config =& $this->_ci_get_component('config');
Barry Mienydd671972010-10-04 16:33:58 +0200571
Derek Jones32bf1862010-03-02 13:46:07 -0600572 if ($path == '')
573 {
574 $void = array_shift($this->_ci_library_paths);
575 $void = array_shift($this->_ci_model_paths);
576 $void = array_shift($this->_ci_helper_paths);
577 $void = array_shift($config->_config_paths);
578 }
579 else
580 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500581 $path = rtrim($path, '/').'/';
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000582
Derek Jones32bf1862010-03-02 13:46:07 -0600583 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
584 {
585 if (($key = array_search($path, $this->{$var})) !== FALSE)
586 {
587 unset($this->{$var}[$key]);
588 }
589 }
Barry Mienydd671972010-10-04 16:33:58 +0200590
Derek Jones32bf1862010-03-02 13:46:07 -0600591 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
592 {
593 unset($config->_config_paths[$key]);
594 }
595 }
Barry Mienydd671972010-10-04 16:33:58 +0200596
Derek Jones32bf1862010-03-02 13:46:07 -0600597 // make sure the application default paths are still in the array
598 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
599 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
600 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
601 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
602 }
603
604 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200605
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 /**
607 * Loader
608 *
609 * This function is used to load views and files.
610 * Variables are prefixed with _ci_ to avoid symbol collision with
611 * variables made available to view files
612 *
613 * @access private
614 * @param array
615 * @return void
616 */
617 function _ci_load($_ci_data)
618 {
619 // Set the default data variables
620 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
621 {
622 $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
623 }
624
625 // Set the path to the requested file
626 if ($_ci_path == '')
627 {
628 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
629 $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
630 $_ci_path = $this->_ci_view_path.$_ci_file;
631 }
632 else
633 {
634 $_ci_x = explode('/', $_ci_path);
635 $_ci_file = end($_ci_x);
636 }
Barry Mienydd671972010-10-04 16:33:58 +0200637
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 if ( ! file_exists($_ci_path))
639 {
640 show_error('Unable to load the requested file: '.$_ci_file);
641 }
Barry Mienydd671972010-10-04 16:33:58 +0200642
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 // This allows anything loaded using $this->load (views, files, etc.)
644 // to become accessible from within the Controller and Model functions.
Barry Mienydd671972010-10-04 16:33:58 +0200645
Pascal Kriete89ace432010-11-10 15:49:10 -0500646 $_ci_CI =& get_instance();
647 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
Derek Allard2067d1a2008-11-13 22:59:24 +0000648 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500649 if ( ! isset($this->$_ci_key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000650 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500651 $this->$_ci_key =& $_ci_CI->$_ci_key;
Derek Allard2067d1a2008-11-13 22:59:24 +0000652 }
653 }
654
655 /*
656 * Extract and cache variables
657 *
658 * You can either set variables using the dedicated $this->load_vars()
659 * function or via the second parameter of this function. We'll merge
660 * the two types and cache them so that views that are embedded within
661 * other views can have access to these variables.
Barry Mienydd671972010-10-04 16:33:58 +0200662 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 if (is_array($_ci_vars))
664 {
665 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
666 }
667 extract($this->_ci_cached_vars);
Barry Mienydd671972010-10-04 16:33:58 +0200668
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 /*
670 * Buffer the output
671 *
672 * We buffer the output for two reasons:
673 * 1. Speed. You get a significant speed boost.
674 * 2. So that the final rendered template can be
675 * post-processed by the output class. Why do we
676 * need post processing? For one thing, in order to
677 * show the elapsed page load time. Unless we
678 * can intercept the content right before it's sent to
679 * the browser and then stop the timer it won't be accurate.
680 */
681 ob_start();
Barry Mienydd671972010-10-04 16:33:58 +0200682
Derek Allard2067d1a2008-11-13 22:59:24 +0000683 // If the PHP installation does not support short tags we'll
684 // do a little string replacement, changing the short tags
685 // to standard PHP echo statements.
Barry Mienydd671972010-10-04 16:33:58 +0200686
Derek Allard2067d1a2008-11-13 22:59:24 +0000687 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
688 {
689 echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
690 }
691 else
692 {
693 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
694 }
Barry Mienydd671972010-10-04 16:33:58 +0200695
Derek Allard2067d1a2008-11-13 22:59:24 +0000696 log_message('debug', 'File loaded: '.$_ci_path);
Barry Mienydd671972010-10-04 16:33:58 +0200697
Derek Allard2067d1a2008-11-13 22:59:24 +0000698 // Return the file data if requested
699 if ($_ci_return === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200700 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 $buffer = ob_get_contents();
702 @ob_end_clean();
703 return $buffer;
704 }
705
706 /*
707 * Flush the buffer... or buff the flusher?
708 *
709 * In order to permit views to be nested within
710 * other views, we need to flush the content back out whenever
711 * we are beyond the first level of output buffering so that
712 * it can be seen and included properly by the first included
713 * template and any subsequent ones. Oy!
714 *
Barry Mienydd671972010-10-04 16:33:58 +0200715 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000716 if (ob_get_level() > $this->_ci_ob_level + 1)
717 {
718 ob_end_flush();
719 }
720 else
721 {
Greg Aker22f1a632010-11-10 15:34:35 -0600722 $_ci_CI->output->append_output(ob_get_contents());
Derek Allard2067d1a2008-11-13 22:59:24 +0000723 @ob_end_clean();
724 }
725 }
726
727 // --------------------------------------------------------------------
728
729 /**
730 * Load class
731 *
732 * This function loads the requested class.
733 *
734 * @access private
Barry Mienydd671972010-10-04 16:33:58 +0200735 * @param string the item that is being loaded
Derek Allard2067d1a2008-11-13 22:59:24 +0000736 * @param mixed any additional parameters
737 * @param string an optional object name
Barry Mienydd671972010-10-04 16:33:58 +0200738 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000739 */
740 function _ci_load_class($class, $params = NULL, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200741 {
742 // Get the class name, and while we're at it trim any slashes.
743 // The directory path can be included as part of the class name,
Derek Allard2067d1a2008-11-13 22:59:24 +0000744 // but we don't want a leading slash
745 $class = str_replace(EXT, '', trim($class, '/'));
Barry Mienydd671972010-10-04 16:33:58 +0200746
Derek Allard2067d1a2008-11-13 22:59:24 +0000747 // Was the path included with the class name?
748 // We look for a slash to determine this
749 $subdir = '';
Derek Jones32bf1862010-03-02 13:46:07 -0600750 if (($last_slash = strrpos($class, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 {
Derek Jones32bf1862010-03-02 13:46:07 -0600752 // Extract the path
753 $subdir = substr($class, 0, $last_slash + 1);
Barry Mienydd671972010-10-04 16:33:58 +0200754
Derek Jones32bf1862010-03-02 13:46:07 -0600755 // Get the filename from the path
756 $class = substr($class, $last_slash + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000757 }
758
759 // We'll test for both lowercase and capitalized versions of the file name
760 foreach (array(ucfirst($class), strtolower($class)) as $class)
761 {
762 $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;
763
Barry Mienydd671972010-10-04 16:33:58 +0200764 // Is this a class extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000765 if (file_exists($subclass))
766 {
767 $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200768
Derek Allard2067d1a2008-11-13 22:59:24 +0000769 if ( ! file_exists($baseclass))
770 {
771 log_message('error', "Unable to load the requested class: ".$class);
772 show_error("Unable to load the requested class: ".$class);
773 }
774
775 // Safety: Was the class already loaded by a previous call?
776 if (in_array($subclass, $this->_ci_loaded_files))
777 {
778 // Before we deem this to be a duplicate request, let's see
779 // if a custom object name is being supplied. If so, we'll
780 // return a new instance of the object
781 if ( ! is_null($object_name))
782 {
783 $CI =& get_instance();
784 if ( ! isset($CI->$object_name))
785 {
Barry Mienydd671972010-10-04 16:33:58 +0200786 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 }
788 }
Barry Mienydd671972010-10-04 16:33:58 +0200789
Derek Allard2067d1a2008-11-13 22:59:24 +0000790 $is_duplicate = TRUE;
791 log_message('debug', $class." class already loaded. Second attempt ignored.");
792 return;
793 }
Barry Mienydd671972010-10-04 16:33:58 +0200794
795 include_once($baseclass);
Derek Allard2067d1a2008-11-13 22:59:24 +0000796 include_once($subclass);
797 $this->_ci_loaded_files[] = $subclass;
Barry Mienydd671972010-10-04 16:33:58 +0200798
799 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000800 }
Barry Mienydd671972010-10-04 16:33:58 +0200801
Derek Allard2067d1a2008-11-13 22:59:24 +0000802 // Lets search for the requested library file and load it.
Derek Jones32bf1862010-03-02 13:46:07 -0600803 $is_duplicate = FALSE;
804 foreach ($this->_ci_library_paths as $path)
Derek Allard2067d1a2008-11-13 22:59:24 +0000805 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 $filepath = $path.'libraries/'.$subdir.$class.EXT;
Derek Jones32bf1862010-03-02 13:46:07 -0600807
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 // Does the file exist? No? Bummer...
809 if ( ! file_exists($filepath))
810 {
811 continue;
812 }
Barry Mienydd671972010-10-04 16:33:58 +0200813
Derek Allard2067d1a2008-11-13 22:59:24 +0000814 // Safety: Was the class already loaded by a previous call?
815 if (in_array($filepath, $this->_ci_loaded_files))
816 {
817 // Before we deem this to be a duplicate request, let's see
818 // if a custom object name is being supplied. If so, we'll
819 // return a new instance of the object
820 if ( ! is_null($object_name))
821 {
822 $CI =& get_instance();
823 if ( ! isset($CI->$object_name))
824 {
825 return $this->_ci_init_class($class, '', $params, $object_name);
826 }
827 }
Barry Mienydd671972010-10-04 16:33:58 +0200828
Derek Allard2067d1a2008-11-13 22:59:24 +0000829 $is_duplicate = TRUE;
830 log_message('debug', $class." class already loaded. Second attempt ignored.");
831 return;
832 }
Barry Mienydd671972010-10-04 16:33:58 +0200833
Derek Allard2067d1a2008-11-13 22:59:24 +0000834 include_once($filepath);
835 $this->_ci_loaded_files[] = $filepath;
Barry Mienydd671972010-10-04 16:33:58 +0200836 return $this->_ci_init_class($class, '', $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000837 }
Derek Jones32bf1862010-03-02 13:46:07 -0600838
Derek Allard2067d1a2008-11-13 22:59:24 +0000839 } // END FOREACH
840
841 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
842 if ($subdir == '')
843 {
844 $path = strtolower($class).'/'.$class;
845 return $this->_ci_load_class($path, $params);
846 }
Barry Mienydd671972010-10-04 16:33:58 +0200847
Derek Allard2067d1a2008-11-13 22:59:24 +0000848 // If we got this far we were unable to find the requested class.
849 // We do not issue errors if the load call failed due to a duplicate request
850 if ($is_duplicate == FALSE)
851 {
852 log_message('error', "Unable to load the requested class: ".$class);
853 show_error("Unable to load the requested class: ".$class);
854 }
855 }
Barry Mienydd671972010-10-04 16:33:58 +0200856
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 // --------------------------------------------------------------------
858
859 /**
860 * Instantiates a class
861 *
862 * @access private
863 * @param string
864 * @param string
865 * @param string an optional object name
866 * @return null
867 */
868 function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200869 {
Derek Jones32bf1862010-03-02 13:46:07 -0600870 // Is there an associated config file for this class? Note: these should always be lowercase
Derek Allard2067d1a2008-11-13 22:59:24 +0000871 if ($config === NULL)
872 {
Eric Barnes5e16ec62011-01-04 17:25:23 -0500873 // Fetch the config paths containing any package paths
874 $config_component = $this->_ci_get_component('config');
875
876 if (is_array($config_component->_config_paths))
Derek Allard2067d1a2008-11-13 22:59:24 +0000877 {
Eric Barnes5e16ec62011-01-04 17:25:23 -0500878 // Break on the first found file, thus package files
879 // are not overridden by default paths
880 foreach ($config_component->_config_paths as $path)
881 {
882 // We test for both uppercase and lowercase, for servers that
joelcox1bfd9fa2011-01-16 18:49:39 +0100883 // are case-sensitive with regard to file names. Check for environment
884 // first, global next
885 if (file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT))
886 {
887 include_once($path .'config/'.ENVIRONMENT.'/'.strtolower($class).EXT);
888 break;
889 }
890 elseif (file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT))
891 {
892 include_once($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).EXT);
893 break;
894 }
895 elseif (file_exists($path .'config/'.strtolower($class).EXT))
Eric Barnes5e16ec62011-01-04 17:25:23 -0500896 {
897 include_once($path .'config/'.strtolower($class).EXT);
898 break;
899 }
900 elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).EXT))
901 {
902 include_once($path .'config/'.ucfirst(strtolower($class)).EXT);
903 break;
904 }
905 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000906 }
907 }
Barry Mienydd671972010-10-04 16:33:58 +0200908
Derek Allard2067d1a2008-11-13 22:59:24 +0000909 if ($prefix == '')
Barry Mienydd671972010-10-04 16:33:58 +0200910 {
911 if (class_exists('CI_'.$class))
Derek Allard2067d1a2008-11-13 22:59:24 +0000912 {
913 $name = 'CI_'.$class;
914 }
Barry Mienydd671972010-10-04 16:33:58 +0200915 elseif (class_exists(config_item('subclass_prefix').$class))
Derek Allard2067d1a2008-11-13 22:59:24 +0000916 {
917 $name = config_item('subclass_prefix').$class;
918 }
919 else
920 {
921 $name = $class;
922 }
923 }
924 else
925 {
926 $name = $prefix.$class;
927 }
Barry Mienydd671972010-10-04 16:33:58 +0200928
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 // Is the class name valid?
930 if ( ! class_exists($name))
931 {
932 log_message('error', "Non-existent class: ".$name);
933 show_error("Non-existent class: ".$class);
934 }
Barry Mienydd671972010-10-04 16:33:58 +0200935
Derek Allard2067d1a2008-11-13 22:59:24 +0000936 // Set the variable name we will assign the class to
937 // Was a custom class name supplied? If so we'll use it
938 $class = strtolower($class);
Barry Mienydd671972010-10-04 16:33:58 +0200939
Derek Allard2067d1a2008-11-13 22:59:24 +0000940 if (is_null($object_name))
941 {
942 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
943 }
944 else
945 {
946 $classvar = $object_name;
947 }
948
Barry Mienydd671972010-10-04 16:33:58 +0200949 // Save the class name and object name
Derek Allard2067d1a2008-11-13 22:59:24 +0000950 $this->_ci_classes[$class] = $classvar;
951
Barry Mienydd671972010-10-04 16:33:58 +0200952 // Instantiate the class
Derek Allard2067d1a2008-11-13 22:59:24 +0000953 $CI =& get_instance();
954 if ($config !== NULL)
955 {
956 $CI->$classvar = new $name($config);
957 }
958 else
Barry Mienydd671972010-10-04 16:33:58 +0200959 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000960 $CI->$classvar = new $name;
Barry Mienydd671972010-10-04 16:33:58 +0200961 }
962 }
963
Derek Allard2067d1a2008-11-13 22:59:24 +0000964 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200965
Derek Allard2067d1a2008-11-13 22:59:24 +0000966 /**
967 * Autoloader
968 *
969 * The config/autoload.php file contains an array that permits sub-systems,
Derek Jonesc6da5032010-03-09 20:44:27 -0600970 * libraries, and helpers to be loaded automatically.
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 *
972 * @access private
973 * @param array
974 * @return void
975 */
976 function _ci_autoloader()
Barry Mienydd671972010-10-04 16:33:58 +0200977 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000978 include_once(APPPATH.'config/autoload'.EXT);
Barry Mienydd671972010-10-04 16:33:58 +0200979
Derek Allard2067d1a2008-11-13 22:59:24 +0000980 if ( ! isset($autoload))
981 {
982 return FALSE;
983 }
Barry Mienydd671972010-10-04 16:33:58 +0200984
Phil Sturgeon9730c752010-12-15 10:50:15 +0000985 // Autoload packages
986 if (isset($autoload['packages']))
987 {
988 foreach ($autoload['packages'] as $package_path)
989 {
990 $this->add_package_path($package_path);
991 }
992 }
993
Derek Allard2067d1a2008-11-13 22:59:24 +0000994 // Load any custom config file
995 if (count($autoload['config']) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200996 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000997 $CI =& get_instance();
998 foreach ($autoload['config'] as $key => $val)
999 {
1000 $CI->config->load($val);
1001 }
Barry Mienydd671972010-10-04 16:33:58 +02001002 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001003
Derek Jonesc6da5032010-03-09 20:44:27 -06001004 // Autoload helpers and languages
1005 foreach (array('helper', 'language') as $type)
Barry Mienydd671972010-10-04 16:33:58 +02001006 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
1008 {
1009 $this->$type($autoload[$type]);
Barry Mienydd671972010-10-04 16:33:58 +02001010 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001011 }
1012
1013 // A little tweak to remain backward compatible
1014 // The $autoload['core'] item was deprecated
Derek Jones32bf1862010-03-02 13:46:07 -06001015 if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001016 {
1017 $autoload['libraries'] = $autoload['core'];
1018 }
Barry Mienydd671972010-10-04 16:33:58 +02001019
Derek Allard2067d1a2008-11-13 22:59:24 +00001020 // Load libraries
1021 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
1022 {
1023 // Load the database driver.
1024 if (in_array('database', $autoload['libraries']))
1025 {
1026 $this->database();
1027 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
1028 }
Barry Mienydd671972010-10-04 16:33:58 +02001029
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 // Load all other libraries
1031 foreach ($autoload['libraries'] as $item)
1032 {
1033 $this->library($item);
1034 }
Barry Mienydd671972010-10-04 16:33:58 +02001035 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001036
1037 // Autoload models
1038 if (isset($autoload['model']))
1039 {
1040 $this->model($autoload['model']);
1041 }
Barry Mienydd671972010-10-04 16:33:58 +02001042 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001043
1044 // --------------------------------------------------------------------
1045
1046 /**
1047 * Object to Array
1048 *
1049 * Takes an object as input and converts the class variables to array key/vals
1050 *
1051 * @access private
1052 * @param object
1053 * @return array
1054 */
1055 function _ci_object_to_array($object)
1056 {
1057 return (is_object($object)) ? get_object_vars($object) : $object;
1058 }
1059
1060 // --------------------------------------------------------------------
1061
1062 /**
Derek Jones32bf1862010-03-02 13:46:07 -06001063 * Get a reference to a specific library or model
1064 *
1065 * @access private
1066 * @return bool
1067 */
1068 function &_ci_get_component($component)
1069 {
Pascal Kriete89ace432010-11-10 15:49:10 -05001070 $CI =& get_instance();
1071 return $CI->$component;
Derek Jones32bf1862010-03-02 13:46:07 -06001072 }
1073
1074 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001075
Derek Jones32bf1862010-03-02 13:46:07 -06001076 /**
1077 * Prep filename
1078 *
1079 * This function preps the name of various items to make loading them more reliable.
1080 *
1081 * @access private
1082 * @param mixed
1083 * @return array
1084 */
1085 function _ci_prep_filename($filename, $extension)
1086 {
1087 if ( ! is_array($filename))
Barry Mienydd671972010-10-04 16:33:58 +02001088 {
1089 return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension));
Derek Jones32bf1862010-03-02 13:46:07 -06001090 }
1091 else
1092 {
1093 foreach ($filename as $key => $val)
1094 {
Barry Mienydd671972010-10-04 16:33:58 +02001095 $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension);
Derek Jones32bf1862010-03-02 13:46:07 -06001096 }
Barry Mienydd671972010-10-04 16:33:58 +02001097
Derek Jones32bf1862010-03-02 13:46:07 -06001098 return $filename;
1099 }
1100 }
Barry Mienydd671972010-10-04 16:33:58 +02001101
Derek Allard2067d1a2008-11-13 22:59:24 +00001102
1103}
1104
1105/* End of file Loader.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -06001106/* Location: ./system/core/Loader.php */