blob: 2324eca1e1154789f1470da1f3e1d25a9e953f15 [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 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, 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();
Barry Mienydd671972010-10-04 16:33:58 +020037 var $_ci_is_instance = FALSE; // Whether we should use $this or $CI =& get_instance()
Derek Jones32bf1862010-03-02 13:46:07 -060038 var $_base_classes = array(); // Set by the controller class
Derek Allard2067d1a2008-11-13 22:59:24 +000039 var $_ci_cached_vars = array();
40 var $_ci_classes = array();
41 var $_ci_loaded_files = array();
42 var $_ci_models = array();
43 var $_ci_helpers = array();
Derek Allard2067d1a2008-11-13 22:59:24 +000044 var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
Barry Mienydd671972010-10-04 16:33:58 +020045
Derek Allard2067d1a2008-11-13 22:59:24 +000046
47 /**
48 * Constructor
49 *
50 * Sets the path to the view files and gets the initial output buffering level
51 *
52 * @access public
53 */
54 function CI_Loader()
Barry Mienydd671972010-10-04 16:33:58 +020055 {
Derek Allard2067d1a2008-11-13 22:59:24 +000056 $this->_ci_view_path = APPPATH.'views/';
57 $this->_ci_ob_level = ob_get_level();
Derek Jones32bf1862010-03-02 13:46:07 -060058 $this->_ci_library_paths = array(APPPATH, BASEPATH);
59 $this->_ci_helper_paths = array(APPPATH, BASEPATH);
60 $this->_ci_model_paths = array(APPPATH);
Barry Mienydd671972010-10-04 16:33:58 +020061
Derek Allard2067d1a2008-11-13 22:59:24 +000062 log_message('debug', "Loader Class Initialized");
63 }
Barry Mienydd671972010-10-04 16:33:58 +020064
Derek Allard2067d1a2008-11-13 22:59:24 +000065 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020066
Derek Allard2067d1a2008-11-13 22:59:24 +000067 /**
68 * Class Loader
69 *
70 * This function lets users load and instantiate classes.
71 * It is designed to be called from a user's app controllers.
72 *
73 * @access public
74 * @param string the name of the class
75 * @param mixed the optional parameters
76 * @param string an optional object name
77 * @return void
Barry Mienydd671972010-10-04 16:33:58 +020078 */
Derek Allard2067d1a2008-11-13 22:59:24 +000079 function library($library = '', $params = NULL, $object_name = NULL)
80 {
Greg Akerce433962010-10-12 09:29:35 -050081 if (is_array($library))
82 {
83 foreach($library as $read)
84 {
85 $this->library($read);
86 }
87
88 return;
89 }
90
Derek Jones32bf1862010-03-02 13:46:07 -060091 if ($library == '' OR isset($this->_base_classes[$library]))
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
93 return FALSE;
94 }
95
Derek Jones32bf1862010-03-02 13:46:07 -060096 if ( ! is_null($params) && ! is_array($params))
Derek Allard2067d1a2008-11-13 22:59:24 +000097 {
98 $params = NULL;
99 }
100
101 if (is_array($library))
102 {
103 foreach ($library as $class)
104 {
105 $this->_ci_load_class($class, $params, $object_name);
106 }
107 }
108 else
109 {
110 $this->_ci_load_class($library, $params, $object_name);
111 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 }
113
114 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200115
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 /**
117 * Model Loader
118 *
119 * This function lets users load and instantiate models.
120 *
121 * @access public
122 * @param string the name of the class
123 * @param string name for the model
124 * @param bool database connection
125 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200126 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 function model($model, $name = '', $db_conn = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200128 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 if (is_array($model))
130 {
131 foreach($model as $babe)
132 {
Barry Mienydd671972010-10-04 16:33:58 +0200133 $this->model($babe);
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 }
135 return;
136 }
137
138 if ($model == '')
139 {
140 return;
141 }
Barry Mienydd671972010-10-04 16:33:58 +0200142
Derek Jones32bf1862010-03-02 13:46:07 -0600143 $path = '';
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 // Is the model in a sub-folder? If so, parse out the filename and path.
Derek Jones32bf1862010-03-02 13:46:07 -0600146 if (($last_slash = strrpos($model, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 {
Derek Jones32bf1862010-03-02 13:46:07 -0600148 // The path is in front of the last slash
149 $path = substr($model, 0, $last_slash + 1);
150
151 // And the model name behind it
152 $model = substr($model, $last_slash + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 }
Barry Mienydd671972010-10-04 16:33:58 +0200154
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 if ($name == '')
156 {
157 $name = $model;
158 }
Barry Mienydd671972010-10-04 16:33:58 +0200159
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 if (in_array($name, $this->_ci_models, TRUE))
161 {
162 return;
163 }
Barry Mienydd671972010-10-04 16:33:58 +0200164
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 $CI =& get_instance();
166 if (isset($CI->$name))
167 {
168 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
169 }
Barry Mienydd671972010-10-04 16:33:58 +0200170
Derek Allard2067d1a2008-11-13 22:59:24 +0000171 $model = strtolower($model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000172
Derek Jones32bf1862010-03-02 13:46:07 -0600173 foreach ($this->_ci_model_paths as $mod_path)
174 {
175 if ( ! file_exists($mod_path.'models/'.$path.$model.EXT))
176 {
177 continue;
178 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000179
Derek Jones32bf1862010-03-02 13:46:07 -0600180 if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
181 {
182 if ($db_conn === TRUE)
Pascal Kriete287781e2010-11-10 15:43:49 -0500183 {
Derek Jones32bf1862010-03-02 13:46:07 -0600184 $db_conn = '';
Pascal Kriete287781e2010-11-10 15:43:49 -0500185 }
Derek Jones32bf1862010-03-02 13:46:07 -0600186
187 $CI->load->database($db_conn, FALSE, TRUE);
188 }
189
Greg Akerbce13482010-10-11 15:37:16 -0500190 if ( ! class_exists('CI_Model'))
Derek Jones32bf1862010-03-02 13:46:07 -0600191 {
192 load_class('Model', 'core');
193 }
194
195 require_once($mod_path.'models/'.$path.$model.EXT);
196
197 $model = ucfirst($model);
198
199 $CI->$name = new $model();
Derek Jones32bf1862010-03-02 13:46:07 -0600200
201 $this->_ci_models[] = $name;
202 return;
203 }
Barry Mienydd671972010-10-04 16:33:58 +0200204
Derek Jones32bf1862010-03-02 13:46:07 -0600205 // couldn't find the model
206 show_error('Unable to locate the model you have specified: '.$model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 }
Barry Mienydd671972010-10-04 16:33:58 +0200208
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200210
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 /**
212 * Database Loader
213 *
214 * @access public
215 * @param string the DB credentials
216 * @param bool whether to return the DB object
217 * @param bool whether to enable active record (this allows us to override the config setting)
218 * @return object
Barry Mienydd671972010-10-04 16:33:58 +0200219 */
Derek Jonesffca6c22009-12-05 15:31:44 +0000220 function database($params = '', $return = FALSE, $active_record = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 {
222 // Grab the super object
223 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200224
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 // Do we even need to load the database class?
Derek Jones9fb6dd12009-12-05 15:32:48 +0000226 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 +0000227 {
228 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200229 }
230
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 require_once(BASEPATH.'database/DB'.EXT);
232
233 if ($return === TRUE)
234 {
235 return DB($params, $active_record);
236 }
Barry Mienydd671972010-10-04 16:33:58 +0200237
238 // Initialize the db variable. Needed to prevent
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 // reference errors with some configurations
240 $CI->db = '';
Barry Mienydd671972010-10-04 16:33:58 +0200241
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 // Load the DB class
Barry Mienydd671972010-10-04 16:33:58 +0200243 $CI->db =& DB($params, $active_record);
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 }
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 // --------------------------------------------------------------------
247
248 /**
249 * Load the Utilities Class
250 *
251 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200252 * @return string
253 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 function dbutil()
255 {
256 if ( ! class_exists('CI_DB'))
257 {
258 $this->database();
259 }
Barry Mienydd671972010-10-04 16:33:58 +0200260
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 $CI =& get_instance();
262
263 // for backwards compatibility, load dbforge so we can extend dbutils off it
264 // this use is deprecated and strongly discouraged
265 $CI->load->dbforge();
Barry Mienydd671972010-10-04 16:33:58 +0200266
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 require_once(BASEPATH.'database/DB_utility'.EXT);
268 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility'.EXT);
269 $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
270
Derek Jonesf0a9b332009-07-29 14:19:18 +0000271 $CI->dbutil =& instantiate_class(new $class());
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 }
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 // --------------------------------------------------------------------
275
276 /**
277 * Load the Database Forge Class
278 *
279 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200280 * @return string
281 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 function dbforge()
283 {
284 if ( ! class_exists('CI_DB'))
285 {
286 $this->database();
287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200290
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 require_once(BASEPATH.'database/DB_forge'.EXT);
292 require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge'.EXT);
293 $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
294
295 $CI->dbforge = new $class();
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 }
Barry Mienydd671972010-10-04 16:33:58 +0200297
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 /**
301 * Load View
302 *
303 * This function is used to load a "view" file. It has three parameters:
304 *
305 * 1. The name of the "view" file to be included.
306 * 2. An associative array of data to be extracted for use in the view.
307 * 3. TRUE/FALSE - whether to return the data or load it. In
308 * some cases it's advantageous to be able to return data so that
309 * a developer can process it in some way.
310 *
311 * @access public
312 * @param string
313 * @param array
314 * @param bool
315 * @return void
316 */
317 function view($view, $vars = array(), $return = FALSE)
318 {
319 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
320 }
Barry Mienydd671972010-10-04 16:33:58 +0200321
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 /**
325 * Load File
326 *
327 * This is a generic file loader
328 *
329 * @access public
330 * @param string
331 * @param bool
332 * @return string
333 */
334 function file($path, $return = FALSE)
335 {
336 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
337 }
Barry Mienydd671972010-10-04 16:33:58 +0200338
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200340
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 /**
342 * Set Variables
343 *
344 * Once variables are set they become available within
345 * the controller class and its "view" files.
346 *
347 * @access public
348 * @param array
349 * @return void
350 */
351 function vars($vars = array(), $val = '')
352 {
353 if ($val != '' AND is_string($vars))
354 {
355 $vars = array($vars => $val);
356 }
Barry Mienydd671972010-10-04 16:33:58 +0200357
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 $vars = $this->_ci_object_to_array($vars);
Barry Mienydd671972010-10-04 16:33:58 +0200359
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 if (is_array($vars) AND count($vars) > 0)
361 {
362 foreach ($vars as $key => $val)
363 {
364 $this->_ci_cached_vars[$key] = $val;
365 }
366 }
367 }
Barry Mienydd671972010-10-04 16:33:58 +0200368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200370
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 /**
372 * Load Helper
373 *
374 * This function loads the specified helper file.
375 *
376 * @access public
377 * @param mixed
378 * @return void
379 */
380 function helper($helpers = array())
Barry Mienydd671972010-10-04 16:33:58 +0200381 {
Derek Jones32bf1862010-03-02 13:46:07 -0600382 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
Barry Mienydd671972010-10-04 16:33:58 +0200383 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 if (isset($this->_ci_helpers[$helper]))
385 {
386 continue;
387 }
Derek Jones32bf1862010-03-02 13:46:07 -0600388
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.EXT;
390
Barry Mienydd671972010-10-04 16:33:58 +0200391 // Is this a helper extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 if (file_exists($ext_helper))
393 {
394 $base_helper = BASEPATH.'helpers/'.$helper.EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200395
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 if ( ! file_exists($base_helper))
397 {
398 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 include_once($ext_helper);
402 include_once($base_helper);
Barry Mienydd671972010-10-04 16:33:58 +0200403
Derek Jones32bf1862010-03-02 13:46:07 -0600404 $this->_ci_helpers[$helper] = TRUE;
405 log_message('debug', 'Helper loaded: '.$helper);
406 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 }
Barry Mienydd671972010-10-04 16:33:58 +0200408
Derek Jones32bf1862010-03-02 13:46:07 -0600409 // Try to load the helper
410 foreach ($this->_ci_helper_paths as $path)
411 {
412 if (file_exists($path.'helpers/'.$helper.EXT))
Barry Mienydd671972010-10-04 16:33:58 +0200413 {
Derek Jones32bf1862010-03-02 13:46:07 -0600414 include_once($path.'helpers/'.$helper.EXT);
415
416 $this->_ci_helpers[$helper] = TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200417 log_message('debug', 'Helper loaded: '.$helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600418 break;
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 }
420 }
421
Derek Jones32bf1862010-03-02 13:46:07 -0600422 // unable to load the helper
423 if ( ! isset($this->_ci_helpers[$helper]))
424 {
Barry Mienydd671972010-10-04 16:33:58 +0200425 show_error('Unable to load the requested file: helpers/'.$helper.EXT);
Derek Jones32bf1862010-03-02 13:46:07 -0600426 }
Barry Mienydd671972010-10-04 16:33:58 +0200427 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 }
Barry Mienydd671972010-10-04 16:33:58 +0200429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200431
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 /**
433 * Load Helpers
434 *
435 * This is simply an alias to the above function in case the
436 * user has written the plural form of this function.
437 *
438 * @access public
439 * @param array
440 * @return void
441 */
442 function helpers($helpers = array())
443 {
444 $this->helper($helpers);
445 }
Barry Mienydd671972010-10-04 16:33:58 +0200446
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200448
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 * Loads a language file
451 *
452 * @access public
453 * @param array
454 * @param string
455 * @return void
456 */
457 function language($file = array(), $lang = '')
458 {
459 $CI =& get_instance();
460
461 if ( ! is_array($file))
462 {
463 $file = array($file);
464 }
465
466 foreach ($file as $langfile)
Barry Mienydd671972010-10-04 16:33:58 +0200467 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 $CI->lang->load($langfile, $lang);
469 }
470 }
Barry Mienydd671972010-10-04 16:33:58 +0200471
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 /**
475 * Loads a config file
476 *
477 * @access public
478 * @param string
479 * @return void
480 */
481 function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200482 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 $CI =& get_instance();
484 $CI->config->load($file, $use_sections, $fail_gracefully);
485 }
486
487 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600488
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 /**
Derek Jones8dca0412010-03-05 13:01:44 -0600490 * Driver
491 *
492 * Loads a driver library
493 *
494 * @param string the name of the class
495 * @param mixed the optional parameters
496 * @param string an optional object name
497 * @return void
498 */
499 function driver($library = '', $params = NULL, $object_name = NULL)
500 {
501 if ( ! class_exists('CI_Driver_Library'))
502 {
503 // we aren't instantiating an object here, that'll be done by the Library itself
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600504 require BASEPATH.'libraries/Driver'.EXT;
505 }
Barry Mienydd671972010-10-04 16:33:58 +0200506
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600507 // We can save the loader some time since Drivers will *always* be in a subfolder,
508 // and typically identically named to the library
509 if ( ! strpos($library, '/'))
510 {
Greg Akerd25e66a2010-03-28 01:07:09 -0500511 $library = ucfirst($library).'/'.$library;
Derek Jones8dca0412010-03-05 13:01:44 -0600512 }
Barry Mienydd671972010-10-04 16:33:58 +0200513
Derek Jones8dca0412010-03-05 13:01:44 -0600514 return $this->library($library, $params, $object_name);
515 }
516
517 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Jones8dca0412010-03-05 13:01:44 -0600519 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600520 * Add Package Path
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 *
Derek Jones32bf1862010-03-02 13:46:07 -0600522 * Prepends a parent path to the library, model, helper, and config path arrays
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 *
524 * @access public
525 * @param string
526 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600527 */
528 function add_package_path($path)
529 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500530 $path = rtrim($path, '/').'/';
531
Derek Jones32bf1862010-03-02 13:46:07 -0600532 array_unshift($this->_ci_library_paths, $path);
533 array_unshift($this->_ci_model_paths, $path);
534 array_unshift($this->_ci_helper_paths, $path);
Barry Mienydd671972010-10-04 16:33:58 +0200535
Derek Jones32bf1862010-03-02 13:46:07 -0600536 // Add config file path
537 $config =& $this->_ci_get_component('config');
538 array_unshift($config->_config_paths, $path);
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 }
540
541 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600542
543 /**
544 * Remove Package Path
545 *
546 * Remove a path from the library, model, and helper path arrays if it exists
547 * If no path is provided, the most recently added path is removed.
548 *
549 * @access public
550 * @param type
551 * @return type
552 */
553 function remove_package_path($path = '', $remove_config_path = TRUE)
554 {
555 $config =& $this->_ci_get_component('config');
Barry Mienydd671972010-10-04 16:33:58 +0200556
Derek Jones32bf1862010-03-02 13:46:07 -0600557 if ($path == '')
558 {
559 $void = array_shift($this->_ci_library_paths);
560 $void = array_shift($this->_ci_model_paths);
561 $void = array_shift($this->_ci_helper_paths);
562 $void = array_shift($config->_config_paths);
563 }
564 else
565 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500566 $path = rtrim($path, '/').'/';
567
Derek Jones32bf1862010-03-02 13:46:07 -0600568 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
569 {
570 if (($key = array_search($path, $this->{$var})) !== FALSE)
571 {
572 unset($this->{$var}[$key]);
573 }
574 }
Barry Mienydd671972010-10-04 16:33:58 +0200575
Derek Jones32bf1862010-03-02 13:46:07 -0600576 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
577 {
578 unset($config->_config_paths[$key]);
579 }
580 }
Barry Mienydd671972010-10-04 16:33:58 +0200581
Derek Jones32bf1862010-03-02 13:46:07 -0600582 // make sure the application default paths are still in the array
583 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
584 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
585 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
586 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
587 }
588
589 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200590
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 /**
592 * Loader
593 *
594 * This function is used to load views and files.
595 * Variables are prefixed with _ci_ to avoid symbol collision with
596 * variables made available to view files
597 *
598 * @access private
599 * @param array
600 * @return void
601 */
602 function _ci_load($_ci_data)
603 {
604 // Set the default data variables
605 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
606 {
607 $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val];
608 }
609
610 // Set the path to the requested file
611 if ($_ci_path == '')
612 {
613 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
614 $_ci_file = ($_ci_ext == '') ? $_ci_view.EXT : $_ci_view;
615 $_ci_path = $this->_ci_view_path.$_ci_file;
616 }
617 else
618 {
619 $_ci_x = explode('/', $_ci_path);
620 $_ci_file = end($_ci_x);
621 }
Barry Mienydd671972010-10-04 16:33:58 +0200622
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 if ( ! file_exists($_ci_path))
624 {
625 show_error('Unable to load the requested file: '.$_ci_file);
626 }
Barry Mienydd671972010-10-04 16:33:58 +0200627
Derek Allard2067d1a2008-11-13 22:59:24 +0000628 // This allows anything loaded using $this->load (views, files, etc.)
629 // to become accessible from within the Controller and Model functions.
630 // Only needed when running PHP 5
Barry Mienydd671972010-10-04 16:33:58 +0200631
Derek Allard2067d1a2008-11-13 22:59:24 +0000632 if ($this->_ci_is_instance())
633 {
634 $_ci_CI =& get_instance();
635 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
636 {
637 if ( ! isset($this->$_ci_key))
638 {
639 $this->$_ci_key =& $_ci_CI->$_ci_key;
640 }
641 }
642 }
643
644 /*
645 * Extract and cache variables
646 *
647 * You can either set variables using the dedicated $this->load_vars()
648 * function or via the second parameter of this function. We'll merge
649 * the two types and cache them so that views that are embedded within
650 * other views can have access to these variables.
Barry Mienydd671972010-10-04 16:33:58 +0200651 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000652 if (is_array($_ci_vars))
653 {
654 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
655 }
656 extract($this->_ci_cached_vars);
Barry Mienydd671972010-10-04 16:33:58 +0200657
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 /*
659 * Buffer the output
660 *
661 * We buffer the output for two reasons:
662 * 1. Speed. You get a significant speed boost.
663 * 2. So that the final rendered template can be
664 * post-processed by the output class. Why do we
665 * need post processing? For one thing, in order to
666 * show the elapsed page load time. Unless we
667 * can intercept the content right before it's sent to
668 * the browser and then stop the timer it won't be accurate.
669 */
670 ob_start();
Barry Mienydd671972010-10-04 16:33:58 +0200671
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 // If the PHP installation does not support short tags we'll
673 // do a little string replacement, changing the short tags
674 // to standard PHP echo statements.
Barry Mienydd671972010-10-04 16:33:58 +0200675
Derek Allard2067d1a2008-11-13 22:59:24 +0000676 if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE)
677 {
678 echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
679 }
680 else
681 {
682 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
683 }
Barry Mienydd671972010-10-04 16:33:58 +0200684
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 log_message('debug', 'File loaded: '.$_ci_path);
Barry Mienydd671972010-10-04 16:33:58 +0200686
Derek Allard2067d1a2008-11-13 22:59:24 +0000687 // Return the file data if requested
688 if ($_ci_return === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200689 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000690 $buffer = ob_get_contents();
691 @ob_end_clean();
692 return $buffer;
693 }
694
695 /*
696 * Flush the buffer... or buff the flusher?
697 *
698 * In order to permit views to be nested within
699 * other views, we need to flush the content back out whenever
700 * we are beyond the first level of output buffering so that
701 * it can be seen and included properly by the first included
702 * template and any subsequent ones. Oy!
703 *
Barry Mienydd671972010-10-04 16:33:58 +0200704 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000705 if (ob_get_level() > $this->_ci_ob_level + 1)
706 {
707 ob_end_flush();
708 }
709 else
710 {
711 // PHP 4 requires that we use a global
712 global $OUT;
713 $OUT->append_output(ob_get_contents());
714 @ob_end_clean();
715 }
716 }
717
718 // --------------------------------------------------------------------
719
720 /**
721 * Load class
722 *
723 * This function loads the requested class.
724 *
725 * @access private
Barry Mienydd671972010-10-04 16:33:58 +0200726 * @param string the item that is being loaded
Derek Allard2067d1a2008-11-13 22:59:24 +0000727 * @param mixed any additional parameters
728 * @param string an optional object name
Barry Mienydd671972010-10-04 16:33:58 +0200729 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000730 */
731 function _ci_load_class($class, $params = NULL, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200732 {
733 // Get the class name, and while we're at it trim any slashes.
734 // The directory path can be included as part of the class name,
Derek Allard2067d1a2008-11-13 22:59:24 +0000735 // but we don't want a leading slash
736 $class = str_replace(EXT, '', trim($class, '/'));
Barry Mienydd671972010-10-04 16:33:58 +0200737
Derek Allard2067d1a2008-11-13 22:59:24 +0000738 // Was the path included with the class name?
739 // We look for a slash to determine this
740 $subdir = '';
Derek Jones32bf1862010-03-02 13:46:07 -0600741 if (($last_slash = strrpos($class, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000742 {
Derek Jones32bf1862010-03-02 13:46:07 -0600743 // Extract the path
744 $subdir = substr($class, 0, $last_slash + 1);
Barry Mienydd671972010-10-04 16:33:58 +0200745
Derek Jones32bf1862010-03-02 13:46:07 -0600746 // Get the filename from the path
747 $class = substr($class, $last_slash + 1);
Derek Allard2067d1a2008-11-13 22:59:24 +0000748 }
749
750 // We'll test for both lowercase and capitalized versions of the file name
751 foreach (array(ucfirst($class), strtolower($class)) as $class)
752 {
753 $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.EXT;
754
Barry Mienydd671972010-10-04 16:33:58 +0200755 // Is this a class extension request?
Derek Allard2067d1a2008-11-13 22:59:24 +0000756 if (file_exists($subclass))
757 {
758 $baseclass = BASEPATH.'libraries/'.ucfirst($class).EXT;
Barry Mienydd671972010-10-04 16:33:58 +0200759
Derek Allard2067d1a2008-11-13 22:59:24 +0000760 if ( ! file_exists($baseclass))
761 {
762 log_message('error', "Unable to load the requested class: ".$class);
763 show_error("Unable to load the requested class: ".$class);
764 }
765
766 // Safety: Was the class already loaded by a previous call?
767 if (in_array($subclass, $this->_ci_loaded_files))
768 {
769 // Before we deem this to be a duplicate request, let's see
770 // if a custom object name is being supplied. If so, we'll
771 // return a new instance of the object
772 if ( ! is_null($object_name))
773 {
774 $CI =& get_instance();
775 if ( ! isset($CI->$object_name))
776 {
Barry Mienydd671972010-10-04 16:33:58 +0200777 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000778 }
779 }
Barry Mienydd671972010-10-04 16:33:58 +0200780
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 $is_duplicate = TRUE;
782 log_message('debug', $class." class already loaded. Second attempt ignored.");
783 return;
784 }
Barry Mienydd671972010-10-04 16:33:58 +0200785
786 include_once($baseclass);
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 include_once($subclass);
788 $this->_ci_loaded_files[] = $subclass;
Barry Mienydd671972010-10-04 16:33:58 +0200789
790 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000791 }
Barry Mienydd671972010-10-04 16:33:58 +0200792
Derek Allard2067d1a2008-11-13 22:59:24 +0000793 // Lets search for the requested library file and load it.
Derek Jones32bf1862010-03-02 13:46:07 -0600794 $is_duplicate = FALSE;
795 foreach ($this->_ci_library_paths as $path)
Derek Allard2067d1a2008-11-13 22:59:24 +0000796 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000797 $filepath = $path.'libraries/'.$subdir.$class.EXT;
Derek Jones32bf1862010-03-02 13:46:07 -0600798
Derek Allard2067d1a2008-11-13 22:59:24 +0000799 // Does the file exist? No? Bummer...
800 if ( ! file_exists($filepath))
801 {
802 continue;
803 }
Barry Mienydd671972010-10-04 16:33:58 +0200804
Derek Allard2067d1a2008-11-13 22:59:24 +0000805 // Safety: Was the class already loaded by a previous call?
806 if (in_array($filepath, $this->_ci_loaded_files))
807 {
808 // Before we deem this to be a duplicate request, let's see
809 // if a custom object name is being supplied. If so, we'll
810 // return a new instance of the object
811 if ( ! is_null($object_name))
812 {
813 $CI =& get_instance();
814 if ( ! isset($CI->$object_name))
815 {
816 return $this->_ci_init_class($class, '', $params, $object_name);
817 }
818 }
Barry Mienydd671972010-10-04 16:33:58 +0200819
Derek Allard2067d1a2008-11-13 22:59:24 +0000820 $is_duplicate = TRUE;
821 log_message('debug', $class." class already loaded. Second attempt ignored.");
822 return;
823 }
Barry Mienydd671972010-10-04 16:33:58 +0200824
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 include_once($filepath);
826 $this->_ci_loaded_files[] = $filepath;
Barry Mienydd671972010-10-04 16:33:58 +0200827 return $this->_ci_init_class($class, '', $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000828 }
Derek Jones32bf1862010-03-02 13:46:07 -0600829
Derek Allard2067d1a2008-11-13 22:59:24 +0000830 } // END FOREACH
831
832 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
833 if ($subdir == '')
834 {
835 $path = strtolower($class).'/'.$class;
836 return $this->_ci_load_class($path, $params);
837 }
Barry Mienydd671972010-10-04 16:33:58 +0200838
Derek Allard2067d1a2008-11-13 22:59:24 +0000839 // If we got this far we were unable to find the requested class.
840 // We do not issue errors if the load call failed due to a duplicate request
841 if ($is_duplicate == FALSE)
842 {
843 log_message('error', "Unable to load the requested class: ".$class);
844 show_error("Unable to load the requested class: ".$class);
845 }
846 }
Barry Mienydd671972010-10-04 16:33:58 +0200847
Derek Allard2067d1a2008-11-13 22:59:24 +0000848 // --------------------------------------------------------------------
849
850 /**
851 * Instantiates a class
852 *
853 * @access private
854 * @param string
855 * @param string
856 * @param string an optional object name
857 * @return null
858 */
859 function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200860 {
Derek Jones32bf1862010-03-02 13:46:07 -0600861 // Is there an associated config file for this class? Note: these should always be lowercase
Derek Allard2067d1a2008-11-13 22:59:24 +0000862 if ($config === NULL)
863 {
864 // We test for both uppercase and lowercase, for servers that
865 // are case-sensitive with regard to file names
866 if (file_exists(APPPATH.'config/'.strtolower($class).EXT))
867 {
868 include_once(APPPATH.'config/'.strtolower($class).EXT);
Barry Mienydd671972010-10-04 16:33:58 +0200869 }
Derek Jonesc8dddd92009-07-10 18:58:03 +0000870 elseif (file_exists(APPPATH.'config/'.ucfirst(strtolower($class)).EXT))
Derek Allard2067d1a2008-11-13 22:59:24 +0000871 {
Derek Jonesc8dddd92009-07-10 18:58:03 +0000872 include_once(APPPATH.'config/'.ucfirst(strtolower($class)).EXT);
Derek Allard2067d1a2008-11-13 22:59:24 +0000873 }
874 }
Barry Mienydd671972010-10-04 16:33:58 +0200875
Derek Allard2067d1a2008-11-13 22:59:24 +0000876 if ($prefix == '')
Barry Mienydd671972010-10-04 16:33:58 +0200877 {
878 if (class_exists('CI_'.$class))
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 {
880 $name = 'CI_'.$class;
881 }
Barry Mienydd671972010-10-04 16:33:58 +0200882 elseif (class_exists(config_item('subclass_prefix').$class))
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 {
884 $name = config_item('subclass_prefix').$class;
885 }
886 else
887 {
888 $name = $class;
889 }
890 }
891 else
892 {
893 $name = $prefix.$class;
894 }
Barry Mienydd671972010-10-04 16:33:58 +0200895
Derek Allard2067d1a2008-11-13 22:59:24 +0000896 // Is the class name valid?
897 if ( ! class_exists($name))
898 {
899 log_message('error', "Non-existent class: ".$name);
900 show_error("Non-existent class: ".$class);
901 }
Barry Mienydd671972010-10-04 16:33:58 +0200902
Derek Allard2067d1a2008-11-13 22:59:24 +0000903 // Set the variable name we will assign the class to
904 // Was a custom class name supplied? If so we'll use it
905 $class = strtolower($class);
Barry Mienydd671972010-10-04 16:33:58 +0200906
Derek Allard2067d1a2008-11-13 22:59:24 +0000907 if (is_null($object_name))
908 {
909 $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
910 }
911 else
912 {
913 $classvar = $object_name;
914 }
915
Barry Mienydd671972010-10-04 16:33:58 +0200916 // Save the class name and object name
Derek Allard2067d1a2008-11-13 22:59:24 +0000917 $this->_ci_classes[$class] = $classvar;
918
Barry Mienydd671972010-10-04 16:33:58 +0200919 // Instantiate the class
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 $CI =& get_instance();
921 if ($config !== NULL)
922 {
923 $CI->$classvar = new $name($config);
924 }
925 else
Barry Mienydd671972010-10-04 16:33:58 +0200926 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 $CI->$classvar = new $name;
Barry Mienydd671972010-10-04 16:33:58 +0200928 }
929 }
930
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200932
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 /**
934 * Autoloader
935 *
936 * The config/autoload.php file contains an array that permits sub-systems,
Derek Jonesc6da5032010-03-09 20:44:27 -0600937 * libraries, and helpers to be loaded automatically.
Derek Allard2067d1a2008-11-13 22:59:24 +0000938 *
939 * @access private
940 * @param array
941 * @return void
942 */
943 function _ci_autoloader()
Barry Mienydd671972010-10-04 16:33:58 +0200944 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000945 include_once(APPPATH.'config/autoload'.EXT);
Barry Mienydd671972010-10-04 16:33:58 +0200946
Derek Allard2067d1a2008-11-13 22:59:24 +0000947 if ( ! isset($autoload))
948 {
949 return FALSE;
950 }
Barry Mienydd671972010-10-04 16:33:58 +0200951
Derek Allard2067d1a2008-11-13 22:59:24 +0000952 // Load any custom config file
953 if (count($autoload['config']) > 0)
Barry Mienydd671972010-10-04 16:33:58 +0200954 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 $CI =& get_instance();
956 foreach ($autoload['config'] as $key => $val)
957 {
958 $CI->config->load($val);
959 }
Barry Mienydd671972010-10-04 16:33:58 +0200960 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000961
Derek Jonesc6da5032010-03-09 20:44:27 -0600962 // Autoload helpers and languages
963 foreach (array('helper', 'language') as $type)
Barry Mienydd671972010-10-04 16:33:58 +0200964 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000965 if (isset($autoload[$type]) AND count($autoload[$type]) > 0)
966 {
967 $this->$type($autoload[$type]);
Barry Mienydd671972010-10-04 16:33:58 +0200968 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000969 }
970
971 // A little tweak to remain backward compatible
972 // The $autoload['core'] item was deprecated
Derek Jones32bf1862010-03-02 13:46:07 -0600973 if ( ! isset($autoload['libraries']) AND isset($autoload['core']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000974 {
975 $autoload['libraries'] = $autoload['core'];
976 }
Barry Mienydd671972010-10-04 16:33:58 +0200977
Derek Allard2067d1a2008-11-13 22:59:24 +0000978 // Load libraries
979 if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0)
980 {
981 // Load the database driver.
982 if (in_array('database', $autoload['libraries']))
983 {
984 $this->database();
985 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
986 }
Barry Mienydd671972010-10-04 16:33:58 +0200987
Derek Allard2067d1a2008-11-13 22:59:24 +0000988 // Load all other libraries
989 foreach ($autoload['libraries'] as $item)
990 {
991 $this->library($item);
992 }
Barry Mienydd671972010-10-04 16:33:58 +0200993 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000994
995 // Autoload models
996 if (isset($autoload['model']))
997 {
998 $this->model($autoload['model']);
999 }
Barry Mienydd671972010-10-04 16:33:58 +02001000 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001001
1002 // --------------------------------------------------------------------
1003
1004 /**
1005 * Object to Array
1006 *
1007 * Takes an object as input and converts the class variables to array key/vals
1008 *
1009 * @access private
1010 * @param object
1011 * @return array
1012 */
1013 function _ci_object_to_array($object)
1014 {
1015 return (is_object($object)) ? get_object_vars($object) : $object;
1016 }
1017
1018 // --------------------------------------------------------------------
1019
1020 /**
1021 * Determines whether we should use the CI instance or $this
Derek Jones32bf1862010-03-02 13:46:07 -06001022 * @PHP4
Barry Mienydd671972010-10-04 16:33:58 +02001023 *
Derek Allard2067d1a2008-11-13 22:59:24 +00001024 * @access private
1025 * @return bool
1026 */
1027 function _ci_is_instance()
1028 {
Derek Jones32bf1862010-03-02 13:46:07 -06001029 if (is_php('5.0.0') == TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001030 {
1031 return TRUE;
1032 }
Barry Mienydd671972010-10-04 16:33:58 +02001033
Derek Allard2067d1a2008-11-13 22:59:24 +00001034 global $CI;
1035 return (is_object($CI)) ? TRUE : FALSE;
1036 }
Barry Mienydd671972010-10-04 16:33:58 +02001037
Derek Jones32bf1862010-03-02 13:46:07 -06001038 // --------------------------------------------------------------------
1039
1040 /**
1041 * Get a reference to a specific library or model
1042 *
1043 * @access private
1044 * @return bool
1045 */
1046 function &_ci_get_component($component)
1047 {
1048 if ($this->_ci_is_instance())
1049 {
1050 $CI =& get_instance();
1051 return $CI->$component;
1052 }
1053 else
1054 {
1055 return $this->$component;
1056 }
1057 }
1058
1059 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001060
Derek Jones32bf1862010-03-02 13:46:07 -06001061 /**
1062 * Prep filename
1063 *
1064 * This function preps the name of various items to make loading them more reliable.
1065 *
1066 * @access private
1067 * @param mixed
1068 * @return array
1069 */
1070 function _ci_prep_filename($filename, $extension)
1071 {
1072 if ( ! is_array($filename))
Barry Mienydd671972010-10-04 16:33:58 +02001073 {
1074 return array(strtolower(str_replace(EXT, '', str_replace($extension, '', $filename)).$extension));
Derek Jones32bf1862010-03-02 13:46:07 -06001075 }
1076 else
1077 {
1078 foreach ($filename as $key => $val)
1079 {
Barry Mienydd671972010-10-04 16:33:58 +02001080 $filename[$key] = strtolower(str_replace(EXT, '', str_replace($extension, '', $val)).$extension);
Derek Jones32bf1862010-03-02 13:46:07 -06001081 }
Barry Mienydd671972010-10-04 16:33:58 +02001082
Derek Jones32bf1862010-03-02 13:46:07 -06001083 return $filename;
1084 }
1085 }
Barry Mienydd671972010-10-04 16:33:58 +02001086
Derek Allard2067d1a2008-11-13 22:59:24 +00001087
1088}
1089
1090/* End of file Loader.php */
Derek Jonesc68dfbf2010-03-02 12:59:23 -06001091/* Location: ./system/core/Loader.php */