当我在我的类中实现接口时,autoloader首先获取带有命名空间的接口类,并且包含它没有问题。但是它得到没有命名空间的接口类名,所以我的自动加载器不能包含这些文件,我有错误。 我的班级:
namespace model\order;
use lib\model as Lib;
class Bitgo implements Lib\BitcoinInterface
{
}
自动加载机:
<?php
Class Autoloader
{
public function __construct()
{
spl_autoload_register(array($this, 'mainAutoload'));
}
public function mainAutoload ($className)
{
var_dump(__DIR__);
if ($className) {
$fullPath = $this->checkPathExist($className);
require_once ($fullPath);
$this->checkClassExist($className);
}
}
private function checkPathExist($className) {
$pathClass = str_replace(['_', '\\'], '/', $className);
$fullPath = URL_APP . $pathClass . '.php';
if (file_exists($fullPath)) {
return $fullPath;
}
$fullPath = strtolower($fullPath);
if (file_exists($fullPath)) {
return $fullPath;
}
if (SYSTEM_DEBUG_MODE) {
exit('Error: file not exists - ' . $fullPath);
}
$error = 'System error! Please report to email: info@bit-changer.net';
Lib_logger::saveToLog($error . ' (Path: '.$fullPath.')', LOG_TYPE_ERROR_CRITICAL);
exit($error);
}
private function checkClassExist($className) {
if (class_exists($className)) {
return;
}
if (strripos($className, '\\') > 0) {
$delimPos = strripos($className, '\\');
$className = substr($className, $delimPos + 1, strlen($className));
}
if (!class_exists($className)) {
if (SYSTEM_DEBUG_MODE) {
exit('Error: class not exists - ' . $className);
}
$error = 'System error! Please report to email: info@bit-changer.net';
Lib_logger::saveToLog($error . ' (Class: '.$className.')', LOG_TYPE_ERROR_CRITICAL);
exit($error);
}
}
}
new Autoloader();