Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * 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. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Loader Class |
| 32 | * |
| 33 | * Loads views and files |
| 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Libraries |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 37 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 38 | * @category Loader |
| 39 | * @link http://codeigniter.com/user_guide/libraries/loader.html |
| 40 | */ |
| 41 | class CI_Loader { |
| 42 | |
| 43 | // All these are set automatically. Don't mess with them. |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 44 | /** |
| 45 | * Nesting level of the output buffering mechanism |
| 46 | * |
| 47 | * @var int |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 48 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 49 | protected $_ci_ob_level; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 50 | /** |
| 51 | * List of paths to load views from |
| 52 | * |
| 53 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 54 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 55 | protected $_ci_view_paths = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 56 | /** |
| 57 | * List of paths to load libraries from |
| 58 | * |
| 59 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 60 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 61 | protected $_ci_library_paths = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 62 | /** |
| 63 | * List of paths to load models from |
| 64 | * |
| 65 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 66 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 67 | protected $_ci_model_paths = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 68 | /** |
| 69 | * List of paths to load helpers from |
| 70 | * |
| 71 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 72 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 73 | protected $_ci_helper_paths = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 74 | /** |
| 75 | * List of loaded base classes |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 76 | * |
| 77 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 78 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 79 | protected $_base_classes = array(); // Set by the controller class |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 80 | /** |
| 81 | * List of cached variables |
| 82 | * |
| 83 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 84 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 85 | protected $_ci_cached_vars = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 86 | /** |
| 87 | * List of loaded classes |
| 88 | * |
| 89 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 90 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 91 | protected $_ci_classes = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 92 | /** |
| 93 | * List of loaded files |
| 94 | * |
| 95 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 96 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 97 | protected $_ci_loaded_files = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 98 | /** |
| 99 | * List of loaded models |
| 100 | * |
| 101 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 102 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 103 | protected $_ci_models = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 104 | /** |
| 105 | * List of loaded helpers |
| 106 | * |
| 107 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 108 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 109 | protected $_ci_helpers = array(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 110 | /** |
| 111 | * List of class name mappings |
| 112 | * |
| 113 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 114 | */ |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 115 | protected $_ci_varmap = array( |
| 116 | 'unit_test' => 'unit', |
| 117 | 'user_agent' => 'agent' |
| 118 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Constructor |
| 122 | * |
| 123 | * Sets the path to the view files and gets the initial output buffering level |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 124 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 125 | public function __construct() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 126 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 127 | $this->_ci_ob_level = ob_get_level(); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 128 | $this->_ci_library_paths = array(APPPATH, BASEPATH); |
| 129 | $this->_ci_helper_paths = array(APPPATH, BASEPATH); |
| 130 | $this->_ci_model_paths = array(APPPATH); |
Joe Cianflone | 8eef9c7 | 2011-08-21 10:39:06 -0400 | [diff] [blame] | 131 | $this->_ci_view_paths = array(VIEWPATH => TRUE); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 132 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 133 | log_message('debug', 'Loader Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 135 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | // -------------------------------------------------------------------- |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 137 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 138 | /** |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 139 | * Initialize the Loader |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 140 | * |
| 141 | * This method is called once in CI_Controller. |
| 142 | * |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 143 | * @param array |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 144 | * @return object |
| 145 | */ |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 146 | public function initialize() |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 147 | { |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 148 | $this->_ci_classes = array(); |
| 149 | $this->_ci_loaded_files = array(); |
| 150 | $this->_ci_models = array(); |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 151 | $this->_base_classes =& is_loaded(); |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 152 | |
| 153 | $this->_ci_autoloader(); |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 154 | return $this; |
| 155 | } |
| 156 | |
| 157 | // -------------------------------------------------------------------- |
| 158 | |
| 159 | /** |
| 160 | * Is Loaded |
| 161 | * |
| 162 | * A utility function to test if a class is in the self::$_ci_classes array. |
| 163 | * This function returns the object name if the class tested for is loaded, |
| 164 | * and returns FALSE if it isn't. |
| 165 | * |
| 166 | * It is mainly used in the form_helper -> _get_validation_object() |
| 167 | * |
| 168 | * @param string class being checked for |
| 169 | * @return mixed class object name on the CI SuperObject or FALSE |
| 170 | */ |
| 171 | public function is_loaded($class) |
| 172 | { |
| 173 | if (isset($this->_ci_classes[$class])) |
| 174 | { |
| 175 | return $this->_ci_classes[$class]; |
| 176 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 177 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 178 | return FALSE; |
| 179 | } |
| 180 | |
| 181 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 182 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 183 | /** |
| 184 | * Class Loader |
| 185 | * |
| 186 | * This function lets users load and instantiate classes. |
| 187 | * It is designed to be called from a user's app controllers. |
| 188 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 189 | * @param string the name of the class |
| 190 | * @param mixed the optional parameters |
| 191 | * @param string an optional object name |
| 192 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 194 | public function library($library = '', $params = NULL, $object_name = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | { |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 196 | if (is_array($library)) |
| 197 | { |
Phil Sturgeon | 08b5169 | 2011-04-03 18:05:42 +0100 | [diff] [blame] | 198 | foreach ($library as $class) |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 199 | { |
Kellas Reeves | 3c6e485 | 2011-02-09 11:57:56 -0600 | [diff] [blame] | 200 | $this->library($class, $params); |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 201 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 202 | |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 203 | return; |
| 204 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 205 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 206 | if ($library == '' OR isset($this->_base_classes[$library])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 207 | { |
| 208 | return FALSE; |
| 209 | } |
| 210 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 211 | if ( ! is_null($params) && ! is_array($params)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | { |
| 213 | $params = NULL; |
| 214 | } |
| 215 | |
Kellas Reeves | 3c6e485 | 2011-02-09 11:57:56 -0600 | [diff] [blame] | 216 | $this->_ci_load_class($library, $params, $object_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 220 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 221 | /** |
| 222 | * Model Loader |
| 223 | * |
| 224 | * This function lets users load and instantiate models. |
| 225 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 226 | * @param string the name of the class |
| 227 | * @param string name for the model |
| 228 | * @param bool database connection |
| 229 | * @return void |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 230 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 231 | public function model($model, $name = '', $db_conn = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 232 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 233 | if (is_array($model)) |
| 234 | { |
Pascal Kriete | 5d5895f | 2011-02-14 13:27:07 -0500 | [diff] [blame] | 235 | foreach ($model as $babe) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 237 | $this->model($babe); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 238 | } |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | if ($model == '') |
| 243 | { |
| 244 | return; |
| 245 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 246 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 247 | $path = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 248 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | // Is the model in a sub-folder? If so, parse out the filename and path. |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 250 | if (($last_slash = strrpos($model, '/')) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 252 | // The path is in front of the last slash |
| 253 | $path = substr($model, 0, $last_slash + 1); |
| 254 | |
| 255 | // And the model name behind it |
| 256 | $model = substr($model, $last_slash + 1); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 258 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 259 | if ($name == '') |
| 260 | { |
| 261 | $name = $model; |
| 262 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 263 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | if (in_array($name, $this->_ci_models, TRUE)) |
| 265 | { |
| 266 | return; |
| 267 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 268 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 269 | $CI =& get_instance(); |
| 270 | if (isset($CI->$name)) |
| 271 | { |
| 272 | show_error('The model name you are loading is the name of a resource that is already being used: '.$name); |
| 273 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 274 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 275 | $model = strtolower($model); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 277 | foreach ($this->_ci_model_paths as $mod_path) |
| 278 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 279 | if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 280 | { |
| 281 | continue; |
| 282 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 284 | if ($db_conn !== FALSE AND ! class_exists('CI_DB')) |
| 285 | { |
| 286 | if ($db_conn === TRUE) |
Pascal Kriete | 287781e | 2010-11-10 15:43:49 -0500 | [diff] [blame] | 287 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 288 | $db_conn = ''; |
Pascal Kriete | 287781e | 2010-11-10 15:43:49 -0500 | [diff] [blame] | 289 | } |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 290 | |
| 291 | $CI->load->database($db_conn, FALSE, TRUE); |
| 292 | } |
| 293 | |
Greg Aker | bce1348 | 2010-10-11 15:37:16 -0500 | [diff] [blame] | 294 | if ( ! class_exists('CI_Model')) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 295 | { |
| 296 | load_class('Model', 'core'); |
| 297 | } |
| 298 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 299 | require_once($mod_path.'models/'.$path.$model.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 300 | |
| 301 | $model = ucfirst($model); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 302 | $CI->$name = new $model(); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 303 | $this->_ci_models[] = $name; |
| 304 | return; |
| 305 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 307 | // couldn't find the model |
| 308 | show_error('Unable to locate the model you have specified: '.$model); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 309 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 310 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 312 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 313 | /** |
| 314 | * Database Loader |
| 315 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 316 | * @param string the DB credentials |
| 317 | * @param bool whether to return the DB object |
| 318 | * @param bool whether to enable active record (this allows us to override the config setting) |
| 319 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 320 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 321 | public function database($params = '', $return = FALSE, $active_record = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 322 | { |
| 323 | // Grab the super object |
| 324 | $CI =& get_instance(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 325 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | // Do we even need to load the database class? |
Derek Jones | 9fb6dd1 | 2009-12-05 15:32:48 +0000 | [diff] [blame] | 327 | if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | { |
| 329 | return FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 330 | } |
| 331 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 332 | require_once(BASEPATH.'database/DB.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | |
| 334 | if ($return === TRUE) |
| 335 | { |
| 336 | return DB($params, $active_record); |
| 337 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 338 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 339 | // Initialize the db variable. Needed to prevent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 340 | // reference errors with some configurations |
| 341 | $CI->db = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 342 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | // Load the DB class |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 344 | $CI->db =& DB($params, $active_record); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 346 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | // -------------------------------------------------------------------- |
| 348 | |
| 349 | /** |
| 350 | * Load the Utilities Class |
| 351 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 352 | * @return string |
| 353 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 354 | public function dbutil() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | { |
| 356 | if ( ! class_exists('CI_DB')) |
| 357 | { |
| 358 | $this->database(); |
| 359 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 360 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 361 | $CI =& get_instance(); |
| 362 | |
| 363 | // for backwards compatibility, load dbforge so we can extend dbutils off it |
| 364 | // this use is deprecated and strongly discouraged |
| 365 | $CI->load->dbforge(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 366 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 367 | require_once(BASEPATH.'database/DB_utility.php'); |
| 368 | require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 369 | $class = 'CI_DB_'.$CI->db->dbdriver.'_utility'; |
| 370 | |
Pascal Kriete | 5856002 | 2010-11-10 16:01:20 -0500 | [diff] [blame] | 371 | $CI->dbutil = new $class(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 372 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 373 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 374 | // -------------------------------------------------------------------- |
| 375 | |
| 376 | /** |
| 377 | * Load the Database Forge Class |
| 378 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 379 | * @return string |
| 380 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 381 | public function dbforge() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 382 | { |
| 383 | if ( ! class_exists('CI_DB')) |
| 384 | { |
| 385 | $this->database(); |
| 386 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 387 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | $CI =& get_instance(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 389 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 390 | require_once(BASEPATH.'database/DB_forge.php'); |
| 391 | require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | $class = 'CI_DB_'.$CI->db->dbdriver.'_forge'; |
| 393 | |
| 394 | $CI->dbforge = new $class(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 396 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 397 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | /** |
| 400 | * Load View |
| 401 | * |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 402 | * This function is used to load a "view" file. It has three parameters: |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 403 | * |
| 404 | * 1. The name of the "view" file to be included. |
| 405 | * 2. An associative array of data to be extracted for use in the view. |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 406 | * 3. TRUE/FALSE - whether to return the data or load it. In |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 407 | * some cases it's advantageous to be able to return data so that |
| 408 | * a developer can process it in some way. |
| 409 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | * @param string |
| 411 | * @param array |
| 412 | * @param bool |
| 413 | * @return void |
| 414 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 415 | public function view($view, $vars = array(), $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | { |
| 417 | return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); |
| 418 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 419 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 420 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 421 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 422 | /** |
| 423 | * Load File |
| 424 | * |
| 425 | * This is a generic file loader |
| 426 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 427 | * @param string |
| 428 | * @param bool |
| 429 | * @return string |
| 430 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 431 | public function file($path, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 432 | { |
| 433 | return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); |
| 434 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 435 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 436 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 437 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | /** |
| 439 | * Set Variables |
| 440 | * |
| 441 | * Once variables are set they become available within |
| 442 | * the controller class and its "view" files. |
| 443 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 444 | * @param array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 445 | * @param string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 446 | * @return void |
| 447 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 448 | public function vars($vars = array(), $val = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | { |
| 450 | if ($val != '' AND is_string($vars)) |
| 451 | { |
| 452 | $vars = array($vars => $val); |
| 453 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 454 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 455 | $vars = $this->_ci_object_to_array($vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 456 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 457 | if (is_array($vars) AND count($vars) > 0) |
| 458 | { |
| 459 | foreach ($vars as $key => $val) |
| 460 | { |
| 461 | $this->_ci_cached_vars[$key] = $val; |
| 462 | } |
| 463 | } |
| 464 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 465 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 467 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | /** |
Phil Sturgeon | 8731f64 | 2011-07-22 16:11:34 -0600 | [diff] [blame] | 469 | * Get Variable |
| 470 | * |
| 471 | * Check if a variable is set and retrieve it. |
| 472 | * |
| 473 | * @param array |
| 474 | * @return void |
| 475 | */ |
| 476 | public function get_var($key) |
| 477 | { |
| 478 | return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; |
| 479 | } |
| 480 | |
| 481 | // -------------------------------------------------------------------- |
| 482 | |
| 483 | /** |
Shane Pearson | 81dd223 | 2011-11-18 20:49:35 -0600 | [diff] [blame] | 484 | * Get Variables |
| 485 | * |
| 486 | * Retrieve all loaded variables |
| 487 | * |
| 488 | * @return array |
| 489 | */ |
| 490 | public function get_vars() |
| 491 | { |
| 492 | return $this->_ci_cached_vars; |
| 493 | } |
| 494 | |
| 495 | // -------------------------------------------------------------------- |
| 496 | |
| 497 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 498 | * Load Helper |
| 499 | * |
| 500 | * This function loads the specified helper file. |
| 501 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 502 | * @param mixed |
| 503 | * @return void |
| 504 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 505 | public function helper($helpers = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 506 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 507 | foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 508 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | if (isset($this->_ci_helpers[$helper])) |
| 510 | { |
| 511 | continue; |
| 512 | } |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 513 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 514 | $ext_helper = APPPATH.'helpers/'.config_item('subclass_prefix').$helper.'.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 516 | // Is this a helper extension request? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 517 | if (file_exists($ext_helper)) |
| 518 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 519 | $base_helper = BASEPATH.'helpers/'.$helper.'.php'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 520 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | if ( ! file_exists($base_helper)) |
| 522 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 523 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 524 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 525 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 526 | include_once($ext_helper); |
| 527 | include_once($base_helper); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 528 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 529 | $this->_ci_helpers[$helper] = TRUE; |
| 530 | log_message('debug', 'Helper loaded: '.$helper); |
| 531 | continue; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 532 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 533 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 534 | // Try to load the helper |
| 535 | foreach ($this->_ci_helper_paths as $path) |
| 536 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 537 | if (file_exists($path.'helpers/'.$helper.'.php')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 538 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 539 | include_once($path.'helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 540 | |
| 541 | $this->_ci_helpers[$helper] = TRUE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 542 | log_message('debug', 'Helper loaded: '.$helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 543 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 547 | // unable to load the helper |
| 548 | if ( ! isset($this->_ci_helpers[$helper])) |
| 549 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 550 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 551 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 552 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 553 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 554 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 555 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 556 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 557 | /** |
| 558 | * Load Helpers |
| 559 | * |
| 560 | * This is simply an alias to the above function in case the |
| 561 | * user has written the plural form of this function. |
| 562 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | * @param array |
| 564 | * @return void |
| 565 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 566 | public function helpers($helpers = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 567 | { |
| 568 | $this->helper($helpers); |
| 569 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 570 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 571 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 572 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 573 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | * Loads a language file |
| 575 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 576 | * @param array |
| 577 | * @param string |
| 578 | * @return void |
| 579 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 580 | public function language($file = array(), $lang = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 581 | { |
| 582 | $CI =& get_instance(); |
| 583 | |
| 584 | if ( ! is_array($file)) |
| 585 | { |
| 586 | $file = array($file); |
| 587 | } |
| 588 | |
| 589 | foreach ($file as $langfile) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 590 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 591 | $CI->lang->load($langfile, $lang); |
| 592 | } |
| 593 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 594 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 595 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 596 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 597 | /** |
| 598 | * Loads a config file |
| 599 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 600 | * @param string |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 601 | * @param bool |
| 602 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 603 | * @return void |
| 604 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 605 | public function config($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 606 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 607 | $CI =& get_instance(); |
| 608 | $CI->config->load($file, $use_sections, $fail_gracefully); |
| 609 | } |
| 610 | |
| 611 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 612 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 613 | /** |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 614 | * Driver |
| 615 | * |
| 616 | * Loads a driver library |
| 617 | * |
| 618 | * @param string the name of the class |
| 619 | * @param mixed the optional parameters |
| 620 | * @param string an optional object name |
| 621 | * @return void |
| 622 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 623 | public function driver($library = '', $params = NULL, $object_name = NULL) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 624 | { |
| 625 | if ( ! class_exists('CI_Driver_Library')) |
| 626 | { |
| 627 | // we aren't instantiating an object here, that'll be done by the Library itself |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 628 | require BASEPATH.'libraries/Driver.php'; |
Derek Jones | d5e0cb5 | 2010-03-09 20:20:46 -0600 | [diff] [blame] | 629 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 630 | |
Tom Klingenberg | 6a15b2d | 2011-10-07 20:03:30 +0200 | [diff] [blame] | 631 | if ($library == '') |
| 632 | { |
| 633 | return FALSE; |
| 634 | } |
| 635 | |
Derek Jones | d5e0cb5 | 2010-03-09 20:20:46 -0600 | [diff] [blame] | 636 | // We can save the loader some time since Drivers will *always* be in a subfolder, |
| 637 | // and typically identically named to the library |
| 638 | if ( ! strpos($library, '/')) |
| 639 | { |
Greg Aker | d25e66a | 2010-03-28 01:07:09 -0500 | [diff] [blame] | 640 | $library = ucfirst($library).'/'.$library; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 641 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 642 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 643 | return $this->library($library, $params, $object_name); |
| 644 | } |
| 645 | |
| 646 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 647 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 648 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 649 | * Add Package Path |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | * |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 651 | * Prepends a parent path to the library, model, helper, and config path arrays |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 652 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | * @param string |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 654 | * @param boolean |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 655 | * @return void |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 656 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 657 | public function add_package_path($path, $view_cascade=TRUE) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 658 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 659 | $path = rtrim($path, '/').'/'; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 660 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 661 | array_unshift($this->_ci_library_paths, $path); |
| 662 | array_unshift($this->_ci_model_paths, $path); |
| 663 | array_unshift($this->_ci_helper_paths, $path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 664 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 665 | $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; |
| 666 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 667 | // Add config file path |
| 668 | $config =& $this->_ci_get_component('config'); |
| 669 | array_unshift($config->_config_paths, $path); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 673 | |
| 674 | /** |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 675 | * Get Package Paths |
| 676 | * |
| 677 | * Return a list of all package paths, by default it will ignore BASEPATH. |
| 678 | * |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 679 | * @param string |
| 680 | * @return void |
| 681 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 682 | public function get_package_paths($include_base = FALSE) |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 683 | { |
| 684 | return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths; |
| 685 | } |
| 686 | |
| 687 | // -------------------------------------------------------------------- |
| 688 | |
| 689 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 690 | * Remove Package Path |
| 691 | * |
| 692 | * Remove a path from the library, model, and helper path arrays if it exists |
| 693 | * If no path is provided, the most recently added path is removed. |
| 694 | * |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 695 | * @param type |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 696 | * @param bool |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 697 | * @return type |
| 698 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 699 | public function remove_package_path($path = '', $remove_config_path = TRUE) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 700 | { |
| 701 | $config =& $this->_ci_get_component('config'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 702 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 703 | if ($path == '') |
| 704 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 705 | array_shift($this->_ci_library_paths); |
| 706 | array_shift($this->_ci_model_paths); |
| 707 | array_shift($this->_ci_helper_paths); |
| 708 | array_shift($this->_ci_view_paths); |
| 709 | array_shift($config->_config_paths); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 710 | } |
| 711 | else |
| 712 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 713 | $path = rtrim($path, '/').'/'; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 714 | foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) |
| 715 | { |
| 716 | if (($key = array_search($path, $this->{$var})) !== FALSE) |
| 717 | { |
| 718 | unset($this->{$var}[$key]); |
| 719 | } |
| 720 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 721 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 722 | if (isset($this->_ci_view_paths[$path.'views/'])) |
| 723 | { |
| 724 | unset($this->_ci_view_paths[$path.'views/']); |
| 725 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 726 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 727 | if (($key = array_search($path, $config->_config_paths)) !== FALSE) |
| 728 | { |
| 729 | unset($config->_config_paths[$key]); |
| 730 | } |
| 731 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 732 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 733 | // make sure the application default paths are still in the array |
| 734 | $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); |
| 735 | $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); |
| 736 | $this->_ci_model_paths = array_unique(array_merge($this->_ci_model_paths, array(APPPATH))); |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 737 | $this->_ci_view_paths = array_merge($this->_ci_view_paths, array(APPPATH.'views/' => TRUE)); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 738 | $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); |
| 739 | } |
| 740 | |
| 741 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 742 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 743 | /** |
| 744 | * Loader |
| 745 | * |
| 746 | * This function is used to load views and files. |
| 747 | * Variables are prefixed with _ci_ to avoid symbol collision with |
| 748 | * variables made available to view files |
| 749 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 750 | * @param array |
| 751 | * @return void |
| 752 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 753 | protected function _ci_load($_ci_data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 754 | { |
| 755 | // Set the default data variables |
| 756 | foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) |
| 757 | { |
| 758 | $$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE : $_ci_data[$_ci_val]; |
| 759 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 760 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 761 | $file_exists = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 762 | |
| 763 | // Set the path to the requested file |
Greg Aker | 8807be3 | 2011-04-21 13:06:15 -0500 | [diff] [blame] | 764 | if ($_ci_path != '') |
| 765 | { |
| 766 | $_ci_x = explode('/', $_ci_path); |
| 767 | $_ci_file = end($_ci_x); |
| 768 | } |
| 769 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 770 | { |
| 771 | $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 772 | $_ci_file = ($_ci_ext == '') ? $_ci_view.'.php' : $_ci_view; |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 773 | |
| 774 | foreach ($this->_ci_view_paths as $view_file => $cascade) |
| 775 | { |
| 776 | if (file_exists($view_file.$_ci_file)) |
| 777 | { |
| 778 | $_ci_path = $view_file.$_ci_file; |
| 779 | $file_exists = TRUE; |
| 780 | break; |
| 781 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 782 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 783 | if ( ! $cascade) |
| 784 | { |
| 785 | break; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 786 | } |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 787 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 788 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 789 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 790 | if ( ! $file_exists && ! file_exists($_ci_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 791 | { |
| 792 | show_error('Unable to load the requested file: '.$_ci_file); |
| 793 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 794 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 795 | // This allows anything loaded using $this->load (views, files, etc.) |
| 796 | // to become accessible from within the Controller and Model functions. |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 797 | $_ci_CI =& get_instance(); |
| 798 | foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 799 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 800 | if ( ! isset($this->$_ci_key)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 801 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 802 | $this->$_ci_key =& $_ci_CI->$_ci_key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 | * Extract and cache variables |
| 808 | * |
| 809 | * You can either set variables using the dedicated $this->load_vars() |
| 810 | * function or via the second parameter of this function. We'll merge |
| 811 | * the two types and cache them so that views that are embedded within |
| 812 | * other views can have access to these variables. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 813 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 814 | if (is_array($_ci_vars)) |
| 815 | { |
| 816 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); |
| 817 | } |
| 818 | extract($this->_ci_cached_vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 819 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 820 | /* |
| 821 | * Buffer the output |
| 822 | * |
| 823 | * We buffer the output for two reasons: |
| 824 | * 1. Speed. You get a significant speed boost. |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 825 | * 2. So that the final rendered template can be post-processed by |
| 826 | * the output class. Why do we need post processing? For one thing, |
| 827 | * in order to show the elapsed page load time. Unless we can |
| 828 | * intercept the content right before it's sent to the browser and |
| 829 | * then stop the timer it won't be accurate. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 830 | */ |
| 831 | ob_start(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 832 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 833 | // If the PHP installation does not support short tags we'll |
| 834 | // do a little string replacement, changing the short tags |
| 835 | // to standard PHP echo statements. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 836 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 837 | if ((bool) @ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) |
| 838 | { |
| 839 | echo eval('?>'.preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($_ci_path)))); |
| 840 | } |
| 841 | else |
| 842 | { |
| 843 | include($_ci_path); // include() vs include_once() allows for multiple views with the same name |
| 844 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 845 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 846 | log_message('debug', 'File loaded: '.$_ci_path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 847 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 848 | // Return the file data if requested |
| 849 | if ($_ci_return === TRUE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 850 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 851 | $buffer = ob_get_contents(); |
| 852 | @ob_end_clean(); |
| 853 | return $buffer; |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * Flush the buffer... or buff the flusher? |
| 858 | * |
| 859 | * In order to permit views to be nested within |
| 860 | * other views, we need to flush the content back out whenever |
| 861 | * we are beyond the first level of output buffering so that |
| 862 | * it can be seen and included properly by the first included |
| 863 | * template and any subsequent ones. Oy! |
| 864 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 865 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 866 | if (ob_get_level() > $this->_ci_ob_level + 1) |
| 867 | { |
| 868 | ob_end_flush(); |
| 869 | } |
| 870 | else |
| 871 | { |
Greg Aker | 22f1a63 | 2010-11-10 15:34:35 -0600 | [diff] [blame] | 872 | $_ci_CI->output->append_output(ob_get_contents()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 873 | @ob_end_clean(); |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | // -------------------------------------------------------------------- |
| 878 | |
| 879 | /** |
| 880 | * Load class |
| 881 | * |
| 882 | * This function loads the requested class. |
| 883 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 884 | * @param string the item that is being loaded |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 885 | * @param mixed any additional parameters |
| 886 | * @param string an optional object name |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 887 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 888 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 889 | protected function _ci_load_class($class, $params = NULL, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 890 | { |
| 891 | // Get the class name, and while we're at it trim any slashes. |
| 892 | // The directory path can be included as part of the class name, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 893 | // but we don't want a leading slash |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 894 | $class = str_replace('.php', '', trim($class, '/')); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 895 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 896 | // Was the path included with the class name? |
| 897 | // We look for a slash to determine this |
| 898 | $subdir = ''; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 899 | if (($last_slash = strrpos($class, '/')) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 900 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 901 | // Extract the path |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 902 | $subdir = substr($class, 0, ++$last_slash); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 903 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 904 | // Get the filename from the path |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 905 | $class = substr($class, $last_slash); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | // We'll test for both lowercase and capitalized versions of the file name |
| 909 | foreach (array(ucfirst($class), strtolower($class)) as $class) |
| 910 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 911 | $subclass = APPPATH.'libraries/'.$subdir.config_item('subclass_prefix').$class.'.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 912 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 913 | // Is this a class extension request? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 914 | if (file_exists($subclass)) |
| 915 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 916 | $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 917 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 918 | if ( ! file_exists($baseclass)) |
| 919 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 920 | log_message('error', 'Unable to load the requested class: '.$class); |
| 921 | show_error('Unable to load the requested class: '.$class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 922 | } |
| 923 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 924 | // Safety: Was the class already loaded by a previous call? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 925 | if (in_array($subclass, $this->_ci_loaded_files)) |
| 926 | { |
| 927 | // Before we deem this to be a duplicate request, let's see |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 928 | // if a custom object name is being supplied. If so, we'll |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 929 | // return a new instance of the object |
| 930 | if ( ! is_null($object_name)) |
| 931 | { |
| 932 | $CI =& get_instance(); |
| 933 | if ( ! isset($CI->$object_name)) |
| 934 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 935 | return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 938 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 939 | $is_duplicate = TRUE; |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 940 | log_message('debug', $class.' class already loaded. Second attempt ignored.'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 941 | return; |
| 942 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 943 | |
| 944 | include_once($baseclass); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 945 | include_once($subclass); |
| 946 | $this->_ci_loaded_files[] = $subclass; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 947 | |
| 948 | return $this->_ci_init_class($class, config_item('subclass_prefix'), $params, $object_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 949 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 950 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 951 | // Lets search for the requested library file and load it. |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 952 | $is_duplicate = FALSE; |
| 953 | foreach ($this->_ci_library_paths as $path) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 954 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 955 | $filepath = $path.'libraries/'.$subdir.$class.'.php'; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 956 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 957 | // Does the file exist? No? Bummer... |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 958 | if ( ! file_exists($filepath)) |
| 959 | { |
| 960 | continue; |
| 961 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 962 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 963 | // Safety: Was the class already loaded by a previous call? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 964 | if (in_array($filepath, $this->_ci_loaded_files)) |
| 965 | { |
| 966 | // Before we deem this to be a duplicate request, let's see |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 967 | // if a custom object name is being supplied. If so, we'll |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 968 | // return a new instance of the object |
| 969 | if ( ! is_null($object_name)) |
| 970 | { |
| 971 | $CI =& get_instance(); |
| 972 | if ( ! isset($CI->$object_name)) |
| 973 | { |
| 974 | return $this->_ci_init_class($class, '', $params, $object_name); |
| 975 | } |
| 976 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 977 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 978 | $is_duplicate = TRUE; |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 979 | log_message('debug', $class.' class already loaded. Second attempt ignored.'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 980 | return; |
| 981 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 982 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 983 | include_once($filepath); |
| 984 | $this->_ci_loaded_files[] = $filepath; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 985 | return $this->_ci_init_class($class, '', $params, $object_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 986 | } |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 987 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 988 | } // END FOREACH |
| 989 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 990 | // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 991 | if ($subdir == '') |
| 992 | { |
| 993 | $path = strtolower($class).'/'.$class; |
| 994 | return $this->_ci_load_class($path, $params); |
| 995 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 996 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 997 | // If we got this far we were unable to find the requested class. |
| 998 | // We do not issue errors if the load call failed due to a duplicate request |
| 999 | if ($is_duplicate == FALSE) |
| 1000 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 1001 | log_message('error', 'Unable to load the requested class: '.$class); |
| 1002 | show_error('Unable to load the requested class: '.$class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1003 | } |
| 1004 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1005 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1006 | // -------------------------------------------------------------------- |
| 1007 | |
| 1008 | /** |
| 1009 | * Instantiates a class |
| 1010 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1011 | * @param string |
| 1012 | * @param string |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 1013 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1014 | * @param string an optional object name |
| 1015 | * @return null |
| 1016 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1017 | protected function _ci_init_class($class, $prefix = '', $config = FALSE, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1018 | { |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1019 | // Is there an associated config file for this class? Note: these should always be lowercase |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1020 | if ($config === NULL) |
| 1021 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1022 | // Fetch the config paths containing any package paths |
| 1023 | $config_component = $this->_ci_get_component('config'); |
| 1024 | |
| 1025 | if (is_array($config_component->_config_paths)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1027 | // Break on the first found file, thus package files |
| 1028 | // are not overridden by default paths |
| 1029 | foreach ($config_component->_config_paths as $path) |
| 1030 | { |
| 1031 | // We test for both uppercase and lowercase, for servers that |
joelcox | 1bfd9fa | 2011-01-16 18:49:39 +0100 | [diff] [blame] | 1032 | // are case-sensitive with regard to file names. Check for environment |
| 1033 | // first, global next |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1034 | if (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) |
joelcox | 1bfd9fa | 2011-01-16 18:49:39 +0100 | [diff] [blame] | 1035 | { |
Phil Sturgeon | 6f1b384 | 2011-08-13 10:28:28 -0600 | [diff] [blame] | 1036 | include($path .'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); |
joelcox | 1bfd9fa | 2011-01-16 18:49:39 +0100 | [diff] [blame] | 1037 | break; |
| 1038 | } |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1039 | elseif (defined('ENVIRONMENT') AND file_exists($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) |
joelcox | 1bfd9fa | 2011-01-16 18:49:39 +0100 | [diff] [blame] | 1040 | { |
Phil Sturgeon | 6f1b384 | 2011-08-13 10:28:28 -0600 | [diff] [blame] | 1041 | include($path .'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); |
joelcox | 1bfd9fa | 2011-01-16 18:49:39 +0100 | [diff] [blame] | 1042 | break; |
| 1043 | } |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1044 | elseif (file_exists($path .'config/'.strtolower($class).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1045 | { |
Phil Sturgeon | 6f1b384 | 2011-08-13 10:28:28 -0600 | [diff] [blame] | 1046 | include($path .'config/'.strtolower($class).'.php'); |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1047 | break; |
| 1048 | } |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1049 | elseif (file_exists($path .'config/'.ucfirst(strtolower($class)).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1050 | { |
Phil Sturgeon | 6f1b384 | 2011-08-13 10:28:28 -0600 | [diff] [blame] | 1051 | include($path .'config/'.ucfirst(strtolower($class)).'.php'); |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1052 | break; |
| 1053 | } |
| 1054 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1055 | } |
| 1056 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1057 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1058 | if ($prefix == '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1059 | { |
| 1060 | if (class_exists('CI_'.$class)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1061 | { |
| 1062 | $name = 'CI_'.$class; |
| 1063 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1064 | elseif (class_exists(config_item('subclass_prefix').$class)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1065 | { |
| 1066 | $name = config_item('subclass_prefix').$class; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | $name = $class; |
| 1071 | } |
| 1072 | } |
| 1073 | else |
| 1074 | { |
| 1075 | $name = $prefix.$class; |
| 1076 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1077 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1078 | // Is the class name valid? |
| 1079 | if ( ! class_exists($name)) |
| 1080 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 1081 | log_message('error', 'Non-existent class: '.$name); |
| 1082 | show_error('Non-existent class: '.$class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1083 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1084 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1085 | // Set the variable name we will assign the class to |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 1086 | // Was a custom class name supplied? If so we'll use it |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1087 | $class = strtolower($class); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1088 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1089 | if (is_null($object_name)) |
| 1090 | { |
| 1091 | $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class]; |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | $classvar = $object_name; |
| 1096 | } |
| 1097 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1098 | // Save the class name and object name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1099 | $this->_ci_classes[$class] = $classvar; |
| 1100 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1101 | // Instantiate the class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1102 | $CI =& get_instance(); |
| 1103 | if ($config !== NULL) |
| 1104 | { |
| 1105 | $CI->$classvar = new $name($config); |
| 1106 | } |
| 1107 | else |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1108 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1109 | $CI->$classvar = new $name; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1113 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1114 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1115 | /** |
| 1116 | * Autoloader |
| 1117 | * |
| 1118 | * The config/autoload.php file contains an array that permits sub-systems, |
Derek Jones | c6da503 | 2010-03-09 20:44:27 -0600 | [diff] [blame] | 1119 | * libraries, and helpers to be loaded automatically. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1120 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1121 | * @param array |
| 1122 | * @return void |
| 1123 | */ |
Shane Pearson | 665baec | 2011-08-22 18:52:19 -0500 | [diff] [blame] | 1124 | protected function _ci_autoloader() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1125 | { |
Greg Aker | d96f882 | 2011-12-27 16:23:47 -0600 | [diff] [blame] | 1126 | if (defined('ENVIRONMENT') AND file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) |
| 1127 | { |
| 1128 | include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | include(APPPATH.'config/autoload.php'); |
| 1133 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1134 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1135 | if ( ! isset($autoload)) |
| 1136 | { |
| 1137 | return FALSE; |
| 1138 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1139 | |
Phil Sturgeon | 9730c75 | 2010-12-15 10:50:15 +0000 | [diff] [blame] | 1140 | // Autoload packages |
| 1141 | if (isset($autoload['packages'])) |
| 1142 | { |
| 1143 | foreach ($autoload['packages'] as $package_path) |
| 1144 | { |
| 1145 | $this->add_package_path($package_path); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1149 | // Load any custom config file |
| 1150 | if (count($autoload['config']) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1151 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1152 | $CI =& get_instance(); |
| 1153 | foreach ($autoload['config'] as $key => $val) |
| 1154 | { |
| 1155 | $CI->config->load($val); |
| 1156 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1157 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1158 | |
Derek Jones | c6da503 | 2010-03-09 20:44:27 -0600 | [diff] [blame] | 1159 | // Autoload helpers and languages |
| 1160 | foreach (array('helper', 'language') as $type) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1161 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1162 | if (isset($autoload[$type]) AND count($autoload[$type]) > 0) |
| 1163 | { |
| 1164 | $this->$type($autoload[$type]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1165 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | // A little tweak to remain backward compatible |
| 1169 | // The $autoload['core'] item was deprecated |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1170 | if ( ! isset($autoload['libraries']) AND isset($autoload['core'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1171 | { |
| 1172 | $autoload['libraries'] = $autoload['core']; |
| 1173 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1174 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1175 | // Load libraries |
| 1176 | if (isset($autoload['libraries']) AND count($autoload['libraries']) > 0) |
| 1177 | { |
| 1178 | // Load the database driver. |
| 1179 | if (in_array('database', $autoload['libraries'])) |
| 1180 | { |
| 1181 | $this->database(); |
| 1182 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); |
| 1183 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1184 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1185 | // Load all other libraries |
| 1186 | foreach ($autoload['libraries'] as $item) |
| 1187 | { |
| 1188 | $this->library($item); |
| 1189 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1190 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1191 | |
| 1192 | // Autoload models |
| 1193 | if (isset($autoload['model'])) |
| 1194 | { |
| 1195 | $this->model($autoload['model']); |
| 1196 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1197 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1198 | |
| 1199 | // -------------------------------------------------------------------- |
| 1200 | |
| 1201 | /** |
| 1202 | * Object to Array |
| 1203 | * |
| 1204 | * Takes an object as input and converts the class variables to array key/vals |
| 1205 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1206 | * @param object |
| 1207 | * @return array |
| 1208 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1209 | protected function _ci_object_to_array($object) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1210 | { |
| 1211 | return (is_object($object)) ? get_object_vars($object) : $object; |
| 1212 | } |
| 1213 | |
| 1214 | // -------------------------------------------------------------------- |
| 1215 | |
| 1216 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1217 | * Get a reference to a specific library or model |
| 1218 | * |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 1219 | * @param string |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1220 | * @return bool |
| 1221 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1222 | protected function &_ci_get_component($component) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1223 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 1224 | $CI =& get_instance(); |
| 1225 | return $CI->$component; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1229 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1230 | /** |
| 1231 | * Prep filename |
| 1232 | * |
| 1233 | * This function preps the name of various items to make loading them more reliable. |
| 1234 | * |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1235 | * @param mixed |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 1236 | * @param string |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1237 | * @return array |
| 1238 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1239 | protected function _ci_prep_filename($filename, $extension) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1240 | { |
| 1241 | if ( ! is_array($filename)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1242 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1243 | return array(strtolower(str_replace('.php', '', str_replace($extension, '', $filename)).$extension)); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1244 | } |
| 1245 | else |
| 1246 | { |
| 1247 | foreach ($filename as $key => $val) |
| 1248 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1249 | $filename[$key] = strtolower(str_replace('.php', '', str_replace($extension, '', $val)).$extension); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1250 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1251 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1252 | return $filename; |
| 1253 | } |
| 1254 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /* End of file Loader.php */ |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame^] | 1258 | /* Location: ./system/core/Loader.php */ |