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