Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 83d1505 | 2011-12-22 13:35:42 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 83d1505 | 2011-12-22 13:35:42 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 39 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Driver Library Class |
| 42 | * |
| 43 | * This class enables you to create "Driver" libraries that add runtime ability |
| 44 | * to extend the capabilities of a class via additional driver objects |
| 45 | * |
| 46 | * @package CodeIgniter |
| 47 | * @subpackage Libraries |
| 48 | * @category Libraries |
| 49 | * @author EllisLab Dev Team |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 50 | * @link |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 51 | */ |
| 52 | class CI_Driver_Library { |
| 53 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Array of drivers that are available to use with the driver class |
| 56 | * |
| 57 | * @var array |
| 58 | */ |
| 59 | protected $valid_drivers = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 60 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 61 | /** |
| 62 | * Name of the current class - usually the driver class |
| 63 | * |
| 64 | * @var string |
| 65 | */ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 66 | protected $lib_name; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 67 | |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 68 | /** |
| 69 | * Get magic method |
| 70 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 71 | * The first time a child is used it won't exist, so we instantiate it |
| 72 | * subsequents calls will go straight to the proper child. |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 73 | * |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 74 | * @param string Child class name |
| 75 | * @return object Child class |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 76 | */ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 77 | public function __get($child) |
Andrey Andreev | 2e3e230 | 2012-10-09 15:52:34 +0300 | [diff] [blame] | 78 | { |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 79 | // Try to load the driver |
dchill42 | c587225 | 2012-07-30 14:53:11 -0400 | [diff] [blame] | 80 | return $this->load_driver($child); |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 81 | } |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 82 | |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 83 | /** |
| 84 | * Load driver |
| 85 | * |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 86 | * Separate load_driver call to support explicit driver load by library or user |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 87 | * |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 88 | * @param string Driver name (w/o parent prefix) |
| 89 | * @return object Child class |
Darren Hill | 6fbf6bd | 2011-08-31 14:15:35 -0400 | [diff] [blame] | 90 | */ |
Darren Hill | c4e266b | 2011-08-30 15:40:27 -0400 | [diff] [blame] | 91 | public function load_driver($child) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 92 | { |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 93 | // Get CodeIgniter instance and subclass prefix |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 94 | $prefix = config_item('subclass_prefix'); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 95 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 96 | if ( ! isset($this->lib_name)) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 97 | { |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 98 | // Get library name without any prefix |
| 99 | $this->lib_name = str_replace(array('CI_', $prefix), '', get_class($this)); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 100 | } |
| 101 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 102 | // The child will be prefixed with the parent lib |
| 103 | $child_name = $this->lib_name.'_'.$child; |
Andrey Andreev | 83d1505 | 2011-12-22 13:35:42 +0200 | [diff] [blame] | 104 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 105 | // See if requested child is a valid driver |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 106 | if ( ! in_array($child, $this->valid_drivers)) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 107 | { |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 108 | // The requested driver isn't valid! |
| 109 | $msg = 'Invalid driver requested: '.$child_name; |
| 110 | log_message('error', $msg); |
| 111 | show_error($msg); |
| 112 | } |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 113 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 114 | // Get package paths and filename case variations to search |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 115 | $CI = get_instance(); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 116 | $paths = $CI->load->get_package_paths(TRUE); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 117 | |
| 118 | // Is there an extension? |
| 119 | $class_name = $prefix.$child_name; |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 120 | $found = class_exists($class_name, FALSE); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 121 | if ( ! $found) |
| 122 | { |
| 123 | // Check for subclass file |
| 124 | foreach ($paths as $path) |
| 125 | { |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 126 | // Does the file exist? |
| 127 | $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$prefix.$child_name.'.php'; |
| 128 | if (file_exists($file)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 129 | { |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 130 | // Yes - require base class from BASEPATH |
| 131 | $basepath = BASEPATH.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; |
| 132 | if ( ! file_exists($basepath)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 133 | { |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 134 | $msg = 'Unable to load the requested class: CI_'.$child_name; |
| 135 | log_message('error', $msg); |
| 136 | show_error($msg); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 137 | } |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 138 | |
| 139 | // Include both sources and mark found |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 140 | include_once($basepath); |
| 141 | include_once($file); |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 142 | $found = TRUE; |
| 143 | break; |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // Do we need to search for the class? |
| 149 | if ( ! $found) |
| 150 | { |
| 151 | // Use standard class name |
| 152 | $class_name = 'CI_'.$child_name; |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 153 | if ( ! class_exists($class_name, FALSE)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 154 | { |
| 155 | // Check package paths |
| 156 | foreach ($paths as $path) |
| 157 | { |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 158 | // Does the file exist? |
| 159 | $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php'; |
| 160 | if (file_exists($file)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 161 | { |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 162 | // Include source |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 163 | include_once($file); |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 164 | break; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 165 | } |
| 166 | } |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 167 | } |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 168 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 169 | |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 170 | // Did we finally find the class? |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 171 | if ( ! class_exists($class_name, FALSE)) |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 172 | { |
Andrey Andreev | 662e342 | 2013-01-28 21:19:13 +0200 | [diff] [blame] | 173 | if (class_exists($child_name, FALSE)) |
William Knauss | 401fb49 | 2012-11-27 00:01:03 -0500 | [diff] [blame] | 174 | { |
| 175 | $class_name = $child_name; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | $msg = 'Unable to load the requested driver: '.$class_name; |
| 180 | log_message('error', $msg); |
| 181 | show_error($msg); |
| 182 | } |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 183 | } |
| 184 | |
Andrey Andreev | 7e83f32 | 2012-11-25 16:03:21 +0200 | [diff] [blame] | 185 | // Instantiate, decorate and add child |
| 186 | $obj = new $class_name(); |
dchill42 | 6262d05 | 2012-11-24 18:41:13 -0500 | [diff] [blame] | 187 | $obj->decorate($this); |
| 188 | $this->$child = $obj; |
| 189 | return $this->$child; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 190 | } |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 191 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 192 | } |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 193 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 194 | // -------------------------------------------------------------------------- |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * CodeIgniter Driver Class |
| 198 | * |
| 199 | * This class enables you to create drivers for a Library based on the Driver Library. |
| 200 | * It handles the drivers' access to the parent library |
| 201 | * |
| 202 | * @package CodeIgniter |
| 203 | * @subpackage Libraries |
| 204 | * @category Libraries |
| 205 | * @author EllisLab Dev Team |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 206 | * @link |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 207 | */ |
| 208 | class CI_Driver { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 209 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 210 | /** |
| 211 | * Instance of the parent class |
| 212 | * |
| 213 | * @var object |
| 214 | */ |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 215 | protected $_parent; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 216 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 217 | /** |
| 218 | * List of methods in the parent class |
| 219 | * |
| 220 | * @var array |
| 221 | */ |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 222 | protected $_methods = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 223 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 224 | /** |
| 225 | * List of properties in the parent class |
| 226 | * |
| 227 | * @var array |
| 228 | */ |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 229 | protected $_properties = array(); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 230 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 231 | /** |
| 232 | * Array of methods and properties for the parent class(es) |
| 233 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 234 | * @static |
| 235 | * @var array |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 236 | */ |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 237 | protected static $_reflections = array(); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Decorate |
| 241 | * |
| 242 | * Decorates the child with the parent driver lib's methods and properties |
| 243 | * |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 244 | * @param object |
| 245 | * @return void |
| 246 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 247 | public function decorate($parent) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 248 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 249 | $this->_parent = $parent; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 250 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 251 | // Lock down attributes to what is defined in the class |
| 252 | // and speed up references in magic methods |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 253 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 254 | $class_name = get_class($parent); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 255 | |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 256 | if ( ! isset(self::$_reflections[$class_name])) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 257 | { |
| 258 | $r = new ReflectionObject($parent); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 260 | foreach ($r->getMethods() as $method) |
| 261 | { |
| 262 | if ($method->isPublic()) |
| 263 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 264 | $this->_methods[] = $method->getName(); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 268 | foreach ($r->getProperties() as $prop) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 269 | { |
| 270 | if ($prop->isPublic()) |
| 271 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 272 | $this->_properties[] = $prop->getName(); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 273 | } |
| 274 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 275 | |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 276 | self::$_reflections[$class_name] = array($this->_methods, $this->_properties); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 277 | } |
| 278 | else |
| 279 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 280 | list($this->_methods, $this->_properties) = self::$_reflections[$class_name]; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 281 | } |
| 282 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 283 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 284 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 285 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 286 | /** |
| 287 | * __call magic method |
| 288 | * |
| 289 | * Handles access to the parent driver library's methods |
| 290 | * |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 291 | * @param string |
| 292 | * @param array |
| 293 | * @return mixed |
| 294 | */ |
| 295 | public function __call($method, $args = array()) |
| 296 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 297 | if (in_array($method, $this->_methods)) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 298 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 299 | return call_user_func_array(array($this->_parent, $method), $args); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 300 | } |
| 301 | |
Andrey Andreev | a0471dc | 2014-11-04 19:22:38 +0200 | [diff] [blame] | 302 | throw new BadMethodCallException('No such method: '.$method.'()'); |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 307 | /** |
| 308 | * __get magic method |
| 309 | * |
| 310 | * Handles reading of the parent driver library's properties |
| 311 | * |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 312 | * @param string |
| 313 | * @return mixed |
| 314 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 315 | public function __get($var) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 316 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 317 | if (in_array($var, $this->_properties)) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 318 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 319 | return $this->_parent->$var; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 324 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 325 | /** |
| 326 | * __set magic method |
| 327 | * |
| 328 | * Handles writing to the parent driver library's properties |
| 329 | * |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 330 | * @param string |
| 331 | * @param array |
| 332 | * @return mixed |
| 333 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 334 | public function __set($var, $val) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 335 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 336 | if (in_array($var, $this->_properties)) |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 337 | { |
Andrey Andreev | 8486e9c | 2012-03-26 20:24:12 +0300 | [diff] [blame] | 338 | $this->_parent->$var = $val; |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 339 | } |
| 340 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 341 | |
Derek Jones | 8dca041 | 2010-03-05 13:01:44 -0600 | [diff] [blame] | 342 | } |