Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * Loader Class |
| 42 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 43 | * Loads framework components. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 44 | * |
| 45 | * @package CodeIgniter |
| 46 | * @subpackage Libraries |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | * @category Loader |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 48 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 49 | * @link http://codeigniter.com/user_guide/libraries/loader.html |
| 50 | */ |
| 51 | class CI_Loader { |
| 52 | |
| 53 | // All these are set automatically. Don't mess with them. |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 54 | /** |
| 55 | * Nesting level of the output buffering mechanism |
| 56 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 57 | * @var int |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 58 | */ |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 59 | protected $_ci_ob_level; |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 60 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 61 | /** |
| 62 | * List of paths to load views from |
| 63 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 64 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 65 | */ |
Ted Wood | 4c22364 | 2013-01-05 16:50:31 -0800 | [diff] [blame] | 66 | protected $_ci_view_paths = array(VIEWPATH => TRUE); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 67 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 68 | /** |
| 69 | * List of paths to load libraries from |
| 70 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 71 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 72 | */ |
Ted Wood | 4c22364 | 2013-01-05 16:50:31 -0800 | [diff] [blame] | 73 | protected $_ci_library_paths = array(APPPATH, BASEPATH); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 74 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 75 | /** |
| 76 | * List of paths to load models from |
| 77 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 78 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 79 | */ |
Ted Wood | 4c22364 | 2013-01-05 16:50:31 -0800 | [diff] [blame] | 80 | protected $_ci_model_paths = array(APPPATH); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 81 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 82 | /** |
| 83 | * List of paths to load helpers from |
| 84 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 85 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 86 | */ |
Ted Wood | 4c22364 | 2013-01-05 16:50:31 -0800 | [diff] [blame] | 87 | protected $_ci_helper_paths = array(APPPATH, BASEPATH); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 88 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 89 | /** |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 90 | * List of cached variables |
| 91 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 92 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 93 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 94 | protected $_ci_cached_vars = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 95 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 96 | /** |
| 97 | * List of loaded classes |
| 98 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 99 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 100 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 101 | protected $_ci_classes = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 102 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 103 | /** |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 104 | * List of loaded models |
| 105 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 106 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 107 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 108 | protected $_ci_models = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 109 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 110 | /** |
| 111 | * List of loaded helpers |
| 112 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 113 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 114 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 115 | protected $_ci_helpers = array(); |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 116 | |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 117 | /** |
| 118 | * List of class name mappings |
| 119 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 120 | * @var array |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 121 | */ |
Timothy Warren | 48a7fbb | 2012-04-23 11:58:16 -0400 | [diff] [blame] | 122 | protected $_ci_varmap = array( |
Timothy Warren | 40403d2 | 2012-04-19 16:38:50 -0400 | [diff] [blame] | 123 | 'unit_test' => 'unit', |
| 124 | 'user_agent' => 'agent' |
| 125 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 127 | // -------------------------------------------------------------------- |
| 128 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 130 | * Class constructor |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | * |
Andrey Andreev | cdac248 | 2012-11-03 18:09:01 +0200 | [diff] [blame] | 132 | * Sets component load paths, gets the initial output buffering level. |
Andrey Andreev | 92ebfb6 | 2012-05-17 12:49:24 +0300 | [diff] [blame] | 133 | * |
| 134 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 135 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 136 | public function __construct() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 137 | { |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 138 | $this->_ci_ob_level = ob_get_level(); |
| 139 | $this->_ci_classes =& is_loaded(); |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 140 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 141 | log_message('info', 'Loader Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 142 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 143 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 144 | // -------------------------------------------------------------------- |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 145 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 146 | /** |
Andrey Andreev | cdac248 | 2012-11-03 18:09:01 +0200 | [diff] [blame] | 147 | * Initializer |
| 148 | * |
| 149 | * @todo Figure out a way to move this to the constructor |
| 150 | * without breaking *package_path*() methods. |
| 151 | * @uses CI_Loader::_ci_autoloader() |
| 152 | * @used-by CI_Controller::__construct() |
| 153 | * @return void |
| 154 | */ |
| 155 | public function initialize() |
| 156 | { |
Andrey Andreev | cdac248 | 2012-11-03 18:09:01 +0200 | [diff] [blame] | 157 | $this->_ci_autoloader(); |
| 158 | } |
| 159 | |
| 160 | // -------------------------------------------------------------------- |
| 161 | |
| 162 | /** |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 163 | * Is Loaded |
| 164 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 165 | * A utility method to test if a class is in the self::$_ci_classes array. |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 166 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 167 | * @used-by Mainly used by Form Helper function _get_validation_object(). |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 168 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 169 | * @param string $class Class name to check for |
| 170 | * @return string|bool Class object name if loaded or FALSE |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 171 | */ |
| 172 | public function is_loaded($class) |
| 173 | { |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 174 | return array_search(ucfirst($class), $this->_ci_classes, TRUE); |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 178 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 179 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 180 | * Library Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 181 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 182 | * Loads and instantiates libraries. |
| 183 | * Designed to be called from application controllers. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 184 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 185 | * @param string $library Library name |
| 186 | * @param array $params Optional parameters to pass to the library class constructor |
| 187 | * @param string $object_name An optional object name to assign to |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 188 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 189 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 190 | public function library($library, $params = NULL, $object_name = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 191 | { |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 192 | if (empty($library)) |
| 193 | { |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 194 | return $this; |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 195 | } |
| 196 | elseif (is_array($library)) |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 197 | { |
Andrey Andreev | 88cf55b | 2014-01-17 15:38:30 +0200 | [diff] [blame] | 198 | foreach ($library as $key => $value) |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 199 | { |
Andrey Andreev | 88cf55b | 2014-01-17 15:38:30 +0200 | [diff] [blame] | 200 | if (is_int($key)) |
| 201 | { |
| 202 | $this->library($value, $params); |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | $this->library($key, $params, $value); |
| 207 | } |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 208 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 209 | |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 210 | return $this; |
Greg Aker | ce43396 | 2010-10-12 09:29:35 -0500 | [diff] [blame] | 211 | } |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 212 | |
vlakoff | 1228fe2 | 2013-01-14 01:30:09 +0100 | [diff] [blame] | 213 | if ($params !== NULL && ! is_array($params)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | { |
| 215 | $params = NULL; |
| 216 | } |
| 217 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 218 | $this->_ci_load_library($library, $params, $object_name); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 219 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 223 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | /** |
| 225 | * Model Loader |
| 226 | * |
James | 7b272ff | 2014-03-20 19:02:37 +0000 | [diff] [blame] | 227 | * Loads and instantiates models. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 229 | * @param string $model Model name |
| 230 | * @param string $name An optional object name to assign to |
| 231 | * @param bool $db_conn An optional database connection configuration to initialize |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 232 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 234 | public function model($model, $name = '', $db_conn = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | { |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 236 | if (empty($model)) |
| 237 | { |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 238 | return $this; |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 239 | } |
| 240 | elseif (is_array($model)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 241 | { |
Andrey Andreev | 5a519db | 2013-01-12 04:19:19 +0200 | [diff] [blame] | 242 | foreach ($model as $key => $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 243 | { |
Ahmad Anbar | 4005e3c | 2013-09-12 23:33:28 +0300 | [diff] [blame] | 244 | is_int($key) ? $this->model($value, '', $db_conn) : $this->model($key, $value, $db_conn); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 245 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 246 | |
| 247 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 250 | $path = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | // 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] | 253 | if (($last_slash = strrpos($model, '/')) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 254 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 255 | // The path is in front of the last slash |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 256 | $path = substr($model, 0, ++$last_slash); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 257 | |
| 258 | // And the model name behind it |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 259 | $model = substr($model, $last_slash); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | |
Phil Sturgeon | 10d78f6 | 2012-06-04 14:41:53 -0500 | [diff] [blame] | 262 | if (empty($name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | { |
| 264 | $name = $model; |
| 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 | if (in_array($name, $this->_ci_models, TRUE)) |
| 268 | { |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 269 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 271 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | $CI =& get_instance(); |
| 273 | if (isset($CI->$name)) |
| 274 | { |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 275 | throw new RuntimeException('The model name you are loading is the name of a resource that is already being used: '.$name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 276 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 278 | if ($db_conn !== FALSE && ! class_exists('CI_DB', FALSE)) |
| 279 | { |
| 280 | if ($db_conn === TRUE) |
| 281 | { |
| 282 | $db_conn = ''; |
| 283 | } |
| 284 | |
Andrey Andreev | 5f83969 | 2014-03-24 17:34:54 +0200 | [diff] [blame] | 285 | $this->database($db_conn, FALSE, TRUE); |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | if ( ! class_exists('CI_Model', FALSE)) |
| 289 | { |
| 290 | load_class('Model', 'core'); |
| 291 | } |
| 292 | |
Andrey Andreev | 825fab7 | 2015-08-17 09:52:42 +0300 | [diff] [blame^] | 293 | $model = ucfirst($model); |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 294 | if ( ! class_exists($model)) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 295 | { |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 296 | foreach ($this->_ci_model_paths as $mod_path) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 297 | { |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 298 | if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) |
| 299 | { |
| 300 | continue; |
| 301 | } |
| 302 | |
| 303 | require_once($mod_path.'models/'.$path.$model.'.php'); |
| 304 | if ( ! class_exists($model, FALSE)) |
| 305 | { |
| 306 | throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model); |
| 307 | } |
| 308 | |
| 309 | break; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 310 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 311 | |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 312 | if ( ! class_exists($model, FALSE)) |
| 313 | { |
| 314 | throw new RuntimeException('Unable to locate the model you have specified: '.$model); |
| 315 | } |
| 316 | } |
| 317 | elseif ( ! is_subclass_of($model, 'CI_Model')) |
| 318 | { |
| 319 | throw new RuntimeException("Class ".$model." already exists and doesn't extend CI_Model"); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 320 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 321 | |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 322 | $this->_ci_models[] = $name; |
| 323 | $CI->$name = new $model(); |
| 324 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 325 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 326 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 327 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 328 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | /** |
| 330 | * Database Loader |
| 331 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 332 | * @param mixed $params Database configuration options |
| 333 | * @param bool $return Whether to return the database object |
| 334 | * @param bool $query_builder Whether to enable Query Builder |
| 335 | * (overrides the configuration setting) |
| 336 | * |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 337 | * @return object|bool Database object if $return is set to TRUE, |
| 338 | * FALSE on failure, CI_Loader instance in any other case |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 339 | */ |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 340 | public function database($params = '', $return = FALSE, $query_builder = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | { |
| 342 | // Grab the super object |
| 343 | $CI =& get_instance(); |
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 | // Do we even need to load the database class? |
Andrey Andreev | 9d0ab04 | 2012-10-24 21:47:39 +0300 | [diff] [blame] | 346 | if ($return === FALSE && $query_builder === NULL && isset($CI->db) && is_object($CI->db) && ! empty($CI->db->conn_id)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | { |
| 348 | return FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 351 | require_once(BASEPATH.'database/DB.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 352 | |
| 353 | if ($return === TRUE) |
| 354 | { |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 355 | return DB($params, $query_builder); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 357 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 358 | // Initialize the db variable. Needed to prevent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | // reference errors with some configurations |
| 360 | $CI->db = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 361 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | // Load the DB class |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 363 | $CI->db =& DB($params, $query_builder); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 364 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 366 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | // -------------------------------------------------------------------- |
| 368 | |
| 369 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 370 | * Load the Database Utilities Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | * |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 372 | * @param object $db Database object |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 373 | * @param bool $return Whether to return the DB Utilities class object or not |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 374 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 375 | */ |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 376 | public function dbutil($db = NULL, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 378 | $CI =& get_instance(); |
| 379 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 380 | if ( ! is_object($db) OR ! ($db instanceof CI_DB)) |
| 381 | { |
| 382 | class_exists('CI_DB', FALSE) OR $this->database(); |
| 383 | $db =& $CI->db; |
| 384 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 385 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 386 | require_once(BASEPATH.'database/DB_utility.php'); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 387 | require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php'); |
| 388 | $class = 'CI_DB_'.$db->dbdriver.'_utility'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 390 | if ($return === TRUE) |
| 391 | { |
| 392 | return new $class($db); |
| 393 | } |
| 394 | |
| 395 | $CI->dbutil = new $class($db); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 396 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 397 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 398 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 399 | // -------------------------------------------------------------------- |
| 400 | |
| 401 | /** |
| 402 | * Load the Database Forge Class |
| 403 | * |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 404 | * @param object $db Database object |
| 405 | * @param bool $return Whether to return the DB Forge class object or not |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 406 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 407 | */ |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 408 | public function dbforge($db = NULL, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 409 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 410 | $CI =& get_instance(); |
| 411 | if ( ! is_object($db) OR ! ($db instanceof CI_DB)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 412 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 413 | class_exists('CI_DB', FALSE) OR $this->database(); |
| 414 | $db =& $CI->db; |
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 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 417 | require_once(BASEPATH.'database/DB_forge.php'); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 418 | require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php'); |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 419 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 420 | if ( ! empty($db->subdriver)) |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 421 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 422 | $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php'; |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 423 | if (file_exists($driver_path)) |
| 424 | { |
| 425 | require_once($driver_path); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 426 | $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge'; |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | else |
| 430 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 431 | $class = 'CI_DB_'.$db->dbdriver.'_forge'; |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 432 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 434 | if ($return === TRUE) |
| 435 | { |
| 436 | return new $class($db); |
| 437 | } |
| 438 | |
| 439 | $CI->dbforge = new $class($db); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 440 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 441 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 442 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 444 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 445 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 446 | * View Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 447 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 448 | * Loads "view" files. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 450 | * @param string $view View name |
| 451 | * @param array $vars An associative array of data |
| 452 | * to be extracted for use in the view |
| 453 | * @param bool $return Whether to return the view output |
| 454 | * or leave it to the Output class |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 455 | * @return object|string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 456 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 457 | public function view($view, $vars = array(), $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | { |
| 459 | return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return)); |
| 460 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 461 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 465 | * Generic File Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 466 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 467 | * @param string $path File path |
| 468 | * @param bool $return Whether to return the file output |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 469 | * @return object|string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 471 | public function file($path, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 472 | { |
| 473 | return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); |
| 474 | } |
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 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 477 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 478 | /** |
| 479 | * Set Variables |
| 480 | * |
| 481 | * Once variables are set they become available within |
| 482 | * the controller class and its "view" files. |
| 483 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 484 | * @param array|object|string $vars |
| 485 | * An associative array or object containing values |
| 486 | * to be set, or a value's name if string |
| 487 | * @param string $val Value to set, only used if $vars is a string |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 488 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 489 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 490 | public function vars($vars, $val = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 491 | { |
vlakoff | a5e0ea8 | 2013-02-27 18:17:35 +0100 | [diff] [blame] | 492 | if (is_string($vars)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 493 | { |
| 494 | $vars = array($vars => $val); |
| 495 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 496 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 497 | $vars = $this->_ci_object_to_array($vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 498 | |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 499 | if (is_array($vars) && count($vars) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | { |
| 501 | foreach ($vars as $key => $val) |
| 502 | { |
| 503 | $this->_ci_cached_vars[$key] = $val; |
| 504 | } |
| 505 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 506 | |
| 507 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 509 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 510 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 511 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 512 | /** |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 513 | * Clear Cached Variables |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 514 | * |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 515 | * Clears the cached variables. |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 516 | * |
Andrey Andreev | 10fb7d1 | 2015-08-03 10:05:29 +0300 | [diff] [blame] | 517 | * @return CI_Loader |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 518 | */ |
| 519 | public function clear_vars() |
| 520 | { |
| 521 | $this->_ci_cached_vars = array(); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 522 | return $this; |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 523 | } |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 524 | |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 525 | // -------------------------------------------------------------------- |
| 526 | |
| 527 | /** |
Phil Sturgeon | 8731f64 | 2011-07-22 16:11:34 -0600 | [diff] [blame] | 528 | * Get Variable |
| 529 | * |
| 530 | * Check if a variable is set and retrieve it. |
| 531 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 532 | * @param string $key Variable name |
| 533 | * @return mixed The variable or NULL if not found |
Phil Sturgeon | 8731f64 | 2011-07-22 16:11:34 -0600 | [diff] [blame] | 534 | */ |
| 535 | public function get_var($key) |
| 536 | { |
| 537 | return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; |
| 538 | } |
| 539 | |
| 540 | // -------------------------------------------------------------------- |
| 541 | |
| 542 | /** |
Shane Pearson | 81dd223 | 2011-11-18 20:49:35 -0600 | [diff] [blame] | 543 | * Get Variables |
| 544 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 545 | * Retrieves all loaded variables. |
Shane Pearson | 81dd223 | 2011-11-18 20:49:35 -0600 | [diff] [blame] | 546 | * |
| 547 | * @return array |
| 548 | */ |
| 549 | public function get_vars() |
| 550 | { |
| 551 | return $this->_ci_cached_vars; |
| 552 | } |
| 553 | |
| 554 | // -------------------------------------------------------------------- |
| 555 | |
| 556 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 557 | * Helper Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 558 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 559 | * @param string|string[] $helpers Helper name(s) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 560 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 561 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 562 | public function helper($helpers = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 563 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 564 | foreach ($this->_ci_prep_filename($helpers, '_helper') as $helper) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 565 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 566 | if (isset($this->_ci_helpers[$helper])) |
| 567 | { |
| 568 | continue; |
| 569 | } |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 570 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 571 | // Is this a helper extension request? |
Andrey Andreev | 12d7b46 | 2012-11-12 13:42:09 +0200 | [diff] [blame] | 572 | $ext_helper = config_item('subclass_prefix').$helper; |
| 573 | $ext_loaded = FALSE; |
| 574 | foreach ($this->_ci_helper_paths as $path) |
| 575 | { |
| 576 | if (file_exists($path.'helpers/'.$ext_helper.'.php')) |
| 577 | { |
| 578 | include_once($path.'helpers/'.$ext_helper.'.php'); |
| 579 | $ext_loaded = TRUE; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // If we have loaded extensions - check if the base one is here |
| 584 | if ($ext_loaded === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 586 | $base_helper = BASEPATH.'helpers/'.$helper.'.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 587 | if ( ! file_exists($base_helper)) |
| 588 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 589 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 590 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 591 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 592 | include_once($base_helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 593 | $this->_ci_helpers[$helper] = TRUE; |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 594 | log_message('info', 'Helper loaded: '.$helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 595 | continue; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 596 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 597 | |
Andrey Andreev | 12d7b46 | 2012-11-12 13:42:09 +0200 | [diff] [blame] | 598 | // No extensions found ... try loading regular helpers and/or overrides |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 599 | foreach ($this->_ci_helper_paths as $path) |
| 600 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 601 | if (file_exists($path.'helpers/'.$helper.'.php')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 602 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 603 | include_once($path.'helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 604 | |
| 605 | $this->_ci_helpers[$helper] = TRUE; |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 606 | log_message('info', 'Helper loaded: '.$helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 607 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 611 | // unable to load the helper |
| 612 | if ( ! isset($this->_ci_helpers[$helper])) |
| 613 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 614 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 615 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 616 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 617 | |
| 618 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 619 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 620 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 621 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 622 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 623 | /** |
| 624 | * Load Helpers |
| 625 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 626 | * An alias for the helper() method in case the developer has |
| 627 | * written the plural form of it. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 628 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 629 | * @uses CI_Loader::helper() |
| 630 | * @param string|string[] $helpers Helper name(s) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 631 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 632 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 633 | public function helpers($helpers = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 634 | { |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 635 | return $this->helper($helpers); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 637 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | // -------------------------------------------------------------------- |
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 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 641 | * Language Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 642 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 643 | * Loads language files. |
| 644 | * |
| 645 | * @param string|string[] $files List of language file names to load |
| 646 | * @param string Language name |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 647 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 649 | public function language($files, $lang = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | { |
Andrey Andreev | d8e31ec | 2014-11-07 12:17:50 +0200 | [diff] [blame] | 651 | get_instance()->lang->load($files, $lang); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 652 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 654 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 655 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 656 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 657 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 658 | * Config Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 659 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 660 | * Loads a config file (an alias for CI_Config::load()). |
| 661 | * |
| 662 | * @uses CI_Config::load() |
| 663 | * @param string $file Configuration file name |
| 664 | * @param bool $use_sections Whether configuration values should be loaded into their own section |
| 665 | * @param bool $fail_gracefully Whether to just return FALSE or display an error message |
| 666 | * @return bool TRUE if the file was loaded correctly or FALSE on failure |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 667 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 668 | public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 669 | { |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 670 | return get_instance()->config->load($file, $use_sections, $fail_gracefully); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 674 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 675 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 676 | * Driver Loader |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 677 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 678 | * Loads a driver library. |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 679 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 680 | * @param string|string[] $library Driver name(s) |
| 681 | * @param array $params Optional parameters to pass to the driver |
| 682 | * @param string $object_name An optional object name to assign to |
| 683 | * |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 684 | * @return object|bool Object or FALSE on failure if $library is a string |
| 685 | * and $object_name is set. CI_Loader instance otherwise. |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 686 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 687 | public function driver($library, $params = NULL, $object_name = NULL) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 688 | { |
Christopher Guiney | b54d355 | 2012-03-10 08:38:10 -0800 | [diff] [blame] | 689 | if (is_array($library)) |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 690 | { |
Christopher Guiney | b54d355 | 2012-03-10 08:38:10 -0800 | [diff] [blame] | 691 | foreach ($library as $driver) |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 692 | { |
| 693 | $this->driver($driver); |
| 694 | } |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 695 | |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 696 | return $this; |
| 697 | } |
| 698 | elseif (empty($library)) |
Tom Klingenberg | 6a15b2d | 2011-10-07 20:03:30 +0200 | [diff] [blame] | 699 | { |
| 700 | return FALSE; |
| 701 | } |
| 702 | |
vlakoff | fadb822 | 2013-05-12 10:57:09 +0200 | [diff] [blame] | 703 | if ( ! class_exists('CI_Driver_Library', FALSE)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 704 | { |
| 705 | // We aren't instantiating an object here, just making the base class available |
| 706 | require BASEPATH.'libraries/Driver.php'; |
| 707 | } |
| 708 | |
Derek Jones | d5e0cb5 | 2010-03-09 20:20:46 -0600 | [diff] [blame] | 709 | // We can save the loader some time since Drivers will *always* be in a subfolder, |
| 710 | // and typically identically named to the library |
| 711 | if ( ! strpos($library, '/')) |
| 712 | { |
Greg Aker | d25e66a | 2010-03-28 01:07:09 -0500 | [diff] [blame] | 713 | $library = ucfirst($library).'/'.$library; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 714 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 715 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 716 | return $this->library($library, $params, $object_name); |
| 717 | } |
| 718 | |
| 719 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 720 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 721 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 722 | * Add Package Path |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 723 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 724 | * Prepends a parent path to the library, model, helper and config |
| 725 | * path arrays. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 726 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 727 | * @see CI_Loader::$_ci_library_paths |
| 728 | * @see CI_Loader::$_ci_model_paths |
| 729 | * @see CI_Loader::$_ci_helper_paths |
| 730 | * @see CI_Config::$_config_paths |
| 731 | * |
| 732 | * @param string $path Path to add |
| 733 | * @param bool $view_cascade (default: TRUE) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 734 | * @return object |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 735 | */ |
Andrey Andreev | cce9180 | 2012-06-12 13:25:31 +0300 | [diff] [blame] | 736 | public function add_package_path($path, $view_cascade = TRUE) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 737 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 738 | $path = rtrim($path, '/').'/'; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 739 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 740 | array_unshift($this->_ci_library_paths, $path); |
| 741 | array_unshift($this->_ci_model_paths, $path); |
| 742 | array_unshift($this->_ci_helper_paths, $path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 743 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 744 | $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; |
| 745 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 746 | // Add config file path |
| 747 | $config =& $this->_ci_get_component('config'); |
and-ers | b3ec942 | 2013-01-03 16:05:12 +0100 | [diff] [blame] | 748 | $config->_config_paths[] = $path; |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 749 | |
| 750 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 754 | |
| 755 | /** |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 756 | * Get Package Paths |
| 757 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 758 | * Return a list of all package paths. |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 759 | * |
vlakoff | cdc6113 | 2013-05-10 16:47:47 +0200 | [diff] [blame] | 760 | * @param bool $include_base Whether to include BASEPATH (default: FALSE) |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 761 | * @return array |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 762 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 763 | public function get_package_paths($include_base = FALSE) |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 764 | { |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 765 | return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | // -------------------------------------------------------------------- |
| 769 | |
| 770 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 771 | * Remove Package Path |
| 772 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 773 | * Remove a path from the library, model, helper and/or config |
| 774 | * path arrays if it exists. If no path is provided, the most recently |
| 775 | * added path will be removed removed. |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 776 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 777 | * @param string $path Path to remove |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 778 | * @return object |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 779 | */ |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 780 | public function remove_package_path($path = '') |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 781 | { |
| 782 | $config =& $this->_ci_get_component('config'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 783 | |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 784 | if ($path === '') |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 785 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 786 | array_shift($this->_ci_library_paths); |
| 787 | array_shift($this->_ci_model_paths); |
| 788 | array_shift($this->_ci_helper_paths); |
| 789 | array_shift($this->_ci_view_paths); |
Korri | 3684d34 | 2012-04-17 00:35:08 -0400 | [diff] [blame] | 790 | array_pop($config->_config_paths); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 791 | } |
| 792 | else |
| 793 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 794 | $path = rtrim($path, '/').'/'; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 795 | foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) |
| 796 | { |
| 797 | if (($key = array_search($path, $this->{$var})) !== FALSE) |
| 798 | { |
| 799 | unset($this->{$var}[$key]); |
| 800 | } |
| 801 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 802 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 803 | if (isset($this->_ci_view_paths[$path.'views/'])) |
| 804 | { |
| 805 | unset($this->_ci_view_paths[$path.'views/']); |
| 806 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 807 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 808 | if (($key = array_search($path, $config->_config_paths)) !== FALSE) |
| 809 | { |
| 810 | unset($config->_config_paths[$key]); |
| 811 | } |
| 812 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 813 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 814 | // make sure the application default paths are still in the array |
| 815 | $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); |
| 816 | $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); |
| 817 | $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] | 818 | $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] | 819 | $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 820 | |
| 821 | return $this; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 825 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 826 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 827 | * Internal CI Data Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 828 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 829 | * Used to load views and files. |
| 830 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 831 | * Variables are prefixed with _ci_ to avoid symbol collision with |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 832 | * variables made available to view files. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 833 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 834 | * @used-by CI_Loader::view() |
| 835 | * @used-by CI_Loader::file() |
| 836 | * @param array $_ci_data Data to load |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 837 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 838 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 839 | protected function _ci_load($_ci_data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 840 | { |
| 841 | // Set the default data variables |
| 842 | foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) |
| 843 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 844 | $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 845 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 846 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 847 | $file_exists = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 848 | |
| 849 | // Set the path to the requested file |
Alex Bilbie | 40bd2a7 | 2012-06-02 16:04:15 +0100 | [diff] [blame] | 850 | if (is_string($_ci_path) && $_ci_path !== '') |
Greg Aker | 8807be3 | 2011-04-21 13:06:15 -0500 | [diff] [blame] | 851 | { |
| 852 | $_ci_x = explode('/', $_ci_path); |
| 853 | $_ci_file = end($_ci_x); |
| 854 | } |
| 855 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 856 | { |
| 857 | $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 858 | $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 859 | |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 860 | foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 861 | { |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 862 | if (file_exists($_ci_view_file.$_ci_file)) |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 863 | { |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 864 | $_ci_path = $_ci_view_file.$_ci_file; |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 865 | $file_exists = TRUE; |
| 866 | break; |
| 867 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 868 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 869 | if ( ! $cascade) |
| 870 | { |
| 871 | break; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 872 | } |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 873 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 874 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 875 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 876 | if ( ! $file_exists && ! file_exists($_ci_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 877 | { |
| 878 | show_error('Unable to load the requested file: '.$_ci_file); |
| 879 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 880 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 881 | // This allows anything loaded using $this->load (views, files, etc.) |
| 882 | // to become accessible from within the Controller and Model functions. |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 883 | $_ci_CI =& get_instance(); |
| 884 | foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 885 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 886 | if ( ! isset($this->$_ci_key)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 887 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 888 | $this->$_ci_key =& $_ci_CI->$_ci_key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
| 892 | /* |
| 893 | * Extract and cache variables |
| 894 | * |
vlakoff | 0250618 | 2012-07-03 07:28:50 +0200 | [diff] [blame] | 895 | * You can either set variables using the dedicated $this->load->vars() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 896 | * function or via the second parameter of this function. We'll merge |
| 897 | * the two types and cache them so that views that are embedded within |
| 898 | * other views can have access to these variables. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 899 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 900 | if (is_array($_ci_vars)) |
| 901 | { |
| 902 | $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); |
| 903 | } |
| 904 | extract($this->_ci_cached_vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 905 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 906 | /* |
| 907 | * Buffer the output |
| 908 | * |
| 909 | * We buffer the output for two reasons: |
| 910 | * 1. Speed. You get a significant speed boost. |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 911 | * 2. So that the final rendered template can be post-processed by |
dchill42 | 5628ba0 | 2012-08-08 12:05:45 -0400 | [diff] [blame] | 912 | * the output class. Why do we need post processing? For one thing, |
| 913 | * in order to show the elapsed page load time. Unless we can |
| 914 | * intercept the content right before it's sent to the browser and |
| 915 | * then stop the timer it won't be accurate. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 916 | */ |
| 917 | ob_start(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 918 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 919 | // If the PHP installation does not support short tags we'll |
| 920 | // do a little string replacement, changing the short tags |
| 921 | // to standard PHP echo statements. |
Andrey Andreev | 07355da | 2015-07-22 12:46:16 +0300 | [diff] [blame] | 922 | if ( ! is_php('5.4') && ! ini_get('short_open_tag') && config_item('rewrite_short_tags') === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 923 | { |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 924 | 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] | 925 | } |
| 926 | else |
| 927 | { |
| 928 | include($_ci_path); // include() vs include_once() allows for multiple views with the same name |
| 929 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 930 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 931 | log_message('info', 'File loaded: '.$_ci_path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 932 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 933 | // Return the file data if requested |
| 934 | if ($_ci_return === TRUE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 935 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 936 | $buffer = ob_get_contents(); |
| 937 | @ob_end_clean(); |
| 938 | return $buffer; |
| 939 | } |
| 940 | |
| 941 | /* |
| 942 | * Flush the buffer... or buff the flusher? |
| 943 | * |
| 944 | * In order to permit views to be nested within |
| 945 | * other views, we need to flush the content back out whenever |
| 946 | * we are beyond the first level of output buffering so that |
| 947 | * it can be seen and included properly by the first included |
| 948 | * template and any subsequent ones. Oy! |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 949 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 950 | if (ob_get_level() > $this->_ci_ob_level + 1) |
| 951 | { |
| 952 | ob_end_flush(); |
| 953 | } |
| 954 | else |
| 955 | { |
Greg Aker | 22f1a63 | 2010-11-10 15:34:35 -0600 | [diff] [blame] | 956 | $_ci_CI->output->append_output(ob_get_contents()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 957 | @ob_end_clean(); |
| 958 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 959 | |
| 960 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | // -------------------------------------------------------------------- |
| 964 | |
| 965 | /** |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 966 | * Internal CI Library Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 967 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 968 | * @used-by CI_Loader::library() |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 969 | * @uses CI_Loader::_ci_init_library() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 970 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 971 | * @param string $class Class name to load |
| 972 | * @param mixed $params Optional parameters to pass to the class constructor |
| 973 | * @param string $object_name Optional object name to assign to |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 974 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 975 | */ |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 976 | protected function _ci_load_library($class, $params = NULL, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 977 | { |
| 978 | // Get the class name, and while we're at it trim any slashes. |
| 979 | // The directory path can be included as part of the class name, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 980 | // but we don't want a leading slash |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 981 | $class = str_replace('.php', '', trim($class, '/')); |
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 | // Was the path included with the class name? |
| 984 | // We look for a slash to determine this |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 985 | if (($last_slash = strrpos($class, '/')) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 986 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 987 | // Extract the path |
Andrey Andreev | c26d34f | 2013-01-28 21:46:08 +0200 | [diff] [blame] | 988 | $subdir = substr($class, 0, ++$last_slash); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 989 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 990 | // Get the filename from the path |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 991 | $class = substr($class, $last_slash); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 992 | } |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 993 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 994 | { |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 995 | $subdir = ''; |
| 996 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 997 | |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 998 | $class = ucfirst($class); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 999 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1000 | // Is this a stock library? There are a few special conditions if so ... |
| 1001 | if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php')) |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1002 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1003 | return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1004 | } |
| 1005 | |
vlakoff | 3567246 | 2013-02-15 01:36:04 +0100 | [diff] [blame] | 1006 | // Let's search for the requested library file and load it. |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1007 | foreach ($this->_ci_library_paths as $path) |
| 1008 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1009 | // BASEPATH has already been checked for |
| 1010 | if ($path === BASEPATH) |
| 1011 | { |
| 1012 | continue; |
| 1013 | } |
| 1014 | |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1015 | $filepath = $path.'libraries/'.$subdir.$class.'.php'; |
| 1016 | |
| 1017 | // Safety: Was the class already loaded by a previous call? |
| 1018 | if (class_exists($class, FALSE)) |
| 1019 | { |
| 1020 | // Before we deem this to be a duplicate request, let's see |
| 1021 | // if a custom object name is being supplied. If so, we'll |
| 1022 | // return a new instance of the object |
| 1023 | if ($object_name !== NULL) |
| 1024 | { |
| 1025 | $CI =& get_instance(); |
| 1026 | if ( ! isset($CI->$object_name)) |
| 1027 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1028 | return $this->_ci_init_library($class, '', $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | log_message('debug', $class.' class already loaded. Second attempt ignored.'); |
| 1033 | return; |
| 1034 | } |
| 1035 | // Does the file exist? No? Bummer... |
| 1036 | elseif ( ! file_exists($filepath)) |
| 1037 | { |
| 1038 | continue; |
| 1039 | } |
| 1040 | |
| 1041 | include_once($filepath); |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1042 | return $this->_ci_init_library($class, '', $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1043 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1044 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 1045 | // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 1046 | if ($subdir === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1047 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1048 | return $this->_ci_load_library($class.'/'.$class, $params, $object_name); |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 1049 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1050 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1051 | // If we got this far we were unable to find the requested class. |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1052 | log_message('error', 'Unable to load the requested class: '.$class); |
| 1053 | show_error('Unable to load the requested class: '.$class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1054 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1055 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1056 | // -------------------------------------------------------------------- |
| 1057 | |
| 1058 | /** |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1059 | * Internal CI Stock Library Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1060 | * |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1061 | * @used-by CI_Loader::_ci_load_library() |
| 1062 | * @uses CI_Loader::_ci_init_library() |
| 1063 | * |
| 1064 | * @param string $library Library name to load |
| 1065 | * @param string $file_path Path to the library filename, relative to libraries/ |
| 1066 | * @param mixed $params Optional parameters to pass to the class constructor |
| 1067 | * @param string $object_name Optional object name to assign to |
| 1068 | * @return void |
| 1069 | */ |
| 1070 | protected function _ci_load_stock_library($library_name, $file_path, $params, $object_name) |
| 1071 | { |
| 1072 | $prefix = 'CI_'; |
| 1073 | |
| 1074 | if (class_exists($prefix.$library_name, FALSE)) |
| 1075 | { |
| 1076 | if (class_exists(config_item('subclass_prefix').$library_name, FALSE)) |
| 1077 | { |
| 1078 | $prefix = config_item('subclass_prefix'); |
| 1079 | } |
| 1080 | |
| 1081 | // Before we deem this to be a duplicate request, let's see |
| 1082 | // if a custom object name is being supplied. If so, we'll |
| 1083 | // return a new instance of the object |
| 1084 | if ($object_name !== NULL) |
| 1085 | { |
| 1086 | $CI =& get_instance(); |
| 1087 | if ( ! isset($CI->$object_name)) |
| 1088 | { |
| 1089 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); |
| 1094 | return; |
| 1095 | } |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1096 | |
| 1097 | $paths = $this->_ci_library_paths; |
| 1098 | array_pop($paths); // BASEPATH |
| 1099 | array_pop($paths); // APPPATH (needs to be the first path checked) |
| 1100 | array_unshift($paths, APPPATH); |
| 1101 | |
| 1102 | foreach ($paths as $path) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1103 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1104 | if (file_exists($path = $path.'libraries/'.$file_path.$library_name.'.php')) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1105 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1106 | // Override |
| 1107 | include_once($path); |
| 1108 | if (class_exists($prefix.$library_name, FALSE)) |
| 1109 | { |
| 1110 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); |
| 1115 | } |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); |
| 1120 | |
| 1121 | // Check for extensions |
| 1122 | $subclass = config_item('subclass_prefix').$library_name; |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1123 | foreach ($paths as $path) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1124 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1125 | if (file_exists($path = $path.'libraries/'.$file_path.$subclass.'.php')) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1126 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1127 | include_once($path); |
| 1128 | if (class_exists($subclass, FALSE)) |
| 1129 | { |
| 1130 | $prefix = config_item('subclass_prefix'); |
| 1131 | break; |
| 1132 | } |
| 1133 | else |
| 1134 | { |
mwhitneysdsu | e04f4f7 | 2015-03-30 12:38:22 -0700 | [diff] [blame] | 1135 | log_message('debug', $path.' exists, but does not declare '.$subclass); |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1136 | } |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1141 | } |
| 1142 | |
| 1143 | // -------------------------------------------------------------------- |
| 1144 | |
| 1145 | /** |
| 1146 | * Internal CI Library Instantiator |
| 1147 | * |
| 1148 | * @used-by CI_Loader::_ci_load_stock_library() |
| 1149 | * @used-by CI_Loader::_ci_load_library() |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1150 | * |
| 1151 | * @param string $class Class name |
| 1152 | * @param string $prefix Class name prefix |
| 1153 | * @param array|null|bool $config Optional configuration to pass to the class constructor: |
| 1154 | * FALSE to skip; |
| 1155 | * NULL to search in config paths; |
| 1156 | * array containing configuration data |
| 1157 | * @param string $object_name Optional object name to assign to |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1158 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1159 | */ |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1160 | protected function _ci_init_library($class, $prefix, $config = FALSE, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1161 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1162 | // 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] | 1163 | if ($config === NULL) |
| 1164 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1165 | // Fetch the config paths containing any package paths |
| 1166 | $config_component = $this->_ci_get_component('config'); |
| 1167 | |
| 1168 | if (is_array($config_component->_config_paths)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1169 | { |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1170 | $found = FALSE; |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1171 | foreach ($config_component->_config_paths as $path) |
| 1172 | { |
| 1173 | // We test for both uppercase and lowercase, for servers that |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1174 | // are case-sensitive with regard to file names. Load global first, |
| 1175 | // override with environment next |
| 1176 | if (file_exists($path.'config/'.strtolower($class).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1177 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1178 | include($path.'config/'.strtolower($class).'.php'); |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1179 | $found = TRUE; |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1180 | } |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1181 | elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1182 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1183 | include($path.'config/'.ucfirst(strtolower($class)).'.php'); |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1184 | $found = TRUE; |
| 1185 | } |
| 1186 | |
| 1187 | if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) |
| 1188 | { |
| 1189 | include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); |
| 1190 | $found = TRUE; |
| 1191 | } |
| 1192 | elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) |
| 1193 | { |
| 1194 | include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); |
| 1195 | $found = TRUE; |
| 1196 | } |
| 1197 | |
| 1198 | // Break on the first found configuration, thus package |
| 1199 | // files are not overridden by default paths |
| 1200 | if ($found === TRUE) |
| 1201 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1205 | } |
| 1206 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1207 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1208 | $class_name = $prefix.$class; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1209 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1210 | // Is the class name valid? |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1211 | if ( ! class_exists($class_name, FALSE)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1212 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1213 | log_message('error', 'Non-existent class: '.$class_name); |
| 1214 | show_error('Non-existent class: '.$class_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1215 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1216 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1217 | // Set the variable name we will assign the class to |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 1218 | // Was a custom class name supplied? If so we'll use it |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1219 | if (empty($object_name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1220 | { |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1221 | $object_name = strtolower($class); |
| 1222 | if (isset($this->_ci_varmap[$object_name])) |
| 1223 | { |
| 1224 | $object_name = $this->_ci_varmap[$object_name]; |
| 1225 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1226 | } |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1227 | |
| 1228 | // Don't overwrite existing properties |
| 1229 | $CI =& get_instance(); |
| 1230 | if (isset($CI->$object_name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1231 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1232 | if ($CI->$object_name instanceof $class_name) |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1233 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1234 | log_message('debug', $class_name." has already been instantiated as '".$object_name."'. Second attempt aborted."); |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1235 | return; |
| 1236 | } |
| 1237 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1238 | show_error("Resource '".$object_name."' already exists and is not a ".$class_name." instance."); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1241 | // Save the class name and object name |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1242 | $this->_ci_classes[$object_name] = $class; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1243 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1244 | // Instantiate the class |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1245 | $CI->$object_name = isset($config) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1246 | ? new $class_name($config) |
| 1247 | : new $class_name(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1248 | } |
| 1249 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1250 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1252 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1253 | * CI Autoloader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1254 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1255 | * Loads component listed in the config/autoload.php file. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1256 | * |
Andrey Andreev | cdac248 | 2012-11-03 18:09:01 +0200 | [diff] [blame] | 1257 | * @used-by CI_Loader::initialize() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1258 | * @return void |
| 1259 | */ |
Shane Pearson | 665baec | 2011-08-22 18:52:19 -0500 | [diff] [blame] | 1260 | protected function _ci_autoloader() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1261 | { |
Andrey Andreev | 4b6469d | 2015-01-22 16:42:17 +0200 | [diff] [blame] | 1262 | if (file_exists(APPPATH.'config/autoload.php')) |
Andrey Andreev | bd6a814 | 2015-01-22 16:41:25 +0200 | [diff] [blame] | 1263 | { |
| 1264 | include(APPPATH.'config/autoload.php'); |
| 1265 | } |
| 1266 | |
Andrey Andreev | db529ca | 2013-01-28 11:00:02 +0200 | [diff] [blame] | 1267 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 1268 | { |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 1269 | include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 1270 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1271 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1272 | if ( ! isset($autoload)) |
| 1273 | { |
Gabriel Potkány | d9287a0 | 2015-02-04 08:47:56 +0100 | [diff] [blame] | 1274 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1275 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1276 | |
Phil Sturgeon | 9730c75 | 2010-12-15 10:50:15 +0000 | [diff] [blame] | 1277 | // Autoload packages |
| 1278 | if (isset($autoload['packages'])) |
| 1279 | { |
| 1280 | foreach ($autoload['packages'] as $package_path) |
| 1281 | { |
| 1282 | $this->add_package_path($package_path); |
| 1283 | } |
| 1284 | } |
| 1285 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1286 | // Load any custom config file |
| 1287 | if (count($autoload['config']) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1288 | { |
Andrey Andreev | 623227f | 2014-03-24 12:46:25 +0200 | [diff] [blame] | 1289 | foreach ($autoload['config'] as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1290 | { |
Andrey Andreev | 689d41c | 2014-03-24 17:28:40 +0200 | [diff] [blame] | 1291 | $this->config($val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1292 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1293 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1294 | |
Derek Jones | c6da503 | 2010-03-09 20:44:27 -0600 | [diff] [blame] | 1295 | // Autoload helpers and languages |
| 1296 | foreach (array('helper', 'language') as $type) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1297 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1298 | if (isset($autoload[$type]) && count($autoload[$type]) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1299 | { |
| 1300 | $this->$type($autoload[$type]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1301 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1302 | } |
| 1303 | |
Andrey Andreev | 9ab70a8 | 2013-07-23 00:09:26 +0300 | [diff] [blame] | 1304 | // Autoload drivers |
| 1305 | if (isset($autoload['drivers'])) |
| 1306 | { |
| 1307 | foreach ($autoload['drivers'] as $item) |
| 1308 | { |
| 1309 | $this->driver($item); |
| 1310 | } |
| 1311 | } |
| 1312 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1313 | // Load libraries |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1314 | if (isset($autoload['libraries']) && count($autoload['libraries']) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1315 | { |
| 1316 | // Load the database driver. |
| 1317 | if (in_array('database', $autoload['libraries'])) |
| 1318 | { |
| 1319 | $this->database(); |
| 1320 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); |
| 1321 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1322 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1323 | // Load all other libraries |
Andrey Andreev | e36d048 | 2015-04-04 21:55:09 +0300 | [diff] [blame] | 1324 | $this->library($autoload['libraries']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1325 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1326 | |
| 1327 | // Autoload models |
| 1328 | if (isset($autoload['model'])) |
| 1329 | { |
| 1330 | $this->model($autoload['model']); |
| 1331 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1332 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1333 | |
| 1334 | // -------------------------------------------------------------------- |
| 1335 | |
| 1336 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1337 | * CI Object to Array translator |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1338 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1339 | * Takes an object as input and converts the class variables to |
| 1340 | * an associative array with key/value pairs. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1341 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1342 | * @param object $object Object data to translate |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1343 | * @return array |
| 1344 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1345 | protected function _ci_object_to_array($object) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1346 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1347 | return is_object($object) ? get_object_vars($object) : $object; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | // -------------------------------------------------------------------- |
| 1351 | |
| 1352 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1353 | * CI Component getter |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1354 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1355 | * Get a reference to a specific library or model. |
| 1356 | * |
| 1357 | * @param string $component Component name |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1358 | * @return bool |
| 1359 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1360 | protected function &_ci_get_component($component) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1361 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 1362 | $CI =& get_instance(); |
| 1363 | return $CI->$component; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1367 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1368 | /** |
| 1369 | * Prep filename |
| 1370 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1371 | * This function prepares filenames of various items to |
| 1372 | * make their loading more reliable. |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1373 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1374 | * @param string|string[] $filename Filename(s) |
| 1375 | * @param string $extension Filename extension |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1376 | * @return array |
| 1377 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1378 | protected function _ci_prep_filename($filename, $extension) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1379 | { |
| 1380 | if ( ! is_array($filename)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1381 | { |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 1382 | return array(strtolower(str_replace(array($extension, '.php'), '', $filename).$extension)); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1383 | } |
| 1384 | else |
| 1385 | { |
| 1386 | foreach ($filename as $key => $val) |
| 1387 | { |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 1388 | $filename[$key] = strtolower(str_replace(array($extension, '.php'), '', $val).$extension); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1389 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1390 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1391 | return $filename; |
| 1392 | } |
| 1393 | } |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1394 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1395 | } |