Permalink
Browse files

Removed lowercase class file support

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
dchill42 committed Nov 25, 2012
1 parent 14bcaed commit d4f2a4d621ed639a860cc56ee0f6098dbe90ae62
Showing with 41 additions and 52 deletions.
  1. +19 −34 system/core/Loader.php
  2. +22 −18 tests/codeigniter/core/Loader_test.php
View
@@ -950,51 +950,36 @@ protected function _ci_load_class($class, $params = NULL, $object_name = NULL)
$class = substr($class, $last_slash);
}
- // Get subclass prefix and paths to check
- $prefix = config_item('subclass_prefix');
- $libdir = 'libraries/'.$subdir;
- $subpath = APPPATH.$libdir.$prefix;
- $baseclass = BASEPATH.'libraries/'.ucfirst($class).'.php';
-
- // We'll test for both lowercase and capitalized versions of the file name on case-sensitive systems
- $cases = array(ucfirst($class));
- if (DIRECTORY_SEPARATOR !== '\\')
- {
- $cases[] = strtolower($class);
- }
+ // Class filename must be uppercased
+ $class = ucfirst($class);
// Is this a class extension request?
- foreach ($cases as $class)
+ $prefix = config_item('subclass_prefix');
+ $subclass = APPPATH.'libraries/'.$subdir.$prefix.$class.'.php';
+ if (file_exists($subclass))
{
- $subclass = $subpath.$class.'.php';
- if (file_exists($subclass))
+ $baseclass = BASEPATH.'libraries/'.$class.'.php';
+ if ( ! file_exists($baseclass))
{
- if ( ! file_exists($baseclass))
- {
- $msg = 'Unable to load the requested class: '.$class;
- log_message('error', $msg);
- show_error($msg);
- }
-
- require_once($baseclass);
- require_once($subclass);
- return $this->_ci_init_class($class, $prefix, $params, $object_name);
+ $msg = 'Unable to load the requested class: '.$class;
+ log_message('error', $msg);
+ show_error($msg);
}
+
+ require_once($baseclass);
+ require_once($subclass);
+ return $this->_ci_init_class($class, $prefix, $params, $object_name);
}
// Let's search for the requested library file and load it.
- // We'll check each path for the defined cases of the filename
foreach ($this->_ci_library_paths as $path)
{
- foreach ($cases as $class)
+ // Does the file exist?
+ $filepath = $path.'libraries/'.$subdir.$class.'.php';
+ if (file_exists($filepath))
{
- // Does the file exist?
- $filepath = $path.$libdir.$class.'.php';
- if (file_exists($filepath))
- {
- require_once($filepath);
- return $this->_ci_init_class($class, '', $params, $object_name);
- }
+ require_once($filepath);
+ return $this->_ci_init_class($class, '', $params, $object_name);
}
}
@@ -24,8 +24,9 @@ public function test_library()
{
// Create library in VFS
$lib = 'unit_test_lib';
- $class = 'CI_'.ucfirst($lib);
- $this->ci_vfs_create($lib, '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
+ $name = ucfirst($lib);
+ $class = 'CI_'.$name;
+ $this->ci_vfs_create($name, '<?php class '.$class.' { }', $this->ci_base_root, 'libraries');
// Test is_loaded fail
$this->assertFalse($this->load->is_loaded($lib));
@@ -42,7 +43,7 @@ public function test_library()
$this->assertNull($this->load->library($lib, ' '));
// Create library w/o class
- $lib = 'bad_test_lib';
+ $lib = 'Bad_test_lib';
$this->ci_vfs_create($lib, '', $this->ci_base_root, 'libraries');
// Test non-existent class
@@ -98,9 +99,10 @@ public function test_library_config()
{
// Create library in VFS
$lib = 'unit_test_config_lib';
- $class = 'CI_'.ucfirst($lib);
+ $name = ucfirst($lib);
+ $class = 'CI_'.$name;
$content = '<?php class '.$class.' { public function __construct($params) { $this->config = $params; } }';
- $this->ci_vfs_create($lib, $content, $this->ci_base_root, 'libraries');
+ $this->ci_vfs_create($name, $content, $this->ci_base_root, 'libraries');
// Create config file
$cfg = array(
@@ -128,7 +130,7 @@ public function test_load_library_in_application_dir()
// Create library in VFS
$lib = 'super_test_library';
$class = ucfirst($lib);
- $this->ci_vfs_create($lib, '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
+ $this->ci_vfs_create($class, '<?php class '.$class.' { }', $this->ci_app_root, 'libraries');
// Load library
$this->assertNull($this->load->library($lib));
@@ -144,10 +146,10 @@ public function test_driver()
{
// Create driver in VFS
$driver = 'unit_test_driver';
- $dir = ucfirst($driver);
- $class = 'CI_'.$dir;
+ $name = ucfirst($driver);
+ $class = 'CI_'.$name;
$content = '<?php class '.$class.' { } ';
- $this->ci_vfs_create($driver, $content, $this->ci_base_root, 'libraries/'.$dir);
+ $this->ci_vfs_create($name, $content, $this->ci_base_root, 'libraries/'.$name);
// Test loading as an array.
$this->assertNull($this->load->driver(array($driver)));
@@ -401,11 +403,12 @@ public function test_language()
public function test_packages()
{
- // Create model in VFS package path
+ // Create library in VFS package path
$dir = 'third-party';
$lib = 'unit_test_package';
- $class = 'CI_'.ucfirst($lib);
- $this->ci_vfs_create($lib, '<?php class '.$class.' { }', $this->ci_app_root, array($dir, 'libraries'));
+ $name = ucfirst($lib);
+ $class = 'CI_'.$name;
+ $this->ci_vfs_create($name, '<?php class '.$class.' { }', $this->ci_app_root, array($dir, 'libraries'));
// Get paths
$paths = $this->load->get_package_paths(TRUE);
@@ -435,7 +438,7 @@ public function test_packages()
// Test failed load without path
$this->setExpectedException(
'RuntimeException',
- 'CI Error: Unable to load the requested class: '.$lib
+ 'CI Error: Unable to load the requested class: '.$name
);
$this->load->library($lib);
}
@@ -461,14 +464,15 @@ public function test_initialize()
// Create library in VFS
$lib = 'autolib';
- $lib_class = 'CI_'.ucfirst($lib);
- $this->ci_vfs_create($lib, '<?php class '.$lib_class.' { }', $this->ci_base_root, 'libraries');
+ $libnm = ucfirst($lib);
+ $lib_class = 'CI_'.$libnm;
+ $this->ci_vfs_create($libnm, '<?php class '.$lib_class.' { }', $this->ci_base_root, 'libraries');
// Create driver in VFS
$drv = 'autodrv';
- $subdir = ucfirst($drv);
- $drv_class = 'CI_'.$subdir;
- $this->ci_vfs_create($drv, '<?php class '.$drv_class.' { }', $this->ci_base_root, array('libraries', $subdir));
+ $drvnm = ucfirst($drv);
+ $drv_class = 'CI_'.$drvnm;
+ $this->ci_vfs_create($drvnm, '<?php class '.$drv_class.' { }', $this->ci_base_root, array('libraries', $drvnm));
// Create model in VFS package path
$dir = 'testdir';

0 comments on commit d4f2a4d

Please sign in to comment.