PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/manage/codeigniter/system/libraries/Driver.php

https://bitbucket.org/myockey/clearcreek-chapel-website
PHP | 229 lines | 103 code | 33 blank | 93 comment | 12 complexity | 502c518e1b90c27128ac10ac38cf32b5 MD5 | raw file
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.2.4 or newer
  6. *
  7. * @package CodeIgniter
  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
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Driver Library Class
  18. *
  19. * This class enables you to create "Driver" libraries that add runtime ability
  20. * to extend the capabilities of a class via additional driver objects
  21. *
  22. * @package CodeIgniter
  23. * @subpackage Libraries
  24. * @category Libraries
  25. * @author EllisLab Dev Team
  26. * @link
  27. */
  28. class CI_Driver_Library {
  29. protected $valid_drivers = array();
  30. protected static $lib_name;
  31. // The first time a child is used it won't exist, so we instantiate it
  32. // subsequents calls will go straight to the proper child.
  33. function __get($child)
  34. {
  35. if (! isset($this->lib_name))
  36. {
  37. $this->lib_name = get_class($this);
  38. }
  39. // The class will be prefixed with the parent lib
  40. $child_class = $this->lib_name.'_'.$child;
  41. if (in_array(strtolower($child_class), array_map('strtolower', $this->valid_drivers)))
  42. {
  43. // check and see if the driver is in a separate file
  44. if ( ! class_exists($child_class))
  45. {
  46. // check application path first
  47. foreach (get_instance()->load->get_package_paths(TRUE) as $path)
  48. {
  49. // and check for case sensitivity of both the parent and child libs
  50. foreach (array(ucfirst($this->lib_name), strtolower($this->lib_name)) as $lib)
  51. {
  52. // loves me some nesting!
  53. foreach (array(ucfirst($child_class), strtolower($child_class)) as $class)
  54. {
  55. $filepath = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_class.'.php';
  56. if (file_exists($filepath))
  57. {
  58. include_once $filepath;
  59. break;
  60. }
  61. }
  62. }
  63. }
  64. // it's a valid driver, but the file simply can't be found
  65. if ( ! class_exists($child_class))
  66. {
  67. log_message('error', "Unable to load the requested driver: ".$child_class);
  68. show_error("Unable to load the requested driver: ".$child_class);
  69. }
  70. }
  71. $obj = new $child_class;
  72. $obj->decorate($this);
  73. $this->$child = $obj;
  74. return $this->$child;
  75. }
  76. // The requested driver isn't valid!
  77. log_message('error', "Invalid driver requested: ".$child_class);
  78. show_error("Invalid driver requested: ".$child_class);
  79. }
  80. // --------------------------------------------------------------------
  81. }
  82. // END CI_Driver_Library CLASS
  83. /**
  84. * CodeIgniter Driver Class
  85. *
  86. * This class enables you to create drivers for a Library based on the Driver Library.
  87. * It handles the drivers' access to the parent library
  88. *
  89. * @package CodeIgniter
  90. * @subpackage Libraries
  91. * @category Libraries
  92. * @author EllisLab Dev Team
  93. * @link
  94. */
  95. class CI_Driver {
  96. protected $parent;
  97. private $methods = array();
  98. private $properties = array();
  99. private static $reflections = array();
  100. /**
  101. * Decorate
  102. *
  103. * Decorates the child with the parent driver lib's methods and properties
  104. *
  105. * @param object
  106. * @return void
  107. */
  108. public function decorate($parent)
  109. {
  110. $this->parent = $parent;
  111. // Lock down attributes to what is defined in the class
  112. // and speed up references in magic methods
  113. $class_name = get_class($parent);
  114. if ( ! isset(self::$reflections[$class_name]))
  115. {
  116. $r = new ReflectionObject($parent);
  117. foreach ($r->getMethods() as $method)
  118. {
  119. if ($method->isPublic())
  120. {
  121. $this->methods[] = $method->getName();
  122. }
  123. }
  124. foreach($r->getProperties() as $prop)
  125. {
  126. if ($prop->isPublic())
  127. {
  128. $this->properties[] = $prop->getName();
  129. }
  130. }
  131. self::$reflections[$class_name] = array($this->methods, $this->properties);
  132. }
  133. else
  134. {
  135. list($this->methods, $this->properties) = self::$reflections[$class_name];
  136. }
  137. }
  138. // --------------------------------------------------------------------
  139. /**
  140. * __call magic method
  141. *
  142. * Handles access to the parent driver library's methods
  143. *
  144. * @access public
  145. * @param string
  146. * @param array
  147. * @return mixed
  148. */
  149. public function __call($method, $args = array())
  150. {
  151. if (in_array($method, $this->methods))
  152. {
  153. return call_user_func_array(array($this->parent, $method), $args);
  154. }
  155. $trace = debug_backtrace();
  156. _exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']);
  157. exit;
  158. }
  159. // --------------------------------------------------------------------
  160. /**
  161. * __get magic method
  162. *
  163. * Handles reading of the parent driver library's properties
  164. *
  165. * @param string
  166. * @return mixed
  167. */
  168. public function __get($var)
  169. {
  170. if (in_array($var, $this->properties))
  171. {
  172. return $this->parent->$var;
  173. }
  174. }
  175. // --------------------------------------------------------------------
  176. /**
  177. * __set magic method
  178. *
  179. * Handles writing to the parent driver library's properties
  180. *
  181. * @param string
  182. * @param array
  183. * @return mixed
  184. */
  185. public function __set($var, $val)
  186. {
  187. if (in_array($var, $this->properties))
  188. {
  189. $this->parent->$var = $val;
  190. }
  191. }
  192. // --------------------------------------------------------------------
  193. }
  194. // END CI_Driver CLASS
  195. /* End of file Driver.php */
  196. /* Location: ./system/libraries/Driver.php */