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