blob: e5829ca809f2fbdd2b3a84a096842911fb7ee1ca [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreevd7297352012-01-07 22:53:14 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevd7297352012-01-07 22:53:14 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
Derek Allard2067d1a2008-11-13 22:59:24 +000018 *
19 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
Derek Allard2067d1a2008-11-13 22:59:24 +000029/**
30 * Loader Class
31 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030032 * Loads framework components.
Derek Allard2067d1a2008-11-13 22:59:24 +000033 *
34 * @package CodeIgniter
35 * @subpackage Libraries
Derek Allard2067d1a2008-11-13 22:59:24 +000036 * @category Loader
Andrey Andreev92ebfb62012-05-17 12:49:24 +030037 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000038 * @link http://codeigniter.com/user_guide/libraries/loader.html
39 */
40class CI_Loader {
41
42 // All these are set automatically. Don't mess with them.
David Behlercda768a2011-08-14 23:52:48 +020043 /**
44 * Nesting level of the output buffering mechanism
45 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030046 * @var int
David Behlercda768a2011-08-14 23:52:48 +020047 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -050048 protected $_ci_ob_level;
Andrey Andreev92ebfb62012-05-17 12:49:24 +030049
David Behlercda768a2011-08-14 23:52:48 +020050 /**
51 * List of paths to load views from
52 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030053 * @var array
David Behlercda768a2011-08-14 23:52:48 +020054 */
Ted Wood4c223642013-01-05 16:50:31 -080055 protected $_ci_view_paths = array(VIEWPATH => TRUE);
Andrey Andreev92ebfb62012-05-17 12:49:24 +030056
David Behlercda768a2011-08-14 23:52:48 +020057 /**
58 * List of paths to load libraries from
59 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030060 * @var array
David Behlercda768a2011-08-14 23:52:48 +020061 */
Ted Wood4c223642013-01-05 16:50:31 -080062 protected $_ci_library_paths = array(APPPATH, BASEPATH);
Andrey Andreev92ebfb62012-05-17 12:49:24 +030063
David Behlercda768a2011-08-14 23:52:48 +020064 /**
65 * List of paths to load models from
66 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030067 * @var array
David Behlercda768a2011-08-14 23:52:48 +020068 */
Ted Wood4c223642013-01-05 16:50:31 -080069 protected $_ci_model_paths = array(APPPATH);
Andrey Andreev92ebfb62012-05-17 12:49:24 +030070
David Behlercda768a2011-08-14 23:52:48 +020071 /**
72 * List of paths to load helpers from
73 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030074 * @var array
David Behlercda768a2011-08-14 23:52:48 +020075 */
Ted Wood4c223642013-01-05 16:50:31 -080076 protected $_ci_helper_paths = array(APPPATH, BASEPATH);
Andrey Andreev92ebfb62012-05-17 12:49:24 +030077
David Behlercda768a2011-08-14 23:52:48 +020078 /**
David Behlercda768a2011-08-14 23:52:48 +020079 * List of cached variables
80 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030081 * @var array
David Behlercda768a2011-08-14 23:52:48 +020082 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040083 protected $_ci_cached_vars = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030084
David Behlercda768a2011-08-14 23:52:48 +020085 /**
86 * List of loaded classes
87 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030088 * @var array
David Behlercda768a2011-08-14 23:52:48 +020089 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040090 protected $_ci_classes = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030091
David Behlercda768a2011-08-14 23:52:48 +020092 /**
David Behlercda768a2011-08-14 23:52:48 +020093 * List of loaded models
94 *
Andrey Andreeved4b2582012-10-27 17:46:52 +030095 * @var array
David Behlercda768a2011-08-14 23:52:48 +020096 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -040097 protected $_ci_models = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +030098
David Behlercda768a2011-08-14 23:52:48 +020099 /**
100 * List of loaded helpers
101 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300102 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200103 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400104 protected $_ci_helpers = array();
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300105
David Behlercda768a2011-08-14 23:52:48 +0200106 /**
107 * List of class name mappings
108 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300109 * @var array
David Behlercda768a2011-08-14 23:52:48 +0200110 */
Timothy Warren48a7fbb2012-04-23 11:58:16 -0400111 protected $_ci_varmap = array(
Timothy Warren40403d22012-04-19 16:38:50 -0400112 'unit_test' => 'unit',
113 'user_agent' => 'agent'
114 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000115
Andrey Andreev519f87a2013-07-23 17:16:10 +0300116 // --------------------------------------------------------------------
117
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300119 * Class constructor
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 *
Andrey Andreevcdac2482012-11-03 18:09:01 +0200121 * Sets component load paths, gets the initial output buffering level.
Andrey Andreev92ebfb62012-05-17 12:49:24 +0300122 *
123 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 */
Greg Akerf5c84022011-04-19 17:13:03 -0500125 public function __construct()
Barry Mienydd671972010-10-04 16:33:58 +0200126 {
Andrey Andreev519f87a2013-07-23 17:16:10 +0300127 $this->_ci_ob_level = ob_get_level();
128 $this->_ci_classes =& is_loaded();
David Behlercda768a2011-08-14 23:52:48 +0200129
Andrey Andreevd7297352012-01-07 22:53:14 +0200130 log_message('debug', 'Loader Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 }
Barry Mienydd671972010-10-04 16:33:58 +0200132
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 // --------------------------------------------------------------------
David Behlercda768a2011-08-14 23:52:48 +0200134
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500135 /**
Andrey Andreevcdac2482012-11-03 18:09:01 +0200136 * Initializer
137 *
138 * @todo Figure out a way to move this to the constructor
139 * without breaking *package_path*() methods.
140 * @uses CI_Loader::_ci_autoloader()
141 * @used-by CI_Controller::__construct()
142 * @return void
143 */
144 public function initialize()
145 {
Andrey Andreevcdac2482012-11-03 18:09:01 +0200146 $this->_ci_autoloader();
147 }
148
149 // --------------------------------------------------------------------
150
151 /**
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500152 * Is Loaded
153 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300154 * A utility method to test if a class is in the self::$_ci_classes array.
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500155 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300156 * @used-by Mainly used by Form Helper function _get_validation_object().
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500157 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300158 * @param string $class Class name to check for
159 * @return string|bool Class object name if loaded or FALSE
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500160 */
161 public function is_loaded($class)
162 {
Andrey Andreev519f87a2013-07-23 17:16:10 +0300163 return array_search(ucfirst($class), $this->_ci_classes, TRUE);
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500164 }
165
166 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200167
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300169 * Library Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300171 * Loads and instantiates libraries.
172 * Designed to be called from application controllers.
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300174 * @param string $library Library name
175 * @param array $params Optional parameters to pass to the library class constructor
176 * @param string $object_name An optional object name to assign to
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200178 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -0500179 public function library($library = '', $params = NULL, $object_name = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 {
Andrey Andreev519f87a2013-07-23 17:16:10 +0300181 if (empty($library))
182 {
183 return;
184 }
185 elseif (is_array($library))
Greg Akerce433962010-10-12 09:29:35 -0500186 {
Phil Sturgeon08b51692011-04-03 18:05:42 +0100187 foreach ($library as $class)
Greg Akerce433962010-10-12 09:29:35 -0500188 {
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600189 $this->library($class, $params);
Greg Akerce433962010-10-12 09:29:35 -0500190 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000191
Greg Akerce433962010-10-12 09:29:35 -0500192 return;
193 }
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000194
vlakoff1228fe22013-01-14 01:30:09 +0100195 if ($params !== NULL && ! is_array($params))
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 {
197 $params = NULL;
198 }
199
Kellas Reeves3c6e4852011-02-09 11:57:56 -0600200 $this->_ci_load_class($library, $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 }
202
203 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200204
Derek Allard2067d1a2008-11-13 22:59:24 +0000205 /**
206 * Model Loader
207 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300208 * Loads and instantiates libraries.
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300210 * @param string $model Model name
211 * @param string $name An optional object name to assign to
212 * @param bool $db_conn An optional database connection configuration to initialize
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 * @return void
Barry Mienydd671972010-10-04 16:33:58 +0200214 */
Greg Akerf5c84022011-04-19 17:13:03 -0500215 public function model($model, $name = '', $db_conn = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200216 {
Andrey Andreeved4b2582012-10-27 17:46:52 +0300217 if (empty($model))
218 {
219 return;
220 }
221 elseif (is_array($model))
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 {
Andrey Andreev5a519db2013-01-12 04:19:19 +0200223 foreach ($model as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 {
Ahmad Anbar4005e3c2013-09-12 23:33:28 +0300225 is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn);
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 }
227 return;
228 }
229
Derek Jones32bf1862010-03-02 13:46:07 -0600230 $path = '';
Barry Mienydd671972010-10-04 16:33:58 +0200231
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 // Is the model in a sub-folder? If so, parse out the filename and path.
Derek Jones32bf1862010-03-02 13:46:07 -0600233 if (($last_slash = strrpos($model, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 {
Derek Jones32bf1862010-03-02 13:46:07 -0600235 // The path is in front of the last slash
Andrey Andreevd47baab2012-01-09 16:56:46 +0200236 $path = substr($model, 0, ++$last_slash);
Derek Jones32bf1862010-03-02 13:46:07 -0600237
238 // And the model name behind it
Andrey Andreevd47baab2012-01-09 16:56:46 +0200239 $model = substr($model, $last_slash);
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 }
Barry Mienydd671972010-10-04 16:33:58 +0200241
Phil Sturgeon10d78f62012-06-04 14:41:53 -0500242 if (empty($name))
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 {
244 $name = $model;
245 }
Barry Mienydd671972010-10-04 16:33:58 +0200246
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 if (in_array($name, $this->_ci_models, TRUE))
248 {
249 return;
250 }
Barry Mienydd671972010-10-04 16:33:58 +0200251
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 $CI =& get_instance();
253 if (isset($CI->$name))
254 {
255 show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
256 }
Barry Mienydd671972010-10-04 16:33:58 +0200257
Andrey Andreev20292312013-07-22 14:29:10 +0300258 if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE))
259 {
260 if ($db_conn === TRUE)
261 {
262 $db_conn = '';
263 }
264
265 $CI->load->database($db_conn, FALSE, TRUE);
266 }
267
268 if ( ! class_exists('CI_Model', FALSE))
269 {
270 load_class('Model', 'core');
271 }
272
273 $model = ucfirst(strtolower($model));
Derek Allard2067d1a2008-11-13 22:59:24 +0000274
Derek Jones32bf1862010-03-02 13:46:07 -0600275 foreach ($this->_ci_model_paths as $mod_path)
276 {
Greg Aker3a746652011-04-19 10:59:47 -0500277 if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
Derek Jones32bf1862010-03-02 13:46:07 -0600278 {
279 continue;
280 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000281
Greg Aker3a746652011-04-19 10:59:47 -0500282 require_once($mod_path.'models/'.$path.$model.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600283
Derek Jones32bf1862010-03-02 13:46:07 -0600284 $CI->$name = new $model();
Derek Jones32bf1862010-03-02 13:46:07 -0600285 $this->_ci_models[] = $name;
286 return;
287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Jones32bf1862010-03-02 13:46:07 -0600289 // couldn't find the model
290 show_error('Unable to locate the model you have specified: '.$model);
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 }
Barry Mienydd671972010-10-04 16:33:58 +0200292
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200294
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 /**
296 * Database Loader
297 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300298 * @param mixed $params Database configuration options
299 * @param bool $return Whether to return the database object
300 * @param bool $query_builder Whether to enable Query Builder
301 * (overrides the configuration setting)
302 *
303 * @return void|object|bool Database object if $return is set to TRUE,
304 * FALSE on failure, void in any other case
Barry Mienydd671972010-10-04 16:33:58 +0200305 */
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000306 public function database($params = '', $return = FALSE, $query_builder = NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 {
308 // Grab the super object
309 $CI =& get_instance();
Barry Mienydd671972010-10-04 16:33:58 +0200310
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 // Do we even need to load the database class?
Andrey Andreev9d0ab042012-10-24 21:47:39 +0300312 if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id))
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 {
314 return FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200315 }
316
Greg Aker3a746652011-04-19 10:59:47 -0500317 require_once(BASEPATH.'database/DB.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000318
319 if ($return === TRUE)
320 {
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000321 return DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Andrey Andreevd7297352012-01-07 22:53:14 +0200324 // Initialize the db variable. Needed to prevent
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 // reference errors with some configurations
326 $CI->db = '';
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 // Load the DB class
Jamie Rumbelow7efad202012-02-19 12:37:00 +0000329 $CI->db =& DB($params, $query_builder);
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 }
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 // --------------------------------------------------------------------
333
334 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300335 * Load the Database Utilities Class
Derek Allard2067d1a2008-11-13 22:59:24 +0000336 *
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200337 * @param object $db Database object
338 * @param bool $return Whether to return the DB Forge class object or not
339 * @return void|object
Barry Mienydd671972010-10-04 16:33:58 +0200340 */
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200341 public function dbutil($db = NULL, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 $CI =& get_instance();
344
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200345 if ( ! is_object($db) OR ! ($db instanceof CI_DB))
346 {
347 class_exists('CI_DB', FALSE) OR $this->database();
348 $db =& $CI->db;
349 }
Barry Mienydd671972010-10-04 16:33:58 +0200350
Greg Aker3a746652011-04-19 10:59:47 -0500351 require_once(BASEPATH.'database/DB_utility.php');
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200352 require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php');
353 $class = 'CI_DB_'.$db->dbdriver.'_utility';
Derek Allard2067d1a2008-11-13 22:59:24 +0000354
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200355 if ($return === TRUE)
356 {
357 return new $class($db);
358 }
359
360 $CI->dbutil = new $class($db);
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 }
Barry Mienydd671972010-10-04 16:33:58 +0200362
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 // --------------------------------------------------------------------
364
365 /**
366 * Load the Database Forge Class
367 *
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200368 * @param object $db Database object
369 * @param bool $return Whether to return the DB Forge class object or not
370 * @return void|object
Barry Mienydd671972010-10-04 16:33:58 +0200371 */
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200372 public function dbforge($db = NULL, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 {
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200374 $CI =& get_instance();
375 if ( ! is_object($db) OR ! ($db instanceof CI_DB))
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 {
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200377 class_exists('CI_DB', FALSE) OR $this->database();
378 $db =& $CI->db;
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 }
Barry Mienydd671972010-10-04 16:33:58 +0200380
Greg Aker3a746652011-04-19 10:59:47 -0500381 require_once(BASEPATH.'database/DB_forge.php');
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200382 require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php');
Andrey Andreeva287a342012-11-05 23:19:59 +0200383
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200384 if ( ! empty($db->subdriver))
Andrey Andreeva287a342012-11-05 23:19:59 +0200385 {
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200386 $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php';
Andrey Andreeva287a342012-11-05 23:19:59 +0200387 if (file_exists($driver_path))
388 {
389 require_once($driver_path);
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200390 $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge';
Andrey Andreeva287a342012-11-05 23:19:59 +0200391 }
392 }
393 else
394 {
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200395 $class = 'CI_DB_'.$db->dbdriver.'_forge';
Andrey Andreeva287a342012-11-05 23:19:59 +0200396 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000397
Andrey Andreeveaa60c72012-11-06 01:11:22 +0200398 if ($return === TRUE)
399 {
400 return new $class($db);
401 }
402
403 $CI->dbforge = new $class($db);
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 }
Barry Mienydd671972010-10-04 16:33:58 +0200405
Derek Allard2067d1a2008-11-13 22:59:24 +0000406 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200407
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300409 * View Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300411 * Loads "view" files.
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300413 * @param string $view View name
414 * @param array $vars An associative array of data
415 * to be extracted for use in the view
416 * @param bool $return Whether to return the view output
417 * or leave it to the Output class
garthkerrb53bd4e2013-10-01 19:46:11 -0400418 * @return void|string
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 */
Greg Akerf5c84022011-04-19 17:13:03 -0500420 public function view($view, $vars = array(), $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
422 return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
423 }
Barry Mienydd671972010-10-04 16:33:58 +0200424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300428 * Generic File Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300430 * @param string $path File path
431 * @param bool $return Whether to return the file output
432 * @return void|string
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 */
Greg Akerf5c84022011-04-19 17:13:03 -0500434 public function file($path, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 {
436 return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));
437 }
Barry Mienydd671972010-10-04 16:33:58 +0200438
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 /**
442 * Set Variables
443 *
444 * Once variables are set they become available within
445 * the controller class and its "view" files.
446 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300447 * @param array|object|string $vars
448 * An associative array or object containing values
449 * to be set, or a value's name if string
450 * @param string $val Value to set, only used if $vars is a string
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @return void
452 */
Greg Akerf5c84022011-04-19 17:13:03 -0500453 public function vars($vars = array(), $val = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
vlakoffa5e0ea82013-02-27 18:17:35 +0100455 if (is_string($vars))
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 {
457 $vars = array($vars => $val);
458 }
Barry Mienydd671972010-10-04 16:33:58 +0200459
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 $vars = $this->_ci_object_to_array($vars);
Barry Mienydd671972010-10-04 16:33:58 +0200461
Andrey Andreev94af3552012-03-26 23:10:42 +0300462 if (is_array($vars) && count($vars) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 {
464 foreach ($vars as $key => $val)
465 {
466 $this->_ci_cached_vars[$key] = $val;
467 }
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 /**
Tomaz Lovreca81a5ef2013-10-16 11:29:57 +0200474 * Clear Cached Variables
475 *
476 * Clears the cached variables.
477 *
478 * @return void
479 */
480 public function clear_vars()
481 {
482 $this->_ci_cached_vars = array();
483 }
484
485 // --------------------------------------------------------------------
486
487 /**
Phil Sturgeon8731f642011-07-22 16:11:34 -0600488 * Get Variable
489 *
490 * Check if a variable is set and retrieve it.
491 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300492 * @param string $key Variable name
493 * @return mixed The variable or NULL if not found
Phil Sturgeon8731f642011-07-22 16:11:34 -0600494 */
495 public function get_var($key)
496 {
497 return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL;
498 }
499
500 // --------------------------------------------------------------------
501
502 /**
Shane Pearson81dd2232011-11-18 20:49:35 -0600503 * Get Variables
504 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300505 * Retrieves all loaded variables.
Shane Pearson81dd2232011-11-18 20:49:35 -0600506 *
507 * @return array
508 */
509 public function get_vars()
510 {
511 return $this->_ci_cached_vars;
512 }
513
514 // --------------------------------------------------------------------
515
516 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300517 * Helper Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000518 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300519 * @param string|string[] $helpers Helper name(s)
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 * @return void
521 */
Greg Akerf5c84022011-04-19 17:13:03 -0500522 public function helper($helpers = array())
Barry Mienydd671972010-10-04 16:33:58 +0200523 {
Derek Jones32bf1862010-03-02 13:46:07 -0600524 foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper)
Barry Mienydd671972010-10-04 16:33:58 +0200525 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000526 if (isset($this->_ci_helpers[$helper]))
527 {
528 continue;
529 }
Derek Jones32bf1862010-03-02 13:46:07 -0600530
Barry Mienydd671972010-10-04 16:33:58 +0200531 // Is this a helper extension request?
Andrey Andreev12d7b462012-11-12 13:42:09 +0200532 $ext_helper = config_item('subclass_prefix').$helper;
533 $ext_loaded = FALSE;
534 foreach ($this->_ci_helper_paths as $path)
535 {
536 if (file_exists($path.'helpers/'.$ext_helper.'.php'))
537 {
538 include_once($path.'helpers/'.$ext_helper.'.php');
539 $ext_loaded = TRUE;
540 }
541 }
542
543 // If we have loaded extensions - check if the base one is here
544 if ($ext_loaded === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 {
Greg Aker3a746652011-04-19 10:59:47 -0500546 $base_helper = BASEPATH.'helpers/'.$helper.'.php';
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 if ( ! file_exists($base_helper))
548 {
Greg Aker3a746652011-04-19 10:59:47 -0500549 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 }
Barry Mienydd671972010-10-04 16:33:58 +0200551
Derek Allard2067d1a2008-11-13 22:59:24 +0000552 include_once($base_helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600553 $this->_ci_helpers[$helper] = TRUE;
554 log_message('debug', 'Helper loaded: '.$helper);
555 continue;
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 }
Barry Mienydd671972010-10-04 16:33:58 +0200557
Andrey Andreev12d7b462012-11-12 13:42:09 +0200558 // No extensions found ... try loading regular helpers and/or overrides
Derek Jones32bf1862010-03-02 13:46:07 -0600559 foreach ($this->_ci_helper_paths as $path)
560 {
Greg Aker3a746652011-04-19 10:59:47 -0500561 if (file_exists($path.'helpers/'.$helper.'.php'))
Barry Mienydd671972010-10-04 16:33:58 +0200562 {
Greg Aker3a746652011-04-19 10:59:47 -0500563 include_once($path.'helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600564
565 $this->_ci_helpers[$helper] = TRUE;
Barry Mienydd671972010-10-04 16:33:58 +0200566 log_message('debug', 'Helper loaded: '.$helper);
Derek Jones32bf1862010-03-02 13:46:07 -0600567 break;
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 }
569 }
570
Derek Jones32bf1862010-03-02 13:46:07 -0600571 // unable to load the helper
572 if ( ! isset($this->_ci_helpers[$helper]))
573 {
Greg Aker3a746652011-04-19 10:59:47 -0500574 show_error('Unable to load the requested file: helpers/'.$helper.'.php');
Derek Jones32bf1862010-03-02 13:46:07 -0600575 }
Barry Mienydd671972010-10-04 16:33:58 +0200576 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 }
Barry Mienydd671972010-10-04 16:33:58 +0200578
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200580
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 /**
582 * Load Helpers
583 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300584 * An alias for the helper() method in case the developer has
585 * written the plural form of it.
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300587 * @uses CI_Loader::helper()
588 * @param string|string[] $helpers Helper name(s)
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 * @return void
590 */
Greg Akerf5c84022011-04-19 17:13:03 -0500591 public function helpers($helpers = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 {
593 $this->helper($helpers);
594 }
Barry Mienydd671972010-10-04 16:33:58 +0200595
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200597
Derek Allard2067d1a2008-11-13 22:59:24 +0000598 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300599 * Language Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000600 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300601 * Loads language files.
602 *
603 * @param string|string[] $files List of language file names to load
604 * @param string Language name
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 * @return void
606 */
Andrey Andreeved4b2582012-10-27 17:46:52 +0300607 public function language($files = array(), $lang = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000608 {
609 $CI =& get_instance();
610
Andrey Andreeved4b2582012-10-27 17:46:52 +0300611 is_array($files) OR $files = array($files);
Derek Allard2067d1a2008-11-13 22:59:24 +0000612
Andrey Andreeved4b2582012-10-27 17:46:52 +0300613 foreach ($files as $langfile)
Barry Mienydd671972010-10-04 16:33:58 +0200614 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000615 $CI->lang->load($langfile, $lang);
616 }
617 }
Barry Mienydd671972010-10-04 16:33:58 +0200618
Derek Allard2067d1a2008-11-13 22:59:24 +0000619 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200620
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300622 * Config Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300624 * Loads a config file (an alias for CI_Config::load()).
625 *
626 * @uses CI_Config::load()
627 * @param string $file Configuration file name
628 * @param bool $use_sections Whether configuration values should be loaded into their own section
629 * @param bool $fail_gracefully Whether to just return FALSE or display an error message
630 * @return bool TRUE if the file was loaded correctly or FALSE on failure
Derek Allard2067d1a2008-11-13 22:59:24 +0000631 */
Greg Akerf5c84022011-04-19 17:13:03 -0500632 public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
Barry Mienydd671972010-10-04 16:33:58 +0200633 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 $CI =& get_instance();
Andrey Andreeved4b2582012-10-27 17:46:52 +0300635 return $CI->config->load($file, $use_sections, $fail_gracefully);
Derek Allard2067d1a2008-11-13 22:59:24 +0000636 }
637
638 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600639
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300641 * Driver Loader
Derek Jones8dca0412010-03-05 13:01:44 -0600642 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300643 * Loads a driver library.
Derek Jones8dca0412010-03-05 13:01:44 -0600644 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300645 * @param string|string[] $library Driver name(s)
646 * @param array $params Optional parameters to pass to the driver
647 * @param string $object_name An optional object name to assign to
648 *
649 * @return void|object|bool Object or FALSE on failure if $library is a string
650 * and $object_name is set. void otherwise.
Derek Jones8dca0412010-03-05 13:01:44 -0600651 */
Greg Akerf5c84022011-04-19 17:13:03 -0500652 public function driver($library = '', $params = NULL, $object_name = NULL)
Derek Jones8dca0412010-03-05 13:01:44 -0600653 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800654 if (is_array($library))
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800655 {
Christopher Guineyb54d3552012-03-10 08:38:10 -0800656 foreach ($library as $driver)
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800657 {
658 $this->driver($driver);
659 }
dchill420fc3be52012-08-27 20:54:23 -0400660 return;
Christopher Guiney9929d6f2012-03-09 19:53:24 -0800661 }
662
Alex Bilbieed944a32012-06-02 11:07:47 +0100663 if ($library === '')
Tom Klingenberg6a15b2d2011-10-07 20:03:30 +0200664 {
665 return FALSE;
666 }
667
vlakofffadb8222013-05-12 10:57:09 +0200668 if ( ! class_exists('CI_Driver_Library', FALSE))
dchill426262d052012-11-24 18:41:13 -0500669 {
670 // We aren't instantiating an object here, just making the base class available
671 require BASEPATH.'libraries/Driver.php';
672 }
673
Derek Jonesd5e0cb52010-03-09 20:20:46 -0600674 // We can save the loader some time since Drivers will *always* be in a subfolder,
675 // and typically identically named to the library
676 if ( ! strpos($library, '/'))
677 {
Greg Akerd25e66a2010-03-28 01:07:09 -0500678 $library = ucfirst($library).'/'.$library;
Derek Jones8dca0412010-03-05 13:01:44 -0600679 }
Barry Mienydd671972010-10-04 16:33:58 +0200680
Derek Jones8dca0412010-03-05 13:01:44 -0600681 return $this->library($library, $params, $object_name);
682 }
683
684 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200685
Derek Jones8dca0412010-03-05 13:01:44 -0600686 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600687 * Add Package Path
Derek Allard2067d1a2008-11-13 22:59:24 +0000688 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300689 * Prepends a parent path to the library, model, helper and config
690 * path arrays.
Derek Allard2067d1a2008-11-13 22:59:24 +0000691 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300692 * @see CI_Loader::$_ci_library_paths
693 * @see CI_Loader::$_ci_model_paths
694 * @see CI_Loader::$_ci_helper_paths
695 * @see CI_Config::$_config_paths
696 *
697 * @param string $path Path to add
698 * @param bool $view_cascade (default: TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000699 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600700 */
Andrey Andreevcce91802012-06-12 13:25:31 +0300701 public function add_package_path($path, $view_cascade = TRUE)
Derek Jones32bf1862010-03-02 13:46:07 -0600702 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500703 $path = rtrim($path, '/').'/';
David Behlercda768a2011-08-14 23:52:48 +0200704
Derek Jones32bf1862010-03-02 13:46:07 -0600705 array_unshift($this->_ci_library_paths, $path);
706 array_unshift($this->_ci_model_paths, $path);
707 array_unshift($this->_ci_helper_paths, $path);
Barry Mienydd671972010-10-04 16:33:58 +0200708
Greg Akerf5c84022011-04-19 17:13:03 -0500709 $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths;
710
Derek Jones32bf1862010-03-02 13:46:07 -0600711 // Add config file path
712 $config =& $this->_ci_get_component('config');
and-ersb3ec9422013-01-03 16:05:12 +0100713 $config->_config_paths[] = $path;
Derek Allard2067d1a2008-11-13 22:59:24 +0000714 }
715
716 // --------------------------------------------------------------------
Derek Jones32bf1862010-03-02 13:46:07 -0600717
718 /**
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000719 * Get Package Paths
720 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300721 * Return a list of all package paths.
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000722 *
vlakoffcdc61132013-05-10 16:47:47 +0200723 * @param bool $include_base Whether to include BASEPATH (default: FALSE)
Andrey Andreeved4b2582012-10-27 17:46:52 +0300724 * @return array
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000725 */
Greg Akerf5c84022011-04-19 17:13:03 -0500726 public function get_package_paths($include_base = FALSE)
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000727 {
Andrey Andreev5fd3ae82012-10-24 14:55:35 +0300728 return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths;
Phil Sturgeonde3dbc32010-12-27 17:41:02 +0000729 }
730
731 // --------------------------------------------------------------------
732
733 /**
Derek Jones32bf1862010-03-02 13:46:07 -0600734 * Remove Package Path
735 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300736 * Remove a path from the library, model, helper and/or config
737 * path arrays if it exists. If no path is provided, the most recently
738 * added path will be removed removed.
Derek Jones32bf1862010-03-02 13:46:07 -0600739 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300740 * @param string $path Path to remove
Andrey Andreev94af3552012-03-26 23:10:42 +0300741 * @return void
Derek Jones32bf1862010-03-02 13:46:07 -0600742 */
Andrey Andreeved4b2582012-10-27 17:46:52 +0300743 public function remove_package_path($path = '')
Derek Jones32bf1862010-03-02 13:46:07 -0600744 {
745 $config =& $this->_ci_get_component('config');
Barry Mienydd671972010-10-04 16:33:58 +0200746
Alex Bilbieed944a32012-06-02 11:07:47 +0100747 if ($path === '')
Derek Jones32bf1862010-03-02 13:46:07 -0600748 {
Andrey Andreevd7297352012-01-07 22:53:14 +0200749 array_shift($this->_ci_library_paths);
750 array_shift($this->_ci_model_paths);
751 array_shift($this->_ci_helper_paths);
752 array_shift($this->_ci_view_paths);
Korri3684d342012-04-17 00:35:08 -0400753 array_pop($config->_config_paths);
Derek Jones32bf1862010-03-02 13:46:07 -0600754 }
755 else
756 {
Pascal Kriete6b6c2742010-11-09 13:12:22 -0500757 $path = rtrim($path, '/').'/';
Derek Jones32bf1862010-03-02 13:46:07 -0600758 foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var)
759 {
760 if (($key = array_search($path, $this->{$var})) !== FALSE)
761 {
762 unset($this->{$var}[$key]);
763 }
764 }
David Behlercda768a2011-08-14 23:52:48 +0200765
Greg Akerf5c84022011-04-19 17:13:03 -0500766 if (isset($this->_ci_view_paths[$path.'views/']))
767 {
768 unset($this->_ci_view_paths[$path.'views/']);
769 }
Barry Mienydd671972010-10-04 16:33:58 +0200770
Derek Jones32bf1862010-03-02 13:46:07 -0600771 if (($key = array_search($path, $config->_config_paths)) !== FALSE)
772 {
773 unset($config->_config_paths[$key]);
774 }
775 }
Barry Mienydd671972010-10-04 16:33:58 +0200776
Derek Jones32bf1862010-03-02 13:46:07 -0600777 // make sure the application default paths are still in the array
778 $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH)));
779 $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH)));
780 $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH)));
Greg Akerf5c84022011-04-19 17:13:03 -0500781 $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE));
Derek Jones32bf1862010-03-02 13:46:07 -0600782 $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH)));
783 }
784
785 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200786
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300788 * Internal CI Data Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000789 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300790 * Used to load views and files.
791 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000792 * Variables are prefixed with _ci_ to avoid symbol collision with
Andrey Andreeved4b2582012-10-27 17:46:52 +0300793 * variables made available to view files.
Derek Allard2067d1a2008-11-13 22:59:24 +0000794 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300795 * @used-by CI_Loader::view()
796 * @used-by CI_Loader::file()
797 * @param array $_ci_data Data to load
Derek Allard2067d1a2008-11-13 22:59:24 +0000798 * @return void
799 */
Greg Akerf5c84022011-04-19 17:13:03 -0500800 protected function _ci_load($_ci_data)
Derek Allard2067d1a2008-11-13 22:59:24 +0000801 {
802 // Set the default data variables
803 foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val)
804 {
Andrey Andreev94af3552012-03-26 23:10:42 +0300805 $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 }
David Behlercda768a2011-08-14 23:52:48 +0200807
Greg Akerf5c84022011-04-19 17:13:03 -0500808 $file_exists = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000809
810 // Set the path to the requested file
Alex Bilbie40bd2a72012-06-02 16:04:15 +0100811 if (is_string($_ci_path) && $_ci_path !== '')
Greg Aker8807be32011-04-21 13:06:15 -0500812 {
813 $_ci_x = explode('/', $_ci_path);
814 $_ci_file = end($_ci_x);
815 }
816 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 {
818 $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
Alex Bilbieed944a32012-06-02 11:07:47 +0100819 $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view;
Greg Akerf5c84022011-04-19 17:13:03 -0500820
Joe McFrederick64f470b2012-08-18 12:29:56 -0400821 foreach ($this->_ci_view_paths as $_ci_view_file => $cascade)
Greg Akerf5c84022011-04-19 17:13:03 -0500822 {
Joe McFrederick64f470b2012-08-18 12:29:56 -0400823 if (file_exists($_ci_view_file.$_ci_file))
Greg Akerf5c84022011-04-19 17:13:03 -0500824 {
Joe McFrederick64f470b2012-08-18 12:29:56 -0400825 $_ci_path = $_ci_view_file.$_ci_file;
Greg Akerf5c84022011-04-19 17:13:03 -0500826 $file_exists = TRUE;
827 break;
828 }
David Behlercda768a2011-08-14 23:52:48 +0200829
Greg Akerf5c84022011-04-19 17:13:03 -0500830 if ( ! $cascade)
831 {
832 break;
David Behlercda768a2011-08-14 23:52:48 +0200833 }
Greg Akerf5c84022011-04-19 17:13:03 -0500834 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000835 }
Barry Mienydd671972010-10-04 16:33:58 +0200836
Greg Akerf5c84022011-04-19 17:13:03 -0500837 if ( ! $file_exists && ! file_exists($_ci_path))
Derek Allard2067d1a2008-11-13 22:59:24 +0000838 {
839 show_error('Unable to load the requested file: '.$_ci_file);
840 }
Barry Mienydd671972010-10-04 16:33:58 +0200841
Derek Allard2067d1a2008-11-13 22:59:24 +0000842 // This allows anything loaded using $this->load (views, files, etc.)
843 // to become accessible from within the Controller and Model functions.
Pascal Kriete89ace432010-11-10 15:49:10 -0500844 $_ci_CI =& get_instance();
845 foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
Derek Allard2067d1a2008-11-13 22:59:24 +0000846 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500847 if ( ! isset($this->$_ci_key))
Derek Allard2067d1a2008-11-13 22:59:24 +0000848 {
Pascal Kriete89ace432010-11-10 15:49:10 -0500849 $this->$_ci_key =& $_ci_CI->$_ci_key;
Derek Allard2067d1a2008-11-13 22:59:24 +0000850 }
851 }
852
853 /*
854 * Extract and cache variables
855 *
vlakoff02506182012-07-03 07:28:50 +0200856 * You can either set variables using the dedicated $this->load->vars()
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 * function or via the second parameter of this function. We'll merge
858 * the two types and cache them so that views that are embedded within
859 * other views can have access to these variables.
Barry Mienydd671972010-10-04 16:33:58 +0200860 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000861 if (is_array($_ci_vars))
862 {
863 $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
864 }
865 extract($this->_ci_cached_vars);
Barry Mienydd671972010-10-04 16:33:58 +0200866
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 /*
868 * Buffer the output
869 *
870 * We buffer the output for two reasons:
871 * 1. Speed. You get a significant speed boost.
Andrey Andreevd7297352012-01-07 22:53:14 +0200872 * 2. So that the final rendered template can be post-processed by
dchill425628ba02012-08-08 12:05:45 -0400873 * the output class. Why do we need post processing? For one thing,
874 * in order to show the elapsed page load time. Unless we can
875 * intercept the content right before it's sent to the browser and
876 * then stop the timer it won't be accurate.
Derek Allard2067d1a2008-11-13 22:59:24 +0000877 */
878 ob_start();
Barry Mienydd671972010-10-04 16:33:58 +0200879
Derek Allard2067d1a2008-11-13 22:59:24 +0000880 // If the PHP installation does not support short tags we'll
881 // do a little string replacement, changing the short tags
882 // to standard PHP echo statements.
Andrey Andreeve9d2dc82012-11-07 14:23:29 +0200883 if ( ! is_php('5.4') && (bool) @ini_get('short_open_tag') === FALSE
884 && config_item('rewrite_short_tags') === TRUE && function_usable('eval')
885 )
Derek Allard2067d1a2008-11-13 22:59:24 +0000886 {
Andrey Andreevd47baab2012-01-09 16:56:46 +0200887 echo eval('?>'.preg_replace('/;*\s*\?>/', '; ?>', str_replace('<?=', '<?php echo ', file_get_contents($_ci_path))));
Derek Allard2067d1a2008-11-13 22:59:24 +0000888 }
889 else
890 {
891 include($_ci_path); // include() vs include_once() allows for multiple views with the same name
892 }
Barry Mienydd671972010-10-04 16:33:58 +0200893
Derek Allard2067d1a2008-11-13 22:59:24 +0000894 log_message('debug', 'File loaded: '.$_ci_path);
Barry Mienydd671972010-10-04 16:33:58 +0200895
Derek Allard2067d1a2008-11-13 22:59:24 +0000896 // Return the file data if requested
897 if ($_ci_return === TRUE)
Barry Mienydd671972010-10-04 16:33:58 +0200898 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 $buffer = ob_get_contents();
900 @ob_end_clean();
901 return $buffer;
902 }
903
904 /*
905 * Flush the buffer... or buff the flusher?
906 *
907 * In order to permit views to be nested within
908 * other views, we need to flush the content back out whenever
909 * we are beyond the first level of output buffering so that
910 * it can be seen and included properly by the first included
911 * template and any subsequent ones. Oy!
Barry Mienydd671972010-10-04 16:33:58 +0200912 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000913 if (ob_get_level() > $this->_ci_ob_level + 1)
914 {
915 ob_end_flush();
916 }
917 else
918 {
Greg Aker22f1a632010-11-10 15:34:35 -0600919 $_ci_CI->output->append_output(ob_get_contents());
Derek Allard2067d1a2008-11-13 22:59:24 +0000920 @ob_end_clean();
921 }
922 }
923
924 // --------------------------------------------------------------------
925
926 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +0300927 * Internal CI Class Loader
Derek Allard2067d1a2008-11-13 22:59:24 +0000928 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300929 * @used-by CI_Loader::library()
930 * @uses CI_Loader::_ci_init_class()
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 *
Andrey Andreeved4b2582012-10-27 17:46:52 +0300932 * @param string $class Class name to load
933 * @param mixed $params Optional parameters to pass to the class constructor
934 * @param string $object_name Optional object name to assign to
Barry Mienydd671972010-10-04 16:33:58 +0200935 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +0000936 */
Greg Akerf5c84022011-04-19 17:13:03 -0500937 protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +0200938 {
939 // Get the class name, and while we're at it trim any slashes.
940 // The directory path can be included as part of the class name,
Derek Allard2067d1a2008-11-13 22:59:24 +0000941 // but we don't want a leading slash
Greg Aker3a746652011-04-19 10:59:47 -0500942 $class = str_replace('.php', '', trim($class, '/'));
Barry Mienydd671972010-10-04 16:33:58 +0200943
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 // Was the path included with the class name?
945 // We look for a slash to determine this
Derek Jones32bf1862010-03-02 13:46:07 -0600946 if (($last_slash = strrpos($class, '/')) !== FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000947 {
Derek Jones32bf1862010-03-02 13:46:07 -0600948 // Extract the path
Andrey Andreevc26d34f2013-01-28 21:46:08 +0200949 $subdir = substr($class, 0, ++$last_slash);
Barry Mienydd671972010-10-04 16:33:58 +0200950
Derek Jones32bf1862010-03-02 13:46:07 -0600951 // Get the filename from the path
Andrey Andreevd7297352012-01-07 22:53:14 +0200952 $class = substr($class, $last_slash);
Derek Allard2067d1a2008-11-13 22:59:24 +0000953 }
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200954 else
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200956 $subdir = '';
957 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000958
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200959 $class = ucfirst($class);
960 $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php';
961
962 // Is this a class extension request?
963 if (file_exists($subclass))
964 {
Daniel1d3752c2013-04-14 16:41:57 -0400965 $baseclass = BASEPATH.'libraries/'.$subdir.$class.'.php';
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200966
967 if ( ! file_exists($baseclass))
Derek Allard2067d1a2008-11-13 22:59:24 +0000968 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200969 log_message('error', 'Unable to load the requested class: '.$class);
970 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +0000971 }
Barry Mienydd671972010-10-04 16:33:58 +0200972
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200973 // Safety: Was the class already loaded by a previous call?
974 if (class_exists(config_item('subclass_prefix').$class, FALSE))
Derek Allard2067d1a2008-11-13 22:59:24 +0000975 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200976 // Before we deem this to be a duplicate request, let's see
977 // if a custom object name is being supplied. If so, we'll
978 // return a new instance of the object
979 if ($object_name !== NULL)
Derek Allard2067d1a2008-11-13 22:59:24 +0000980 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200981 $CI =& get_instance();
982 if ( ! isset($CI->$object_name))
Derek Allard2067d1a2008-11-13 22:59:24 +0000983 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200984 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000985 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000986 }
Barry Mienydd671972010-10-04 16:33:58 +0200987
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200988 log_message('debug', $class.' class already loaded. Second attempt ignored.');
989 return;
Derek Allard2067d1a2008-11-13 22:59:24 +0000990 }
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200991
992 include_once($baseclass);
993 include_once($subclass);
994
995 return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name);
996 }
997
vlakoff35672462013-02-15 01:36:04 +0100998 // Let's search for the requested library file and load it.
Andrey Andreev3608e1a2013-01-28 16:27:30 +0200999 foreach ($this->_ci_library_paths as $path)
1000 {
1001 $filepath = $path.'libraries/'.$subdir.$class.'.php';
1002
1003 // Safety: Was the class already loaded by a previous call?
1004 if (class_exists($class, FALSE))
1005 {
1006 // Before we deem this to be a duplicate request, let's see
1007 // if a custom object name is being supplied. If so, we'll
1008 // return a new instance of the object
1009 if ($object_name !== NULL)
1010 {
1011 $CI =& get_instance();
1012 if ( ! isset($CI->$object_name))
1013 {
1014 return $this->_ci_init_class($class, '', $params, $object_name);
1015 }
1016 }
1017
1018 log_message('debug', $class.' class already loaded. Second attempt ignored.');
1019 return;
1020 }
1021 // Does the file exist? No? Bummer...
1022 elseif ( ! file_exists($filepath))
1023 {
1024 continue;
1025 }
1026
1027 include_once($filepath);
1028 return $this->_ci_init_class($class, '', $params, $object_name);
1029 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001030
Andrey Andreevd7297352012-01-07 22:53:14 +02001031 // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified?
Alex Bilbieed944a32012-06-02 11:07:47 +01001032 if ($subdir === '')
Derek Allard2067d1a2008-11-13 22:59:24 +00001033 {
Andrey Andreev3608e1a2013-01-28 16:27:30 +02001034 return $this->_ci_load_class($class.'/'.$class, $params, $object_name);
dchill42aee92652012-08-26 21:45:35 -04001035 }
Barry Mienydd671972010-10-04 16:33:58 +02001036
Derek Allard2067d1a2008-11-13 22:59:24 +00001037 // If we got this far we were unable to find the requested class.
Andrey Andreev3608e1a2013-01-28 16:27:30 +02001038 log_message('error', 'Unable to load the requested class: '.$class);
1039 show_error('Unable to load the requested class: '.$class);
Derek Allard2067d1a2008-11-13 22:59:24 +00001040 }
Barry Mienydd671972010-10-04 16:33:58 +02001041
Derek Allard2067d1a2008-11-13 22:59:24 +00001042 // --------------------------------------------------------------------
1043
1044 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +03001045 * Internal CI Class Instantiator
Derek Allard2067d1a2008-11-13 22:59:24 +00001046 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001047 * @used-by CI_Loader::_ci_load_class()
1048 *
1049 * @param string $class Class name
1050 * @param string $prefix Class name prefix
1051 * @param array|null|bool $config Optional configuration to pass to the class constructor:
1052 * FALSE to skip;
1053 * NULL to search in config paths;
1054 * array containing configuration data
1055 * @param string $object_name Optional object name to assign to
Andrey Andreev94af3552012-03-26 23:10:42 +03001056 * @return void
Derek Allard2067d1a2008-11-13 22:59:24 +00001057 */
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001058 protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL)
Barry Mienydd671972010-10-04 16:33:58 +02001059 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001060 // Is there an associated config file for this class? Note: these should always be lowercase
Derek Allard2067d1a2008-11-13 22:59:24 +00001061 if ($config === NULL)
1062 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001063 // Fetch the config paths containing any package paths
1064 $config_component = $this->_ci_get_component('config');
1065
1066 if (is_array($config_component->_config_paths))
Derek Allard2067d1a2008-11-13 22:59:24 +00001067 {
Eric Barnes5e16ec62011-01-04 17:25:23 -05001068 // Break on the first found file, thus package files
1069 // are not overridden by default paths
1070 foreach ($config_component->_config_paths as $path)
1071 {
1072 // We test for both uppercase and lowercase, for servers that
joelcox1bfd9fa2011-01-16 18:49:39 +01001073 // are case-sensitive with regard to file names. Check for environment
1074 // first, global next
Andrey Andreevdb529ca2013-01-28 11:00:02 +02001075 if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001076 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001077 include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001078 break;
1079 }
Andrey Andreevdb529ca2013-01-28 11:00:02 +02001080 elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'))
joelcox1bfd9fa2011-01-16 18:49:39 +01001081 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001082 include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php');
joelcox1bfd9fa2011-01-16 18:49:39 +01001083 break;
1084 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001085 elseif (file_exists($path.'config/'.strtolower($class).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001086 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001087 include($path.'config/'.strtolower($class).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001088 break;
1089 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001090 elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php'))
Eric Barnes5e16ec62011-01-04 17:25:23 -05001091 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001092 include($path.'config/'.ucfirst(strtolower($class)).'.php');
Eric Barnes5e16ec62011-01-04 17:25:23 -05001093 break;
1094 }
1095 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001096 }
1097 }
Barry Mienydd671972010-10-04 16:33:58 +02001098
Alex Bilbieed944a32012-06-02 11:07:47 +01001099 if ($prefix === '')
Barry Mienydd671972010-10-04 16:33:58 +02001100 {
Andrey Andreev49e68de2013-02-21 16:30:55 +02001101 if (class_exists('CI_'.$class, FALSE))
Derek Allard2067d1a2008-11-13 22:59:24 +00001102 {
1103 $name = 'CI_'.$class;
1104 }
Andrey Andreev49e68de2013-02-21 16:30:55 +02001105 elseif (class_exists(config_item('subclass_prefix').$class, FALSE))
Derek Allard2067d1a2008-11-13 22:59:24 +00001106 {
1107 $name = config_item('subclass_prefix').$class;
1108 }
1109 else
1110 {
1111 $name = $class;
1112 }
1113 }
1114 else
1115 {
1116 $name = $prefix.$class;
1117 }
Barry Mienydd671972010-10-04 16:33:58 +02001118
Derek Allard2067d1a2008-11-13 22:59:24 +00001119 // Is the class name valid?
Andrey Andreev49e68de2013-02-21 16:30:55 +02001120 if ( ! class_exists($name, FALSE))
Derek Allard2067d1a2008-11-13 22:59:24 +00001121 {
Andrey Andreevd7297352012-01-07 22:53:14 +02001122 log_message('error', 'Non-existent class: '.$name);
jonnueee2df62012-07-16 13:06:16 +01001123 show_error('Non-existent class: '.$name);
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 }
Barry Mienydd671972010-10-04 16:33:58 +02001125
Derek Allard2067d1a2008-11-13 22:59:24 +00001126 // Set the variable name we will assign the class to
Andrey Andreevd7297352012-01-07 22:53:14 +02001127 // Was a custom class name supplied? If so we'll use it
Andrey Andreev519f87a2013-07-23 17:16:10 +03001128 if (empty($object_name))
Derek Allard2067d1a2008-11-13 22:59:24 +00001129 {
Andrey Andreev519f87a2013-07-23 17:16:10 +03001130 $object_name = strtolower($class);
1131 if (isset($this->_ci_varmap[$object_name]))
1132 {
1133 $object_name = $this->_ci_varmap[$object_name];
1134 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001135 }
Andrey Andreev519f87a2013-07-23 17:16:10 +03001136
1137 // Don't overwrite existing properties
1138 $CI =& get_instance();
1139 if (isset($CI->$object_name))
Derek Allard2067d1a2008-11-13 22:59:24 +00001140 {
Andrey Andreev519f87a2013-07-23 17:16:10 +03001141 if ($CI->$object_name instanceof $name)
1142 {
1143 log_message('debug', $class." has already been instantiated as '".$object_name."'. Second attempt aborted.");
1144 return;
1145 }
1146
1147 show_error("Resource '".$object_name."' already exists and is not a ".$class." instance.");
Derek Allard2067d1a2008-11-13 22:59:24 +00001148 }
1149
Barry Mienydd671972010-10-04 16:33:58 +02001150 // Save the class name and object name
Andrey Andreev519f87a2013-07-23 17:16:10 +03001151 $this->_ci_classes[$object_name] = $class;
Derek Allard2067d1a2008-11-13 22:59:24 +00001152
Barry Mienydd671972010-10-04 16:33:58 +02001153 // Instantiate the class
Andrey Andreev519f87a2013-07-23 17:16:10 +03001154 $CI->$object_name = isset($config)
1155 ? new $name($config)
1156 : new $name();
Barry Mienydd671972010-10-04 16:33:58 +02001157 }
1158
Derek Allard2067d1a2008-11-13 22:59:24 +00001159 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001160
Derek Allard2067d1a2008-11-13 22:59:24 +00001161 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +03001162 * CI Autoloader
Derek Allard2067d1a2008-11-13 22:59:24 +00001163 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001164 * Loads component listed in the config/autoload.php file.
Derek Allard2067d1a2008-11-13 22:59:24 +00001165 *
Andrey Andreevcdac2482012-11-03 18:09:01 +02001166 * @used-by CI_Loader::initialize()
Derek Allard2067d1a2008-11-13 22:59:24 +00001167 * @return void
1168 */
Shane Pearson665baec2011-08-22 18:52:19 -05001169 protected function _ci_autoloader()
Barry Mienydd671972010-10-04 16:33:58 +02001170 {
Andrey Andreevdb529ca2013-01-28 11:00:02 +02001171 if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'))
bubbafoley0ea04142011-03-17 14:55:41 -05001172 {
Shane Pearson6adfe632011-08-10 16:42:53 -05001173 include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001174 }
1175 else
1176 {
Shane Pearson6adfe632011-08-10 16:42:53 -05001177 include(APPPATH.'config/autoload.php');
bubbafoley0ea04142011-03-17 14:55:41 -05001178 }
Barry Mienydd671972010-10-04 16:33:58 +02001179
Derek Allard2067d1a2008-11-13 22:59:24 +00001180 if ( ! isset($autoload))
1181 {
1182 return FALSE;
1183 }
Barry Mienydd671972010-10-04 16:33:58 +02001184
Phil Sturgeon9730c752010-12-15 10:50:15 +00001185 // Autoload packages
1186 if (isset($autoload['packages']))
1187 {
1188 foreach ($autoload['packages'] as $package_path)
1189 {
1190 $this->add_package_path($package_path);
1191 }
1192 }
1193
Derek Allard2067d1a2008-11-13 22:59:24 +00001194 // Load any custom config file
1195 if (count($autoload['config']) > 0)
Barry Mienydd671972010-10-04 16:33:58 +02001196 {
Derek Allard2067d1a2008-11-13 22:59:24 +00001197 $CI =& get_instance();
1198 foreach ($autoload['config'] as $key => $val)
1199 {
1200 $CI->config->load($val);
1201 }
Barry Mienydd671972010-10-04 16:33:58 +02001202 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001203
Derek Jonesc6da5032010-03-09 20:44:27 -06001204 // Autoload helpers and languages
1205 foreach (array('helper', 'language') as $type)
Barry Mienydd671972010-10-04 16:33:58 +02001206 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001207 if (isset($autoload[$type]) && count($autoload[$type]) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001208 {
1209 $this->$type($autoload[$type]);
Barry Mienydd671972010-10-04 16:33:58 +02001210 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001211 }
1212
Andrey Andreev9ab70a82013-07-23 00:09:26 +03001213 // Autoload drivers
1214 if (isset($autoload['drivers']))
1215 {
1216 foreach ($autoload['drivers'] as $item)
1217 {
1218 $this->driver($item);
1219 }
1220 }
1221
Derek Allard2067d1a2008-11-13 22:59:24 +00001222 // Load libraries
Andrey Andreev94af3552012-03-26 23:10:42 +03001223 if (isset($autoload['libraries']) && count($autoload['libraries']) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +00001224 {
1225 // Load the database driver.
1226 if (in_array('database', $autoload['libraries']))
1227 {
1228 $this->database();
1229 $autoload['libraries'] = array_diff($autoload['libraries'], array('database'));
1230 }
Barry Mienydd671972010-10-04 16:33:58 +02001231
Derek Allard2067d1a2008-11-13 22:59:24 +00001232 // Load all other libraries
1233 foreach ($autoload['libraries'] as $item)
1234 {
1235 $this->library($item);
1236 }
Barry Mienydd671972010-10-04 16:33:58 +02001237 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001238
1239 // Autoload models
1240 if (isset($autoload['model']))
1241 {
1242 $this->model($autoload['model']);
1243 }
Barry Mienydd671972010-10-04 16:33:58 +02001244 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001245
1246 // --------------------------------------------------------------------
1247
1248 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +03001249 * CI Object to Array translator
Derek Allard2067d1a2008-11-13 22:59:24 +00001250 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001251 * Takes an object as input and converts the class variables to
1252 * an associative array with key/value pairs.
Derek Allard2067d1a2008-11-13 22:59:24 +00001253 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001254 * @param object $object Object data to translate
Derek Allard2067d1a2008-11-13 22:59:24 +00001255 * @return array
1256 */
Greg Akerf5c84022011-04-19 17:13:03 -05001257 protected function _ci_object_to_array($object)
Derek Allard2067d1a2008-11-13 22:59:24 +00001258 {
Andrey Andreev94af3552012-03-26 23:10:42 +03001259 return is_object($object) ? get_object_vars($object) : $object;
Derek Allard2067d1a2008-11-13 22:59:24 +00001260 }
1261
1262 // --------------------------------------------------------------------
1263
1264 /**
Andrey Andreeved4b2582012-10-27 17:46:52 +03001265 * CI Component getter
Derek Jones32bf1862010-03-02 13:46:07 -06001266 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001267 * Get a reference to a specific library or model.
1268 *
1269 * @param string $component Component name
Derek Jones32bf1862010-03-02 13:46:07 -06001270 * @return bool
1271 */
Greg Akerf5c84022011-04-19 17:13:03 -05001272 protected function &_ci_get_component($component)
Derek Jones32bf1862010-03-02 13:46:07 -06001273 {
Pascal Kriete89ace432010-11-10 15:49:10 -05001274 $CI =& get_instance();
1275 return $CI->$component;
Derek Jones32bf1862010-03-02 13:46:07 -06001276 }
1277
1278 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001279
Derek Jones32bf1862010-03-02 13:46:07 -06001280 /**
1281 * Prep filename
1282 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001283 * This function prepares filenames of various items to
1284 * make their loading more reliable.
Derek Jones32bf1862010-03-02 13:46:07 -06001285 *
Andrey Andreeved4b2582012-10-27 17:46:52 +03001286 * @param string|string[] $filename Filename(s)
1287 * @param string $extension Filename extension
Derek Jones32bf1862010-03-02 13:46:07 -06001288 * @return array
1289 */
Greg Akerf5c84022011-04-19 17:13:03 -05001290 protected function _ci_prep_filename($filename, $extension)
Derek Jones32bf1862010-03-02 13:46:07 -06001291 {
1292 if ( ! is_array($filename))
Barry Mienydd671972010-10-04 16:33:58 +02001293 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001294 return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension));
Derek Jones32bf1862010-03-02 13:46:07 -06001295 }
1296 else
1297 {
1298 foreach ($filename as $key => $val)
1299 {
Andrey Andreevd47baab2012-01-09 16:56:46 +02001300 $filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension);
Derek Jones32bf1862010-03-02 13:46:07 -06001301 }
Barry Mienydd671972010-10-04 16:33:58 +02001302
Derek Jones32bf1862010-03-02 13:46:07 -06001303 return $filename;
1304 }
1305 }
Andrey Andreev94af3552012-03-26 23:10:42 +03001306
Derek Allard2067d1a2008-11-13 22:59:24 +00001307}
1308
1309/* End of file Loader.php */
Tomaz Lovreca81a5ef2013-10-16 11:29:57 +02001310/* Location: ./system/core/Loader.php */