Skip to content

Commit

Permalink
Revert some of the changes from PR bcit-ci#2029
Browse files Browse the repository at this point in the history
We have file naming conventions and any extension filename needs to match MY_<orig_filename>,
so we don't need to check for lowercase equivalents.
  • Loading branch information
narfbg committed Nov 25, 2012
1 parent 89ecc8a commit 7e83f32
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
66 changes: 24 additions & 42 deletions system/libraries/Driver.php
Expand Up @@ -93,20 +93,16 @@ public function load_driver($child)
$child_name = $this->lib_name.'_'.$child; $child_name = $this->lib_name.'_'.$child;


// See if requested child is a valid driver // See if requested child is a valid driver
if ( ! in_array($child, array_map('strtolower', $this->valid_drivers))) if ( ! in_array($child, $this->valid_drivers))
{ {
// The requested driver isn't valid! // The requested driver isn't valid!
$msg = 'Invalid driver requested: '.$child_name; $msg = 'Invalid driver requested: '.$child_name;
log_message('error', $msg); log_message('error', $msg);
show_error($msg); show_error($msg);
} }


// All driver files should be in a library subdirectory - capitalized
$subdir = ucfirst(strtolower($this->lib_name));

// Get package paths and filename case variations to search // Get package paths and filename case variations to search
$paths = $CI->load->get_package_paths(TRUE); $paths = $CI->load->get_package_paths(TRUE);
$cases = array(ucfirst($child_name), strtolower($child_name));


// Is there an extension? // Is there an extension?
$class_name = $prefix.$child_name; $class_name = $prefix.$child_name;
Expand All @@ -116,31 +112,24 @@ public function load_driver($child)
// Check for subclass file // Check for subclass file
foreach ($paths as $path) foreach ($paths as $path)
{ {
// Extension will be in drivers subdirectory // Does the file exist?
$path .= 'libraries/'.$subdir.'/drivers/'; $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$prefix.$child_name.'.php';

if (file_exists($file))
// Try filename with caps and all lowercase
foreach ($cases as $name)
{ {
// Does the file exist? // Yes - require base class from BASEPATH
$file = $path.$prefix.$name.'.php'; $basepath = BASEPATH.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php';
if (file_exists($file)) if ( ! file_exists($basepath))
{ {
// Yes - require base class from BASEPATH $msg = 'Unable to load the requested class: CI_'.$child_name;
$basepath = BASEPATH.'libraries/'.$subdir.'/drivers/'.ucfirst($child_name).'.php'; log_message('error', $msg);
if ( ! file_exists($basepath)) show_error($msg);
{
$msg = 'Unable to load the requested class: CI_'.$child_name;
log_message('error', $msg);
show_error($msg);
}

// Include both sources and mark found
include($basepath);
include($file);
$found = TRUE;
break 2;
} }

// Include both sources and mark found
include($basepath);
include($file);
$found = TRUE;
break;
} }
} }
} }
Expand All @@ -156,20 +145,13 @@ public function load_driver($child)
// Check package paths // Check package paths
foreach ($paths as $path) foreach ($paths as $path)
{ {
// Class will be in drivers subdirectory // Does the file exist?
$path .= 'libraries/'.$subdir.'/drivers/'; $file = $path.'libraries/'.$this->lib_name.'/drivers/'.$child_name.'.php';

if (file_exists($file))
// Try filename with caps and all lowercase
foreach ($cases as $name)
{ {
// Does the file exist? // Include source
$file = $path.$name.'.php'; include($file);
if (file_exists($file)) break;
{
// Include source
include($file);
break 2;
}
} }
} }
} }
Expand All @@ -183,8 +165,8 @@ public function load_driver($child)
show_error($msg); show_error($msg);
} }


// Instantiate, decorate, and add child // Instantiate, decorate and add child
$obj = new $class_name; $obj = new $class_name();
$obj->decorate($this); $obj->decorate($this);
$this->$child = $obj; $this->$child = $obj;
return $this->$child; return $this->$child;
Expand Down
2 changes: 1 addition & 1 deletion tests/codeigniter/libraries/Driver_test.php
Expand Up @@ -72,7 +72,7 @@ public function test_load_app_driver()
$file = $this->name.'_'.$driver; $file = $this->name.'_'.$driver;
$class = 'CI_'.$file; $class = 'CI_'.$file;
$content = '<?php class '.$class.' extends CI_Driver { }'; $content = '<?php class '.$class.' extends CI_Driver { }';
$this->ci_vfs_create(strtolower($file), $content, $this->ci_app_root, $this->ci_vfs_create($file, $content, $this->ci_app_root,
array('libraries', $this->name, 'drivers')); array('libraries', $this->name, 'drivers'));


// Make valid list // Make valid list
Expand Down

0 comments on commit 7e83f32

Please sign in to comment.