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