我目前正在为我的一个项目开发一个自动加载器类。下面是控制器库的代码:
public static function includeFileContainingClass($classname) {
$classname_rectified = str_replace(__NAMESPACE__.'\\', '', $classname);
$controller_path = ENVIRONMENT_DIRECTROY_CONTROLLERS.strtolower($classname_rectified).'.controller.php';
if (file_exists($controller_path)) {
include $controller_path;
return true;
} else {
// TODO: Implement gettext('MSG_FILE_CONTROLLER_NOTFOUND')
throw new Exception('File '.strtolower($classname_rectified).'.controller.php not found.');
return false;
}
}
这是我尝试调用自动加载器的文件的代码:
try {
spl_autoload_register(__NAMESPACE__.'\\Controller::includeFileContainingClass');
} catch (Exception $malfunction) {
die($malfunction->getMessage());
}
// TESTING ONLY
$test = new Testing();
当我尝试强制故障时,我收到以下消息:
Fatal error: Uncaught exception 'Exception' with message 'File testing.controller.php not found.' in D:\cerophine-0.0.1-alpha1\application\libraries\controller.library.php:51 Stack trace: #0 [internal function]: application\Controller::includeFileContainingClass('application\Tes...') #1 D:\cerophine-0.0.1-alpha1\index.php(58): spl_autoload_call('application\Tes...') #2 {main} thrown in D:\cerophine-0.0.1-alpha1\application\libraries\controller.library.php on line 51
似乎有什么问题?