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