From Cute Crocodile, 12 Years ago, written in Plain Text.
Embed
  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.1.6 or newer
  6.  *
  7.  * @package             CodeIgniter
  8.  * @author              EllisLab Dev Team
  9.  * @copyright   Copyright (c) 2006 - 2011, 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.  
  18. /**
  19.  * CodeIgniter Driver Library Class
  20.  *
  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
  23.  *
  24.  * @package             CodeIgniter
  25.  * @subpackage  Libraries
  26.  * @category    Libraries
  27.  * @author              EllisLab Dev Team
  28.  * @link
  29.  */
  30. class CI_Driver_Library {
  31.  
  32.         protected $valid_drivers        = array();
  33.         protected static $lib_name;
  34.  
  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)
  38.         {
  39.                 if ( ! isset($this->lib_name))
  40.                 {
  41.                         $this->lib_name = get_class($this);
  42.                 }
  43.  
  44.                 // The class will be prefixed with the parent lib
  45.                 $child_class = $this->lib_name.'_'.$child;
  46.        
  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));
  50.                
  51.                 if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
  52.                 {
  53.                         // check and see if the driver is in a separate file
  54.                         if ( ! class_exists($child_class))
  55.                         {
  56.                                 // check application path first
  57.                                 foreach (get_instance()->load->get_package_paths(TRUE) as $path)
  58.                                 {
  59.                                         // loves me some nesting!
  60.                                         foreach (array(ucfirst($driver_name), $driver_name) as $class)
  61.                                         {
  62.                                                 $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php';
  63.  
  64.                                                 if (file_exists($filepath))
  65.                                                 {
  66.                                                         include_once $filepath;
  67.                                                         break;
  68.                                                 }
  69.                                         }
  70.                                 }
  71.  
  72.                                 // it's a valid driver, but the file simply can't be found
  73.                                 if ( ! class_exists($child_class))
  74.                                 {
  75.                                         log_message('error', "Unable to load the requested driver: ".$child_class);
  76.                                         show_error("Unable to load the requested driver: ".$child_class);
  77.                                 }
  78.                         }
  79.  
  80.                         $obj = new $child_class;
  81.                         $obj->decorate($this);
  82.                         $this->$child = $obj;
  83.                         return $this->$child;
  84.                 }
  85.  
  86.                 // The requested driver isn't valid!
  87.                 log_message('error', "Invalid driver requested: ".$child_class);
  88.                 show_error("Invalid driver requested: ".$child_class);
  89.         }
  90.  
  91.         // --------------------------------------------------------------------
  92.