Permalink
Browse files

Started Driver extension changes

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
1 parent f7e23b3 commit 28bee3dc85f9b15d110b1bd53123bbd7eb0b50de @dchill42 committed Sep 10, 2012
@@ -37,7 +37,7 @@
* @author EllisLab Dev Team
* @link
*/
-class CI_Driver_Library {
+abstract class CI_Driver_Library {
/**
* Array of drivers that are available to use with the driver class
@@ -54,6 +54,13 @@ class CI_Driver_Library {
protected $lib_name;
/**
+ * Name of the base class
+ *
+ * @var string
+ */
+ protected $base_name;
+
+ /**
* Get magic method
*
* The first time a child is used it won't exist, so we instantiate it
@@ -80,43 +87,54 @@ public function load_driver($child)
{
if ( ! isset($this->lib_name))
{
+ // Get both the current class (extension) and the base driver library class
$this->lib_name = get_class($this);
+ $this->base_name = $this->_get_base();
}
- // The class will be prefixed with the parent lib
- $child_class = $this->lib_name.'_'.$child;
-
- // Remove the CI_ prefix and lowercase
- $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name)));
- $driver_name = strtolower(str_replace('CI_', '', $child_class));
-
- if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
+ if (in_array($child, array_map('strtolower', $this->valid_drivers)))
{
- // check and see if the driver is in a separate file
- if ( ! class_exists($child_class))
+ $found = FALSE;
+ foreach (array($this->lib_name, $this->base_name) as $lib_name)
{
- // check application path first
- foreach (get_instance()->load->get_package_paths(TRUE) as $path)
+ // The class will be prefixed with the parent lib
+ $child_class = $lib_name.'_'.$child;
+
+ // Remove the CI_ prefix and lowercase
+ $base_name = ucfirst(strtolower(str_replace('CI_', '', $this->base_name)));
+ $driver_name = strtolower(str_replace('CI_', '', $child_class));
+
+ // Check and see if the driver is in a separate file
+ error_log('Checking for '.$child_class.' in '.$base_name);
+ if ( ! class_exists($child_class))
{
- // loves me some nesting!
- foreach (array(ucfirst($driver_name), $driver_name) as $class)
+ // Check application path first
+ foreach (get_instance()->load->get_package_paths(TRUE) as $path)
{
- $filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php';
-
- if (file_exists($filepath))
+ // Check upper- and lower-case names
+ foreach (array(ucfirst($driver_name), $driver_name) as $class)
{
- include_once $filepath;
- break 2;
+ $filepath = $path.'libraries/'.$base_name.'/drivers/'.$class.'.php';
+
+ if (file_exists($filepath))
+ {
+ include_once $filepath;
+ if (class_exists($child_class))
+ {
+ $found = TRUE;
+ break 3;
+ }
+ }
}
}
}
+ }
- // it's a valid driver, but the file simply can't be found
- if ( ! class_exists($child_class))
- {
- log_message('error', 'Unable to load the requested driver: '.$child_class);
- show_error('Unable to load the requested driver: '.$child_class);
- }
+ // It's a valid driver, but the file simply can't be found
+ if ( ! $found)
+ {
+ log_message('error', 'Unable to load the requested driver: '.$child_class);
+ show_error('Unable to load the requested driver: '.$child_class);
}
$obj = new $child_class;
@@ -130,6 +148,15 @@ public function load_driver($child)
show_error('Invalid driver requested: '.$child_class);
}
+ /**
+ * Get base driver library class
+ *
+ * Each driver library MUST implement this abstract method!
+ * The implementation should look like:
+ * protected function _get_base() { return __CLASS__; }
+ */
+ abstract protected function _get_base();
+
}
// --------------------------------------------------------------------------
@@ -77,17 +77,15 @@ public function __construct(array $params = array())
// Get valid drivers list
$CI =& get_instance();
$this->valid_drivers = array(
- 'Session_native',
- 'Session_cookie'
+ 'native',
+ 'cookie'
);
$key = 'sess_valid_drivers';
$drivers = isset($params[$key]) ? $params[$key] : $CI->config->item($key);
if ($drivers)
{
- is_array($drivers) OR $drivers = array($drivers);
-
// Add driver names to valid list
- foreach ($drivers as $driver)
+ foreach ((array)$drivers as $driver)
{
if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers)))
{
@@ -104,9 +102,9 @@ public function __construct(array $params = array())
$driver = 'cookie';
}
- if ( ! in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers)))
+ if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers)))
{
- $this->valid_drivers[] = 'Session_'.$driver;
+ $this->valid_drivers[] = $driver;
}
// Save a copy of parameters in case drivers need access
@@ -129,6 +127,13 @@ public function __construct(array $params = array())
// ------------------------------------------------------------------------
+ protected function _get_base()
+ {
+ return __CLASS__;
+ }
+
+ // ------------------------------------------------------------------------
+
/**
* Loads session storage driver
*
@@ -154,11 +159,10 @@ public function load_driver($driver)
public function select_driver($driver)
{
// Validate driver name
- $lowername = strtolower(str_replace('CI_', '', $driver));
- if (in_array($lowername, array_map('strtolower', $this->valid_drivers)))
+ $child = strtolower(str_replace(array('CI_', $this->lib_name, $this->base_name), '', $driver));
+ if (in_array($child, array_map('strtolower', $this->valid_drivers)))
{
// See if driver is loaded
- $child = str_replace($this->lib_name.'_', '', $driver);
if (isset($this->$child))
{
// See if driver is already current
@@ -686,4 +690,4 @@ protected function initialize()
}
/* End of file Session.php */
-/* Location: ./system/libraries/Session/Session.php */
+/* Location: ./system/libraries/Session/Session.php */
@@ -60,8 +60,8 @@ public function set_up()
'cookie_prefix' => '',
'encryption_key' => 'foobar',
'sess_valid_drivers' => array(
- 'Mock_Libraries_Session_native',
- 'Mock_Libraries_Session_cookie'
+ 'native',
+ 'cookie'
)
);
$this->session = new Mock_Libraries_Session($config);
@@ -39,5 +39,5 @@ protected function _setcookie($name, $value = '', $expire = 0, $path = '', $doma
/**
* Mock native driver (just for consistency in loading)
*/
-class Mock_Libraries_Session_native extends CI_Session_native { }
+//class Mock_Libraries_Session_native extends CI_Session_native { }

0 comments on commit 28bee3d

Please sign in to comment.