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