1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5
* An open source application development framework for PHP 5.1.6 or newer
8
* @author EllisLab Dev Team
9
* @copyright Copyright (c) 2006 - 2012, EllisLab, Inc.
10
* @license http://codeigniter.com/user_guide/license.html
11
* @link http://codeigniter.com
16
// ------------------------------------------------------------------------
19
* CodeIgniter Driver Library Class
21
* This class enables you to create "Driver" libraries that add runtime ability
22
* to extend the capabilities of a class via additional driver objects
24
* @package CodeIgniter
25
* @subpackage Libraries
27
* @author EllisLab Dev Team
30
class CI_Driver_Library {
32
protected $valid_drivers = array();
35
// The first time a child is used it won't exist, so we instantiate it
36
// subsequents calls will go straight to the proper child.
37
function __get($child)
39
if ( ! isset($this->lib_name))
41
$this->lib_name = get_class($this);
44
// The class will be prefixed with the parent lib
45
$child_class = $this->lib_name.'_'.$child;
47
// Remove the CI_ prefix and lowercase
48
$lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name)));
49
$driver_name = strtolower(str_replace('CI_', '', $child_class));
51
if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
53
// check and see if the driver is in a separate file
54
if ( ! class_exists($child_class))
56
// check application path first
57
foreach (get_instance()->load->get_package_paths(TRUE) as $path)
59
// loves me some nesting!
60
foreach (array(ucfirst($driver_name), $driver_name) as $class)
62
$filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php';
64
if (file_exists($filepath))
66
include_once $filepath;
72
// it's a valid driver, but the file simply can't be found
73
if ( ! class_exists($child_class))
75
log_message('error', "Unable to load the requested driver: ".$child_class);
76
show_error("Unable to load the requested driver: ".$child_class);
80
$obj = new $child_class;
81
$obj->decorate($this);
86
// The requested driver isn't valid!
87
log_message('error', "Invalid driver requested: ".$child_class);
88
show_error("Invalid driver requested: ".$child_class);
91
// --------------------------------------------------------------------
94
// END CI_Driver_Library CLASS
98
* CodeIgniter Driver Class
100
* This class enables you to create drivers for a Library based on the Driver Library.
101
* It handles the drivers' access to the parent library
103
* @package CodeIgniter
104
* @subpackage Libraries
105
* @category Libraries
106
* @author EllisLab Dev Team
112
private $methods = array();
113
private $properties = array();
115
private static $reflections = array();
120
* Decorates the child with the parent driver lib's methods and properties
125
public function decorate($parent)
127
$this->parent = $parent;
129
// Lock down attributes to what is defined in the class
130
// and speed up references in magic methods
132
$class_name = get_class($parent);
134
if ( ! isset(self::$reflections[$class_name]))
136
$r = new ReflectionObject($parent);
138
foreach ($r->getMethods() as $method)
140
if ($method->isPublic())
142
$this->methods[] = $method->getName();
146
foreach ($r->getProperties() as $prop)
148
if ($prop->isPublic())
150
$this->properties[] = $prop->getName();
154
self::$reflections[$class_name] = array($this->methods, $this->properties);
158
list($this->methods, $this->properties) = self::$reflections[$class_name];
162
// --------------------------------------------------------------------
165
* __call magic method
167
* Handles access to the parent driver library's methods
174
public function __call($method, $args = array())
176
if (in_array($method, $this->methods))
178
return call_user_func_array(array($this->parent, $method), $args);
181
$trace = debug_backtrace();
182
_exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']);
186
// --------------------------------------------------------------------
191
* Handles reading of the parent driver library's properties
196
public function __get($var)
198
if (in_array($var, $this->properties))
200
return $this->parent->$var;
204
// --------------------------------------------------------------------
209
* Handles writing to the parent driver library's properties
215
public function __set($var, $val)
217
if (in_array($var, $this->properties))
219
$this->parent->$var = $val;
223
// --------------------------------------------------------------------
226
// END CI_Driver CLASS
228
/* End of file Driver.php */
229
/* Location: ./system/libraries/Driver.php */
b'\\ No newline at end of file'