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