summaryrefslogtreecommitdiffstats
path: root/tests/mocks/autoloader.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mocks/autoloader.php')
-rw-r--r--tests/mocks/autoloader.php73
1 files changed, 52 insertions, 21 deletions
diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php
index dd5929206..3d216da1f 100644
--- a/tests/mocks/autoloader.php
+++ b/tests/mocks/autoloader.php
@@ -6,73 +6,104 @@
//
// Prototype :
//
-// include_once('Mock_Core_Loader') // Will load ./mocks/core/loader.php
// $mock_table = new Mock_Libraries_Table(); // Will load ./mocks/libraries/table.php
-// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
+// $mock_database_driver = new Mock_Database_Driver(); // Will load ./mocks/database/driver.php
// and so on...
-function autoload($class)
+function autoload($class)
{
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$ci_core = array(
'Benchmark', 'Config', 'Controller',
'Exceptions', 'Hooks', 'Input',
- 'Lang', 'Loader', 'Model',
+ 'Lang', 'Loader', 'Log', 'Model',
'Output', 'Router', 'Security',
'URI', 'Utf8',
);
$ci_libraries = array(
- 'Calendar', 'Cart', 'Driver',
+ 'Calendar', 'Cart', 'Driver_Library',
'Email', 'Encrypt', 'Form_validation',
'Ftp', 'Image_lib', 'Javascript',
- 'Log', 'Migration', 'Pagination',
- 'Parser', 'Profiler', 'Session',
- 'Table', 'Trackback', 'Typography',
- 'Unit_test', 'Upload', 'User_agent',
- 'Xmlrpc', 'Zip',
+ 'Migration', 'Pagination', 'Parser',
+ 'Profiler', 'Table', 'Trackback',
+ 'Typography', 'Unit_test', 'Upload',
+ 'User_agent', 'Xmlrpc', 'Zip'
+ );
+
+ $ci_drivers = array(
+ 'Session',
);
if (strpos($class, 'Mock_') === 0)
{
- $class = str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class);
- $class = strtolower($class);
+ $class = strtolower(str_replace(array('Mock_', '_'), array('', DIRECTORY_SEPARATOR), $class));
}
elseif (strpos($class, 'CI_') === 0)
{
- $fragments = explode('_', $class, 2);
- $subclass = next($fragments);
+ $subclass = substr($class, 3);
if (in_array($subclass, $ci_core))
{
- $dir = BASEPATH.'core'.DIRECTORY_SEPARATOR;
+ $dir = SYSTEM_PATH.'core'.DIRECTORY_SEPARATOR;
$class = $subclass;
}
elseif (in_array($subclass, $ci_libraries))
{
- $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR;
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR;
+ $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass;
+ }
+ elseif (in_array($subclass, $ci_drivers))
+ {
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR;
$class = $subclass;
}
+ elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) {
+ $dir = SYSTEM_PATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $class = $subclass;
+ }
+ elseif (preg_match('/^CI_DB_(.+)_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 4)
+ {
+ $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR.'subdrivers'.DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'_'.$m[3].'.php';
+ }
+ elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3)
+ {
+ $driver_path = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR;
+ $dir = $driver_path.$m[1].DIRECTORY_SEPARATOR;
+ $file = $dir.$m[1].'_'.$m[2].'.php';
+ }
+ elseif (strpos($class, 'CI_DB') === 0)
+ {
+ $dir = SYSTEM_PATH.'database'.DIRECTORY_SEPARATOR;
+ $file = $dir.str_replace(array('CI_DB','active_record'), array('DB', 'active_rec'), $subclass).'.php';
+ }
else
{
$class = strtolower($class);
}
}
- $file = $dir.$class.'.php';
+ $file = isset($file) ? $file : $dir.$class.'.php';
if ( ! file_exists($file))
{
$trace = debug_backtrace();
- // If the autoload call came from `class_exists` or `file_exists`,
- // we skipped and return FALSE
- if ($trace[2]['function'] == 'class_exists' OR $trace[2]['function'] == 'file_exists')
+ if ($trace[2]['function'] === 'class_exists' OR $trace[2]['function'] === 'file_exists')
+ {
+ // If the autoload call came from `class_exists` or `file_exists`,
+ // we skipped and return FALSE
+ return FALSE;
+ }
+ elseif (($autoloader = spl_autoload_functions()) && end($autoloader) !== __FUNCTION__)
{
+ // If there was other custom autoloader, passed away
return FALSE;
}
- throw new InvalidArgumentException("Unable to load $class.");
+ throw new InvalidArgumentException("Unable to load {$class}.");
}
include_once($file);