改进扩展类库的自动加载

This commit is contained in:
thinkphp
2015-12-25 09:36:42 +08:00
parent 7ea4250331
commit cdd0dc6048
2 changed files with 7 additions and 10 deletions

View File

@@ -34,24 +34,20 @@ class Loader
} elseif ($file = self::findFileInComposer($class)) {
include $file;
} else {
// 项目命名空间
$path = APP_PATH;
// 命名空间自动加载
$name = strtolower(strstr($class, '\\', true));
if (isset(self::$namespace[$name])) {
// 注册的命名空间
$path = dirname(self::$namespace[$name]) . DS;
} elseif (in_array($name, ['think', 'org', 'behavior', 'com', 'traits']) || is_dir(LIB_PATH . $name)) {
} elseif (in_array($name, ['think', 'behavior', 'traits']) || is_dir(LIB_PATH . $name)) {
// Library目录下面的命名空间自动定位
$path = LIB_PATH;
} elseif (is_dir(EXTEND_PATH . $name)) {
// 扩展类库命名空间
$path = EXTEND_PATH;
} else {
$extend = Config::get('extend_library') ?: [];
foreach ($extend as $_extend) {
if (is_dir($_extend . $name)) {
$path = $_extend;
break;
}
}
// 项目命名空间
$path = APP_PATH;
}
$filename = $path . str_replace('\\', DS, str_replace('\\_', '\\', strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $class), "_")))) . EXT;
if (is_file($filename)) {