mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
改进扩展类库的自动加载
This commit is contained in:
1
base.php
1
base.php
@@ -18,6 +18,7 @@ define('THINK_VERSION', '5.0.0beta');
|
||||
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
|
||||
defined('THINK_PATH') or define('THINK_PATH', dirname(__FILE__) . DS);
|
||||
defined('LIB_PATH') or define('LIB_PATH', THINK_PATH . 'library' . DS);
|
||||
defined('EXTEND_PATH') or define('EXTEND_PATH', THINK_PATH . 'extend' . DS);
|
||||
defined('MODE_PATH') or define('MODE_PATH', THINK_PATH . 'mode' . DS); // 系统应用模式目录
|
||||
defined('CORE_PATH') or define('CORE_PATH', LIB_PATH . 'think' . DS);
|
||||
defined('ORG_PATH') or define('ORG_PATH', LIB_PATH . 'org' . DS);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user