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 | * |
Master Yoda | da60e9b | 2016-12-31 08:46:18 -0800 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2017, 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 |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Master Yoda | da60e9b | 2016-12-31 08:46:18 -0800 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2017, 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 |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 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 |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 49 | * @link https://codeigniter.com/user_guide/libraries/loader.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Andrey Andreev | 0b1efb3 | 2016-01-04 12:34:14 +0200 | [diff] [blame] | 288 | // Note: All of the code under this condition used to be just: |
| 289 | // |
| 290 | // load_class('Model', 'core'); |
| 291 | // |
| 292 | // However, load_class() instantiates classes |
| 293 | // to cache them for later use and that prevents |
| 294 | // MY_Model from being an abstract class and is |
| 295 | // sub-optimal otherwise anyway. |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 296 | if ( ! class_exists('CI_Model', FALSE)) |
| 297 | { |
Andrey Andreev | 0b1efb3 | 2016-01-04 12:34:14 +0200 | [diff] [blame] | 298 | $app_path = APPPATH.'core'.DIRECTORY_SEPARATOR; |
| 299 | if (file_exists($app_path.'Model.php')) |
| 300 | { |
| 301 | require_once($app_path.'Model.php'); |
| 302 | if ( ! class_exists('CI_Model', FALSE)) |
| 303 | { |
| 304 | throw new RuntimeException($app_path."Model.php exists, but doesn't declare class CI_Model"); |
| 305 | } |
| 306 | } |
| 307 | elseif ( ! class_exists('CI_Model', FALSE)) |
| 308 | { |
| 309 | require_once(BASEPATH.'core'.DIRECTORY_SEPARATOR.'Model.php'); |
| 310 | } |
| 311 | |
| 312 | $class = config_item('subclass_prefix').'Model'; |
| 313 | if (file_exists($app_path.$class.'.php')) |
| 314 | { |
| 315 | require_once($app_path.$class.'.php'); |
| 316 | if ( ! class_exists($class, FALSE)) |
| 317 | { |
| 318 | throw new RuntimeException($app_path.$class.".php exists, but doesn't declare class ".$class); |
| 319 | } |
| 320 | } |
Andrey Andreev | 2029231 | 2013-07-22 14:29:10 +0300 | [diff] [blame] | 321 | } |
| 322 | |
Andrey Andreev | 825fab7 | 2015-08-17 09:52:42 +0300 | [diff] [blame] | 323 | $model = ucfirst($model); |
Andrey Andreev | 738b9e3 | 2016-02-24 12:14:10 +0200 | [diff] [blame] | 324 | if ( ! class_exists($model, FALSE)) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 325 | { |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 326 | foreach ($this->_ci_model_paths as $mod_path) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 327 | { |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 328 | if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')) |
| 329 | { |
| 330 | continue; |
| 331 | } |
| 332 | |
| 333 | require_once($mod_path.'models/'.$path.$model.'.php'); |
| 334 | if ( ! class_exists($model, FALSE)) |
| 335 | { |
| 336 | throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model); |
| 337 | } |
| 338 | |
| 339 | break; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 340 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 342 | if ( ! class_exists($model, FALSE)) |
| 343 | { |
| 344 | throw new RuntimeException('Unable to locate the model you have specified: '.$model); |
| 345 | } |
| 346 | } |
| 347 | elseif ( ! is_subclass_of($model, 'CI_Model')) |
| 348 | { |
| 349 | 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] | 350 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 351 | |
Andrey Andreev | b63dc19 | 2015-07-22 13:14:50 +0300 | [diff] [blame] | 352 | $this->_ci_models[] = $name; |
| 353 | $CI->$name = new $model(); |
| 354 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 355 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 356 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 357 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 358 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | /** |
| 360 | * Database Loader |
| 361 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 362 | * @param mixed $params Database configuration options |
| 363 | * @param bool $return Whether to return the database object |
| 364 | * @param bool $query_builder Whether to enable Query Builder |
| 365 | * (overrides the configuration setting) |
| 366 | * |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 367 | * @return object|bool Database object if $return is set to TRUE, |
| 368 | * FALSE on failure, CI_Loader instance in any other case |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 369 | */ |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 370 | public function database($params = '', $return = FALSE, $query_builder = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 371 | { |
| 372 | // Grab the super object |
| 373 | $CI =& get_instance(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 374 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | // Do we even need to load the database class? |
Andrey Andreev | 9d0ab04 | 2012-10-24 21:47:39 +0300 | [diff] [blame] | 376 | 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] | 377 | { |
| 378 | return FALSE; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 381 | require_once(BASEPATH.'database/DB.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 382 | |
| 383 | if ($return === TRUE) |
| 384 | { |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 385 | return DB($params, $query_builder); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 387 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 388 | // Initialize the db variable. Needed to prevent |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 389 | // reference errors with some configurations |
| 390 | $CI->db = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 391 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | // Load the DB class |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 393 | $CI->db =& DB($params, $query_builder); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 394 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 396 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 397 | // -------------------------------------------------------------------- |
| 398 | |
| 399 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 400 | * Load the Database Utilities Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 401 | * |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 402 | * @param object $db Database object |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 403 | * @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] | 404 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 405 | */ |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 406 | public function dbutil($db = NULL, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 407 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 408 | $CI =& get_instance(); |
| 409 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 410 | if ( ! is_object($db) OR ! ($db instanceof CI_DB)) |
| 411 | { |
| 412 | class_exists('CI_DB', FALSE) OR $this->database(); |
| 413 | $db =& $CI->db; |
| 414 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 415 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 416 | require_once(BASEPATH.'database/DB_utility.php'); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 417 | require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php'); |
| 418 | $class = 'CI_DB_'.$db->dbdriver.'_utility'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 420 | if ($return === TRUE) |
| 421 | { |
| 422 | return new $class($db); |
| 423 | } |
| 424 | |
| 425 | $CI->dbutil = new $class($db); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 426 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 427 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 428 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 429 | // -------------------------------------------------------------------- |
| 430 | |
| 431 | /** |
| 432 | * Load the Database Forge Class |
| 433 | * |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 434 | * @param object $db Database object |
| 435 | * @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] | 436 | * @return object |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 437 | */ |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 438 | public function dbforge($db = NULL, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 440 | $CI =& get_instance(); |
| 441 | if ( ! is_object($db) OR ! ($db instanceof CI_DB)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 442 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 443 | class_exists('CI_DB', FALSE) OR $this->database(); |
| 444 | $db =& $CI->db; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 445 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 446 | |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 447 | require_once(BASEPATH.'database/DB_forge.php'); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 448 | require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php'); |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 449 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 450 | if ( ! empty($db->subdriver)) |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 451 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 452 | $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] | 453 | if (file_exists($driver_path)) |
| 454 | { |
| 455 | require_once($driver_path); |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 456 | $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge'; |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | else |
| 460 | { |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 461 | $class = 'CI_DB_'.$db->dbdriver.'_forge'; |
Andrey Andreev | a287a34 | 2012-11-05 23:19:59 +0200 | [diff] [blame] | 462 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | |
Andrey Andreev | eaa60c7 | 2012-11-06 01:11:22 +0200 | [diff] [blame] | 464 | if ($return === TRUE) |
| 465 | { |
| 466 | return new $class($db); |
| 467 | } |
| 468 | |
| 469 | $CI->dbforge = new $class($db); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 470 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 472 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 474 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 475 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 476 | * View Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 478 | * Loads "view" files. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 480 | * @param string $view View name |
| 481 | * @param array $vars An associative array of data |
| 482 | * to be extracted for use in the view |
| 483 | * @param bool $return Whether to return the view output |
| 484 | * or leave it to the Output class |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 485 | * @return object|string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 486 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 487 | public function view($view, $vars = array(), $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | { |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 489 | return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 490 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 491 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 493 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 495 | * Generic File Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 496 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 497 | * @param string $path File path |
| 498 | * @param bool $return Whether to return the file output |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 499 | * @return object|string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 501 | public function file($path, $return = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 502 | { |
| 503 | return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return)); |
| 504 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 505 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 507 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | /** |
| 509 | * Set Variables |
| 510 | * |
| 511 | * Once variables are set they become available within |
| 512 | * the controller class and its "view" files. |
| 513 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 514 | * @param array|object|string $vars |
| 515 | * An associative array or object containing values |
| 516 | * to be set, or a value's name if string |
| 517 | * @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] | 518 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 519 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 520 | public function vars($vars, $val = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 521 | { |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 522 | $vars = is_string($vars) |
| 523 | ? array($vars => $val) |
| 524 | : $this->_ci_prepare_view_vars($vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 525 | |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 526 | foreach ($vars as $key => $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | { |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 528 | $this->_ci_cached_vars[$key] = $val; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 529 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 530 | |
| 531 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 532 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 533 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 534 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 535 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 536 | /** |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 537 | * Clear Cached Variables |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 538 | * |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 539 | * Clears the cached variables. |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 540 | * |
Andrey Andreev | 10fb7d1 | 2015-08-03 10:05:29 +0300 | [diff] [blame] | 541 | * @return CI_Loader |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 542 | */ |
| 543 | public function clear_vars() |
| 544 | { |
| 545 | $this->_ci_cached_vars = array(); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 546 | return $this; |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 547 | } |
Andrey Andreev | af01fb1 | 2014-01-03 16:57:44 +0200 | [diff] [blame] | 548 | |
Tomaz Lovrec | a81a5ef | 2013-10-16 11:29:57 +0200 | [diff] [blame] | 549 | // -------------------------------------------------------------------- |
| 550 | |
| 551 | /** |
Phil Sturgeon | 8731f64 | 2011-07-22 16:11:34 -0600 | [diff] [blame] | 552 | * Get Variable |
| 553 | * |
| 554 | * Check if a variable is set and retrieve it. |
| 555 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 556 | * @param string $key Variable name |
| 557 | * @return mixed The variable or NULL if not found |
Phil Sturgeon | 8731f64 | 2011-07-22 16:11:34 -0600 | [diff] [blame] | 558 | */ |
| 559 | public function get_var($key) |
| 560 | { |
| 561 | return isset($this->_ci_cached_vars[$key]) ? $this->_ci_cached_vars[$key] : NULL; |
| 562 | } |
| 563 | |
| 564 | // -------------------------------------------------------------------- |
| 565 | |
| 566 | /** |
Shane Pearson | 81dd223 | 2011-11-18 20:49:35 -0600 | [diff] [blame] | 567 | * Get Variables |
| 568 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 569 | * Retrieves all loaded variables. |
Shane Pearson | 81dd223 | 2011-11-18 20:49:35 -0600 | [diff] [blame] | 570 | * |
| 571 | * @return array |
| 572 | */ |
| 573 | public function get_vars() |
| 574 | { |
| 575 | return $this->_ci_cached_vars; |
| 576 | } |
| 577 | |
| 578 | // -------------------------------------------------------------------- |
| 579 | |
| 580 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 581 | * Helper Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 583 | * @param string|string[] $helpers Helper name(s) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 584 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 586 | public function helper($helpers = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 587 | { |
Andrey Andreev | 4015f9b | 2016-11-14 10:22:59 +0200 | [diff] [blame] | 588 | is_array($helpers) OR $helpers = array($helpers); |
| 589 | foreach ($helpers as &$helper) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 590 | { |
Andrey Andreev | 4015f9b | 2016-11-14 10:22:59 +0200 | [diff] [blame] | 591 | $filename = basename($helper); |
| 592 | $filepath = ($filename === $helper) ? '' : substr($helper, 0, strlen($helper) - strlen($filename)); |
Andrey Andreev | 99d05f0 | 2017-01-11 17:04:06 +0200 | [diff] [blame^] | 593 | $filename = strtolower(preg_replace('#(_helper)?(\.php)?$#i', '', $filename)).'_helper'; |
Andrey Andreev | 4015f9b | 2016-11-14 10:22:59 +0200 | [diff] [blame] | 594 | $helper = $filepath.$filename; |
| 595 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 596 | if (isset($this->_ci_helpers[$helper])) |
| 597 | { |
| 598 | continue; |
| 599 | } |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 600 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 601 | // Is this a helper extension request? |
Andrey Andreev | 4015f9b | 2016-11-14 10:22:59 +0200 | [diff] [blame] | 602 | $ext_helper = config_item('subclass_prefix').$filename; |
Andrey Andreev | 12d7b46 | 2012-11-12 13:42:09 +0200 | [diff] [blame] | 603 | $ext_loaded = FALSE; |
| 604 | foreach ($this->_ci_helper_paths as $path) |
| 605 | { |
| 606 | if (file_exists($path.'helpers/'.$ext_helper.'.php')) |
| 607 | { |
| 608 | include_once($path.'helpers/'.$ext_helper.'.php'); |
| 609 | $ext_loaded = TRUE; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | // If we have loaded extensions - check if the base one is here |
| 614 | if ($ext_loaded === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 615 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 616 | $base_helper = BASEPATH.'helpers/'.$helper.'.php'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 617 | if ( ! file_exists($base_helper)) |
| 618 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 619 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 620 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 621 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | include_once($base_helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 623 | $this->_ci_helpers[$helper] = TRUE; |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 624 | log_message('info', 'Helper loaded: '.$helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 625 | continue; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 626 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 627 | |
Andrey Andreev | 12d7b46 | 2012-11-12 13:42:09 +0200 | [diff] [blame] | 628 | // No extensions found ... try loading regular helpers and/or overrides |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 629 | foreach ($this->_ci_helper_paths as $path) |
| 630 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 631 | if (file_exists($path.'helpers/'.$helper.'.php')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 632 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 633 | include_once($path.'helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 634 | |
| 635 | $this->_ci_helpers[$helper] = TRUE; |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 636 | log_message('info', 'Helper loaded: '.$helper); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 637 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 641 | // unable to load the helper |
| 642 | if ( ! isset($this->_ci_helpers[$helper])) |
| 643 | { |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 644 | show_error('Unable to load the requested file: helpers/'.$helper.'.php'); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 645 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 646 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 647 | |
| 648 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 649 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 650 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 652 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | /** |
| 654 | * Load Helpers |
| 655 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 656 | * An alias for the helper() method in case the developer has |
| 657 | * written the plural form of it. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 658 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 659 | * @uses CI_Loader::helper() |
| 660 | * @param string|string[] $helpers Helper name(s) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 661 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 662 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 663 | public function helpers($helpers = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 664 | { |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 665 | return $this->helper($helpers); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 666 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 667 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 668 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 669 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 670 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 671 | * Language Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 672 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 673 | * Loads language files. |
| 674 | * |
| 675 | * @param string|string[] $files List of language file names to load |
| 676 | * @param string Language name |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 677 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 678 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 679 | public function language($files, $lang = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 680 | { |
Andrey Andreev | d8e31ec | 2014-11-07 12:17:50 +0200 | [diff] [blame] | 681 | get_instance()->lang->load($files, $lang); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 682 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 683 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 684 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 685 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 686 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 687 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 688 | * Config Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 689 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 690 | * Loads a config file (an alias for CI_Config::load()). |
| 691 | * |
| 692 | * @uses CI_Config::load() |
| 693 | * @param string $file Configuration file name |
| 694 | * @param bool $use_sections Whether configuration values should be loaded into their own section |
| 695 | * @param bool $fail_gracefully Whether to just return FALSE or display an error message |
| 696 | * @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] | 697 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 698 | public function config($file, $use_sections = FALSE, $fail_gracefully = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 699 | { |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 700 | return get_instance()->config->load($file, $use_sections, $fail_gracefully); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 704 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 705 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 706 | * Driver Loader |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 707 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 708 | * Loads a driver library. |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 709 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 710 | * @param string|string[] $library Driver name(s) |
| 711 | * @param array $params Optional parameters to pass to the driver |
| 712 | * @param string $object_name An optional object name to assign to |
| 713 | * |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 714 | * @return object|bool Object or FALSE on failure if $library is a string |
| 715 | * and $object_name is set. CI_Loader instance otherwise. |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 716 | */ |
Andrey Andreev | 9c12b3f | 2014-01-06 12:32:30 +0200 | [diff] [blame] | 717 | public function driver($library, $params = NULL, $object_name = NULL) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 718 | { |
Christopher Guiney | b54d355 | 2012-03-10 08:38:10 -0800 | [diff] [blame] | 719 | if (is_array($library)) |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 720 | { |
Andrey Andreev | 44d3b18 | 2016-02-15 14:37:14 +0200 | [diff] [blame] | 721 | foreach ($library as $key => $value) |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 722 | { |
Andrey Andreev | 44d3b18 | 2016-02-15 14:37:14 +0200 | [diff] [blame] | 723 | if (is_int($key)) |
| 724 | { |
| 725 | $this->driver($value, $params); |
| 726 | } |
| 727 | else |
| 728 | { |
| 729 | $this->driver($key, $params, $value); |
| 730 | } |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 731 | } |
Christopher Guiney | 9929d6f | 2012-03-09 19:53:24 -0800 | [diff] [blame] | 732 | |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 733 | return $this; |
| 734 | } |
| 735 | elseif (empty($library)) |
Tom Klingenberg | 6a15b2d | 2011-10-07 20:03:30 +0200 | [diff] [blame] | 736 | { |
| 737 | return FALSE; |
| 738 | } |
| 739 | |
vlakoff | fadb822 | 2013-05-12 10:57:09 +0200 | [diff] [blame] | 740 | if ( ! class_exists('CI_Driver_Library', FALSE)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 741 | { |
| 742 | // We aren't instantiating an object here, just making the base class available |
| 743 | require BASEPATH.'libraries/Driver.php'; |
| 744 | } |
| 745 | |
Derek Jones | d5e0cb5 | 2010-03-09 20:20:46 -0600 | [diff] [blame] | 746 | // We can save the loader some time since Drivers will *always* be in a subfolder, |
| 747 | // and typically identically named to the library |
| 748 | if ( ! strpos($library, '/')) |
| 749 | { |
Greg Aker | d25e66a | 2010-03-28 01:07:09 -0500 | [diff] [blame] | 750 | $library = ucfirst($library).'/'.$library; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 751 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 752 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 753 | return $this->library($library, $params, $object_name); |
| 754 | } |
| 755 | |
| 756 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 757 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 758 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 759 | * Add Package Path |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 760 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 761 | * Prepends a parent path to the library, model, helper and config |
| 762 | * path arrays. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 763 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 764 | * @see CI_Loader::$_ci_library_paths |
| 765 | * @see CI_Loader::$_ci_model_paths |
| 766 | * @see CI_Loader::$_ci_helper_paths |
| 767 | * @see CI_Config::$_config_paths |
| 768 | * |
| 769 | * @param string $path Path to add |
| 770 | * @param bool $view_cascade (default: TRUE) |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 771 | * @return object |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 772 | */ |
Andrey Andreev | cce9180 | 2012-06-12 13:25:31 +0300 | [diff] [blame] | 773 | public function add_package_path($path, $view_cascade = TRUE) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 774 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 775 | $path = rtrim($path, '/').'/'; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 776 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 777 | array_unshift($this->_ci_library_paths, $path); |
| 778 | array_unshift($this->_ci_model_paths, $path); |
| 779 | array_unshift($this->_ci_helper_paths, $path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 780 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 781 | $this->_ci_view_paths = array($path.'views/' => $view_cascade) + $this->_ci_view_paths; |
| 782 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 783 | // Add config file path |
| 784 | $config =& $this->_ci_get_component('config'); |
and-ers | b3ec942 | 2013-01-03 16:05:12 +0100 | [diff] [blame] | 785 | $config->_config_paths[] = $path; |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 786 | |
| 787 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | // -------------------------------------------------------------------- |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 791 | |
| 792 | /** |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 793 | * Get Package Paths |
| 794 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 795 | * Return a list of all package paths. |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 796 | * |
vlakoff | cdc6113 | 2013-05-10 16:47:47 +0200 | [diff] [blame] | 797 | * @param bool $include_base Whether to include BASEPATH (default: FALSE) |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 798 | * @return array |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 799 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 800 | public function get_package_paths($include_base = FALSE) |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 801 | { |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 802 | return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; |
Phil Sturgeon | de3dbc3 | 2010-12-27 17:41:02 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | // -------------------------------------------------------------------- |
| 806 | |
| 807 | /** |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 808 | * Remove Package Path |
| 809 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 810 | * Remove a path from the library, model, helper and/or config |
| 811 | * path arrays if it exists. If no path is provided, the most recently |
| 812 | * added path will be removed removed. |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 813 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 814 | * @param string $path Path to remove |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 815 | * @return object |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 816 | */ |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 817 | public function remove_package_path($path = '') |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 818 | { |
| 819 | $config =& $this->_ci_get_component('config'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 820 | |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 821 | if ($path === '') |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 822 | { |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 823 | array_shift($this->_ci_library_paths); |
| 824 | array_shift($this->_ci_model_paths); |
| 825 | array_shift($this->_ci_helper_paths); |
| 826 | array_shift($this->_ci_view_paths); |
Korri | 3684d34 | 2012-04-17 00:35:08 -0400 | [diff] [blame] | 827 | array_pop($config->_config_paths); |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 828 | } |
| 829 | else |
| 830 | { |
Pascal Kriete | 6b6c274 | 2010-11-09 13:12:22 -0500 | [diff] [blame] | 831 | $path = rtrim($path, '/').'/'; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 832 | foreach (array('_ci_library_paths', '_ci_model_paths', '_ci_helper_paths') as $var) |
| 833 | { |
| 834 | if (($key = array_search($path, $this->{$var})) !== FALSE) |
| 835 | { |
| 836 | unset($this->{$var}[$key]); |
| 837 | } |
| 838 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 839 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 840 | if (isset($this->_ci_view_paths[$path.'views/'])) |
| 841 | { |
| 842 | unset($this->_ci_view_paths[$path.'views/']); |
| 843 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 844 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 845 | if (($key = array_search($path, $config->_config_paths)) !== FALSE) |
| 846 | { |
| 847 | unset($config->_config_paths[$key]); |
| 848 | } |
| 849 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 850 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 851 | // make sure the application default paths are still in the array |
| 852 | $this->_ci_library_paths = array_unique(array_merge($this->_ci_library_paths, array(APPPATH, BASEPATH))); |
| 853 | $this->_ci_helper_paths = array_unique(array_merge($this->_ci_helper_paths, array(APPPATH, BASEPATH))); |
| 854 | $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] | 855 | $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] | 856 | $config->_config_paths = array_unique(array_merge($config->_config_paths, array(APPPATH))); |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 857 | |
| 858 | return $this; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 862 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 863 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 864 | * Internal CI Data Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 865 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 866 | * Used to load views and files. |
| 867 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 868 | * Variables are prefixed with _ci_ to avoid symbol collision with |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 869 | * variables made available to view files. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 870 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 871 | * @used-by CI_Loader::view() |
| 872 | * @used-by CI_Loader::file() |
| 873 | * @param array $_ci_data Data to load |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 874 | * @return object |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 875 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 876 | protected function _ci_load($_ci_data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 877 | { |
| 878 | // Set the default data variables |
| 879 | foreach (array('_ci_view', '_ci_vars', '_ci_path', '_ci_return') as $_ci_val) |
| 880 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 881 | $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 882 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 883 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 884 | $file_exists = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 885 | |
| 886 | // Set the path to the requested file |
Alex Bilbie | 40bd2a7 | 2012-06-02 16:04:15 +0100 | [diff] [blame] | 887 | if (is_string($_ci_path) && $_ci_path !== '') |
Greg Aker | 8807be3 | 2011-04-21 13:06:15 -0500 | [diff] [blame] | 888 | { |
| 889 | $_ci_x = explode('/', $_ci_path); |
| 890 | $_ci_file = end($_ci_x); |
| 891 | } |
| 892 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 893 | { |
| 894 | $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); |
Alex Bilbie | ed944a3 | 2012-06-02 11:07:47 +0100 | [diff] [blame] | 895 | $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 896 | |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 897 | foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 898 | { |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 899 | if (file_exists($_ci_view_file.$_ci_file)) |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 900 | { |
Joe McFrederick | 64f470b | 2012-08-18 12:29:56 -0400 | [diff] [blame] | 901 | $_ci_path = $_ci_view_file.$_ci_file; |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 902 | $file_exists = TRUE; |
| 903 | break; |
| 904 | } |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 905 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 906 | if ( ! $cascade) |
| 907 | { |
| 908 | break; |
David Behler | cda768a | 2011-08-14 23:52:48 +0200 | [diff] [blame] | 909 | } |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 910 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 911 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 912 | |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 913 | if ( ! $file_exists && ! file_exists($_ci_path)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 914 | { |
| 915 | show_error('Unable to load the requested file: '.$_ci_file); |
| 916 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 917 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 918 | // This allows anything loaded using $this->load (views, files, etc.) |
| 919 | // to become accessible from within the Controller and Model functions. |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 920 | $_ci_CI =& get_instance(); |
| 921 | foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 922 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 923 | if ( ! isset($this->$_ci_key)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 924 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 925 | $this->$_ci_key =& $_ci_CI->$_ci_key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | |
| 929 | /* |
| 930 | * Extract and cache variables |
| 931 | * |
vlakoff | 0250618 | 2012-07-03 07:28:50 +0200 | [diff] [blame] | 932 | * You can either set variables using the dedicated $this->load->vars() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 933 | * function or via the second parameter of this function. We'll merge |
| 934 | * the two types and cache them so that views that are embedded within |
| 935 | * other views can have access to these variables. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 936 | */ |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 937 | empty($_ci_vars) OR $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 938 | extract($this->_ci_cached_vars); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 939 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 940 | /* |
| 941 | * Buffer the output |
| 942 | * |
| 943 | * We buffer the output for two reasons: |
| 944 | * 1. Speed. You get a significant speed boost. |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 945 | * 2. So that the final rendered template can be post-processed by |
dchill42 | 5628ba0 | 2012-08-08 12:05:45 -0400 | [diff] [blame] | 946 | * the output class. Why do we need post processing? For one thing, |
| 947 | * in order to show the elapsed page load time. Unless we can |
| 948 | * intercept the content right before it's sent to the browser and |
| 949 | * then stop the timer it won't be accurate. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 950 | */ |
| 951 | ob_start(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 952 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 953 | // If the PHP installation does not support short tags we'll |
| 954 | // do a little string replacement, changing the short tags |
| 955 | // to standard PHP echo statements. |
Andrey Andreev | 07355da | 2015-07-22 12:46:16 +0300 | [diff] [blame] | 956 | 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] | 957 | { |
Andrey Andreev | d47baab | 2012-01-09 16:56:46 +0200 | [diff] [blame] | 958 | 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] | 959 | } |
| 960 | else |
| 961 | { |
| 962 | include($_ci_path); // include() vs include_once() allows for multiple views with the same name |
| 963 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 964 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 965 | log_message('info', 'File loaded: '.$_ci_path); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 966 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 967 | // Return the file data if requested |
| 968 | if ($_ci_return === TRUE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 969 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 970 | $buffer = ob_get_contents(); |
| 971 | @ob_end_clean(); |
| 972 | return $buffer; |
| 973 | } |
| 974 | |
| 975 | /* |
| 976 | * Flush the buffer... or buff the flusher? |
| 977 | * |
| 978 | * In order to permit views to be nested within |
| 979 | * other views, we need to flush the content back out whenever |
| 980 | * we are beyond the first level of output buffering so that |
| 981 | * it can be seen and included properly by the first included |
| 982 | * template and any subsequent ones. Oy! |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 983 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 984 | if (ob_get_level() > $this->_ci_ob_level + 1) |
| 985 | { |
| 986 | ob_end_flush(); |
| 987 | } |
| 988 | else |
| 989 | { |
Greg Aker | 22f1a63 | 2010-11-10 15:34:35 -0600 | [diff] [blame] | 990 | $_ci_CI->output->append_output(ob_get_contents()); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 991 | @ob_end_clean(); |
| 992 | } |
Andrey Andreev | 61a7b8f | 2014-01-07 13:36:50 +0200 | [diff] [blame] | 993 | |
| 994 | return $this; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | // -------------------------------------------------------------------- |
| 998 | |
| 999 | /** |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1000 | * Internal CI Library Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1001 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1002 | * @used-by CI_Loader::library() |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1003 | * @uses CI_Loader::_ci_init_library() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1004 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1005 | * @param string $class Class name to load |
| 1006 | * @param mixed $params Optional parameters to pass to the class constructor |
| 1007 | * @param string $object_name Optional object name to assign to |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1008 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1009 | */ |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1010 | protected function _ci_load_library($class, $params = NULL, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1011 | { |
| 1012 | // Get the class name, and while we're at it trim any slashes. |
| 1013 | // The directory path can be included as part of the class name, |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1014 | // but we don't want a leading slash |
Greg Aker | 3a74665 | 2011-04-19 10:59:47 -0500 | [diff] [blame] | 1015 | $class = str_replace('.php', '', trim($class, '/')); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1016 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1017 | // Was the path included with the class name? |
| 1018 | // We look for a slash to determine this |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1019 | if (($last_slash = strrpos($class, '/')) !== FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1020 | { |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1021 | // Extract the path |
Andrey Andreev | c26d34f | 2013-01-28 21:46:08 +0200 | [diff] [blame] | 1022 | $subdir = substr($class, 0, ++$last_slash); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1023 | |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1024 | // Get the filename from the path |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 1025 | $class = substr($class, $last_slash); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | } |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1027 | else |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1028 | { |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1029 | $subdir = ''; |
| 1030 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1031 | |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1032 | $class = ucfirst($class); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1033 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1034 | // Is this a stock library? There are a few special conditions if so ... |
| 1035 | if (file_exists(BASEPATH.'libraries/'.$subdir.$class.'.php')) |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1036 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1037 | return $this->_ci_load_stock_library($class, $subdir, $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
vlakoff | 3567246 | 2013-02-15 01:36:04 +0100 | [diff] [blame] | 1040 | // Let's search for the requested library file and load it. |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1041 | foreach ($this->_ci_library_paths as $path) |
| 1042 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1043 | // BASEPATH has already been checked for |
| 1044 | if ($path === BASEPATH) |
| 1045 | { |
| 1046 | continue; |
| 1047 | } |
| 1048 | |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1049 | $filepath = $path.'libraries/'.$subdir.$class.'.php'; |
| 1050 | |
| 1051 | // Safety: Was the class already loaded by a previous call? |
| 1052 | if (class_exists($class, FALSE)) |
| 1053 | { |
| 1054 | // Before we deem this to be a duplicate request, let's see |
| 1055 | // if a custom object name is being supplied. If so, we'll |
| 1056 | // return a new instance of the object |
| 1057 | if ($object_name !== NULL) |
| 1058 | { |
| 1059 | $CI =& get_instance(); |
| 1060 | if ( ! isset($CI->$object_name)) |
| 1061 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1062 | return $this->_ci_init_library($class, '', $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | log_message('debug', $class.' class already loaded. Second attempt ignored.'); |
| 1067 | return; |
| 1068 | } |
| 1069 | // Does the file exist? No? Bummer... |
| 1070 | elseif ( ! file_exists($filepath)) |
| 1071 | { |
| 1072 | continue; |
| 1073 | } |
| 1074 | |
| 1075 | include_once($filepath); |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1076 | return $this->_ci_init_library($class, '', $params, $object_name); |
Andrey Andreev | 3608e1a | 2013-01-28 16:27:30 +0200 | [diff] [blame] | 1077 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1078 | |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 1079 | // 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] | 1080 | if ($subdir === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1081 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1082 | return $this->_ci_load_library($class.'/'.$class, $params, $object_name); |
dchill42 | aee9265 | 2012-08-26 21:45:35 -0400 | [diff] [blame] | 1083 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1084 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1085 | // 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] | 1086 | log_message('error', 'Unable to load the requested class: '.$class); |
| 1087 | show_error('Unable to load the requested class: '.$class); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1088 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1089 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1090 | // -------------------------------------------------------------------- |
| 1091 | |
| 1092 | /** |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1093 | * Internal CI Stock Library Loader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1094 | * |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1095 | * @used-by CI_Loader::_ci_load_library() |
| 1096 | * @uses CI_Loader::_ci_init_library() |
| 1097 | * |
Andrey Andreev | e13fa9f | 2016-05-20 17:30:07 +0300 | [diff] [blame] | 1098 | * @param string $library_name Library name to load |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1099 | * @param string $file_path Path to the library filename, relative to libraries/ |
| 1100 | * @param mixed $params Optional parameters to pass to the class constructor |
| 1101 | * @param string $object_name Optional object name to assign to |
| 1102 | * @return void |
| 1103 | */ |
| 1104 | protected function _ci_load_stock_library($library_name, $file_path, $params, $object_name) |
| 1105 | { |
| 1106 | $prefix = 'CI_'; |
| 1107 | |
| 1108 | if (class_exists($prefix.$library_name, FALSE)) |
| 1109 | { |
| 1110 | if (class_exists(config_item('subclass_prefix').$library_name, FALSE)) |
| 1111 | { |
| 1112 | $prefix = config_item('subclass_prefix'); |
| 1113 | } |
| 1114 | |
| 1115 | // Before we deem this to be a duplicate request, let's see |
| 1116 | // if a custom object name is being supplied. If so, we'll |
| 1117 | // return a new instance of the object |
| 1118 | if ($object_name !== NULL) |
| 1119 | { |
| 1120 | $CI =& get_instance(); |
| 1121 | if ( ! isset($CI->$object_name)) |
| 1122 | { |
| 1123 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | log_message('debug', $library_name.' class already loaded. Second attempt ignored.'); |
| 1128 | return; |
| 1129 | } |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1130 | |
| 1131 | $paths = $this->_ci_library_paths; |
| 1132 | array_pop($paths); // BASEPATH |
| 1133 | array_pop($paths); // APPPATH (needs to be the first path checked) |
| 1134 | array_unshift($paths, APPPATH); |
| 1135 | |
| 1136 | foreach ($paths as $path) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1137 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1138 | if (file_exists($path = $path.'libraries/'.$file_path.$library_name.'.php')) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1139 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1140 | // Override |
| 1141 | include_once($path); |
| 1142 | if (class_exists($prefix.$library_name, FALSE)) |
| 1143 | { |
| 1144 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1145 | } |
| 1146 | else |
| 1147 | { |
| 1148 | log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name); |
| 1149 | } |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | include_once(BASEPATH.'libraries/'.$file_path.$library_name.'.php'); |
| 1154 | |
| 1155 | // Check for extensions |
| 1156 | $subclass = config_item('subclass_prefix').$library_name; |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1157 | foreach ($paths as $path) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1158 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1159 | if (file_exists($path = $path.'libraries/'.$file_path.$subclass.'.php')) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1160 | { |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1161 | include_once($path); |
| 1162 | if (class_exists($subclass, FALSE)) |
| 1163 | { |
| 1164 | $prefix = config_item('subclass_prefix'); |
| 1165 | break; |
| 1166 | } |
| 1167 | else |
| 1168 | { |
mwhitneysdsu | e04f4f7 | 2015-03-30 12:38:22 -0700 | [diff] [blame] | 1169 | log_message('debug', $path.' exists, but does not declare '.$subclass); |
Andrey Andreev | 8f5c178 | 2015-03-25 13:41:02 +0200 | [diff] [blame] | 1170 | } |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | return $this->_ci_init_library($library_name, $prefix, $params, $object_name); |
| 1175 | } |
| 1176 | |
| 1177 | // -------------------------------------------------------------------- |
| 1178 | |
| 1179 | /** |
| 1180 | * Internal CI Library Instantiator |
| 1181 | * |
| 1182 | * @used-by CI_Loader::_ci_load_stock_library() |
| 1183 | * @used-by CI_Loader::_ci_load_library() |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1184 | * |
| 1185 | * @param string $class Class name |
| 1186 | * @param string $prefix Class name prefix |
| 1187 | * @param array|null|bool $config Optional configuration to pass to the class constructor: |
| 1188 | * FALSE to skip; |
| 1189 | * NULL to search in config paths; |
| 1190 | * array containing configuration data |
| 1191 | * @param string $object_name Optional object name to assign to |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1192 | * @return void |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1193 | */ |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1194 | protected function _ci_init_library($class, $prefix, $config = FALSE, $object_name = NULL) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1195 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1196 | // 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] | 1197 | if ($config === NULL) |
| 1198 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1199 | // Fetch the config paths containing any package paths |
| 1200 | $config_component = $this->_ci_get_component('config'); |
| 1201 | |
| 1202 | if (is_array($config_component->_config_paths)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1203 | { |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1204 | $found = FALSE; |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1205 | foreach ($config_component->_config_paths as $path) |
| 1206 | { |
| 1207 | // We test for both uppercase and lowercase, for servers that |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1208 | // are case-sensitive with regard to file names. Load global first, |
| 1209 | // override with environment next |
| 1210 | if (file_exists($path.'config/'.strtolower($class).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1211 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1212 | include($path.'config/'.strtolower($class).'.php'); |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1213 | $found = TRUE; |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1214 | } |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1215 | elseif (file_exists($path.'config/'.ucfirst(strtolower($class)).'.php')) |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1216 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1217 | include($path.'config/'.ucfirst(strtolower($class)).'.php'); |
Andrey Andreev | 95c31ad | 2014-12-17 19:01:31 +0200 | [diff] [blame] | 1218 | $found = TRUE; |
| 1219 | } |
| 1220 | |
| 1221 | if (file_exists($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php')) |
| 1222 | { |
| 1223 | include($path.'config/'.ENVIRONMENT.'/'.strtolower($class).'.php'); |
| 1224 | $found = TRUE; |
| 1225 | } |
| 1226 | elseif (file_exists($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php')) |
| 1227 | { |
| 1228 | include($path.'config/'.ENVIRONMENT.'/'.ucfirst(strtolower($class)).'.php'); |
| 1229 | $found = TRUE; |
| 1230 | } |
| 1231 | |
| 1232 | // Break on the first found configuration, thus package |
| 1233 | // files are not overridden by default paths |
| 1234 | if ($found === TRUE) |
| 1235 | { |
Eric Barnes | 5e16ec6 | 2011-01-04 17:25:23 -0500 | [diff] [blame] | 1236 | break; |
| 1237 | } |
| 1238 | } |
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 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1242 | $class_name = $prefix.$class; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1243 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1244 | // Is the class name valid? |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1245 | if ( ! class_exists($class_name, FALSE)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1246 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1247 | log_message('error', 'Non-existent class: '.$class_name); |
| 1248 | show_error('Non-existent class: '.$class_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1249 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1250 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1251 | // Set the variable name we will assign the class to |
Andrey Andreev | d729735 | 2012-01-07 22:53:14 +0200 | [diff] [blame] | 1252 | // Was a custom class name supplied? If so we'll use it |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1253 | if (empty($object_name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1254 | { |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1255 | $object_name = strtolower($class); |
| 1256 | if (isset($this->_ci_varmap[$object_name])) |
| 1257 | { |
| 1258 | $object_name = $this->_ci_varmap[$object_name]; |
| 1259 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1260 | } |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1261 | |
| 1262 | // Don't overwrite existing properties |
| 1263 | $CI =& get_instance(); |
| 1264 | if (isset($CI->$object_name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1265 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1266 | if ($CI->$object_name instanceof $class_name) |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1267 | { |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1268 | 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] | 1269 | return; |
| 1270 | } |
| 1271 | |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1272 | 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] | 1273 | } |
| 1274 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1275 | // Save the class name and object name |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1276 | $this->_ci_classes[$object_name] = $class; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1277 | |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1278 | // Instantiate the class |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1279 | $CI->$object_name = isset($config) |
Andrey Andreev | db669f1 | 2015-01-21 16:51:51 +0200 | [diff] [blame] | 1280 | ? new $class_name($config) |
| 1281 | : new $class_name(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1284 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1285 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1286 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1287 | * CI Autoloader |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1288 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1289 | * Loads component listed in the config/autoload.php file. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1290 | * |
Andrey Andreev | cdac248 | 2012-11-03 18:09:01 +0200 | [diff] [blame] | 1291 | * @used-by CI_Loader::initialize() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1292 | * @return void |
| 1293 | */ |
Shane Pearson | 665baec | 2011-08-22 18:52:19 -0500 | [diff] [blame] | 1294 | protected function _ci_autoloader() |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1295 | { |
Andrey Andreev | 4b6469d | 2015-01-22 16:42:17 +0200 | [diff] [blame] | 1296 | if (file_exists(APPPATH.'config/autoload.php')) |
Andrey Andreev | bd6a814 | 2015-01-22 16:41:25 +0200 | [diff] [blame] | 1297 | { |
| 1298 | include(APPPATH.'config/autoload.php'); |
| 1299 | } |
| 1300 | |
Andrey Andreev | db529ca | 2013-01-28 11:00:02 +0200 | [diff] [blame] | 1301 | if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/autoload.php')) |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 1302 | { |
Shane Pearson | 6adfe63 | 2011-08-10 16:42:53 -0500 | [diff] [blame] | 1303 | include(APPPATH.'config/'.ENVIRONMENT.'/autoload.php'); |
bubbafoley | 0ea0414 | 2011-03-17 14:55:41 -0500 | [diff] [blame] | 1304 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1305 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1306 | if ( ! isset($autoload)) |
| 1307 | { |
Gabriel Potkány | d9287a0 | 2015-02-04 08:47:56 +0100 | [diff] [blame] | 1308 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1309 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1310 | |
Phil Sturgeon | 9730c75 | 2010-12-15 10:50:15 +0000 | [diff] [blame] | 1311 | // Autoload packages |
| 1312 | if (isset($autoload['packages'])) |
| 1313 | { |
| 1314 | foreach ($autoload['packages'] as $package_path) |
| 1315 | { |
| 1316 | $this->add_package_path($package_path); |
| 1317 | } |
| 1318 | } |
| 1319 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1320 | // Load any custom config file |
| 1321 | if (count($autoload['config']) > 0) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1322 | { |
Andrey Andreev | 623227f | 2014-03-24 12:46:25 +0200 | [diff] [blame] | 1323 | foreach ($autoload['config'] as $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1324 | { |
Andrey Andreev | 689d41c | 2014-03-24 17:28:40 +0200 | [diff] [blame] | 1325 | $this->config($val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1326 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1327 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1328 | |
Derek Jones | c6da503 | 2010-03-09 20:44:27 -0600 | [diff] [blame] | 1329 | // Autoload helpers and languages |
| 1330 | foreach (array('helper', 'language') as $type) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1331 | { |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1332 | if (isset($autoload[$type]) && count($autoload[$type]) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1333 | { |
| 1334 | $this->$type($autoload[$type]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1335 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Andrey Andreev | 9ab70a8 | 2013-07-23 00:09:26 +0300 | [diff] [blame] | 1338 | // Autoload drivers |
| 1339 | if (isset($autoload['drivers'])) |
| 1340 | { |
Andrey Andreev | 44d3b18 | 2016-02-15 14:37:14 +0200 | [diff] [blame] | 1341 | $this->driver($autoload['drivers']); |
Andrey Andreev | 9ab70a8 | 2013-07-23 00:09:26 +0300 | [diff] [blame] | 1342 | } |
| 1343 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1344 | // Load libraries |
Andrey Andreev | 94af355 | 2012-03-26 23:10:42 +0300 | [diff] [blame] | 1345 | if (isset($autoload['libraries']) && count($autoload['libraries']) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1346 | { |
| 1347 | // Load the database driver. |
| 1348 | if (in_array('database', $autoload['libraries'])) |
| 1349 | { |
| 1350 | $this->database(); |
| 1351 | $autoload['libraries'] = array_diff($autoload['libraries'], array('database')); |
| 1352 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1353 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1354 | // Load all other libraries |
Andrey Andreev | e36d048 | 2015-04-04 21:55:09 +0300 | [diff] [blame] | 1355 | $this->library($autoload['libraries']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1356 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1357 | |
| 1358 | // Autoload models |
| 1359 | if (isset($autoload['model'])) |
| 1360 | { |
| 1361 | $this->model($autoload['model']); |
| 1362 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1363 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1364 | |
| 1365 | // -------------------------------------------------------------------- |
| 1366 | |
| 1367 | /** |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1368 | * Prepare variables for _ci_vars, to be later extract()-ed inside views |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1369 | * |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1370 | * Converts objects to associative arrays and filters-out internal |
Chris Faulkner | b9ac1a1 | 2017-01-10 16:02:40 +1030 | [diff] [blame] | 1371 | * variable names (i.e. keys prefixed with '_ci_'). |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1372 | * |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1373 | * @param mixed $vars |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1374 | * @return array |
| 1375 | */ |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1376 | protected function _ci_prepare_view_vars($vars) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1377 | { |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1378 | if ( ! is_array($vars)) |
| 1379 | { |
| 1380 | $vars = is_object($vars) |
Chris Faulkner | b9ac1a1 | 2017-01-10 16:02:40 +1030 | [diff] [blame] | 1381 | ? get_object_vars($vars) |
Andrey Andreev | ec8dbbb | 2017-01-04 17:01:44 +0200 | [diff] [blame] | 1382 | : array(); |
| 1383 | } |
| 1384 | |
| 1385 | foreach (array_keys($vars) as $key) |
| 1386 | { |
| 1387 | if (strncmp($key, '_ci_', 4) === 0) |
| 1388 | { |
| 1389 | unset($vars[$key]); |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | return $vars; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | // -------------------------------------------------------------------- |
| 1397 | |
| 1398 | /** |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1399 | * CI Component getter |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1400 | * |
Andrey Andreev | ed4b258 | 2012-10-27 17:46:52 +0300 | [diff] [blame] | 1401 | * Get a reference to a specific library or model. |
| 1402 | * |
| 1403 | * @param string $component Component name |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1404 | * @return bool |
| 1405 | */ |
Greg Aker | f5c8402 | 2011-04-19 17:13:03 -0500 | [diff] [blame] | 1406 | protected function &_ci_get_component($component) |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1407 | { |
Pascal Kriete | 89ace43 | 2010-11-10 15:49:10 -0500 | [diff] [blame] | 1408 | $CI =& get_instance(); |
| 1409 | return $CI->$component; |
Derek Jones | 32bf186 | 2010-03-02 13:46:07 -0600 | [diff] [blame] | 1410 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1411 | } |