diff --git a/convention.php b/convention.php index 60bbeeed..27db1c73 100644 --- a/convention.php +++ b/convention.php @@ -7,6 +7,8 @@ return [ // 应用模式状态 'app_status' => '', + // 注册的根命名空间 + 'root_namespace' => [], // 扩展配置文件 'extra_config_list' => ['database', 'route'], // 扩展函数文件 diff --git a/library/think/App.php b/library/think/App.php index ad90d1c9..e188223f 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -42,6 +42,11 @@ class App // 获取配置参数 $config = Config::get(); + // 注册根命名空间 + if (!empty($config['root_namespace'])) { + Loader::addNamespace($config['root_namespace']); + } + // 加载额外文件 if (!empty($config['extra_file_list'])) { foreach ($config['extra_file_list'] as $file) { diff --git a/library/think/Loader.php b/library/think/Loader.php index 6391c0c4..07731367 100644 --- a/library/think/Loader.php +++ b/library/think/Loader.php @@ -87,9 +87,13 @@ class Loader } // 注册命名空间 - public static function addNamespace($namespace, $path) + public static function addNamespace($namespace, $path = '') { - self::$namespace[$namespace] = $path; + if (is_array($namespace)) { + self::$namespace = array_merge(self::$namespace, $namespace); + } else { + self::$namespace[$namespace] = $path; + } } // 注册自动加载机制 diff --git a/library/think/exception/ErrorException.php b/library/think/exception/ErrorException.php index caa85c93..2f1525c0 100644 --- a/library/think/exception/ErrorException.php +++ b/library/think/exception/ErrorException.php @@ -19,7 +19,7 @@ use think\Exception; * 除开从 think\Exception 继承的功能 * 其他和PHP系统\ErrorException功能基本一样 */ -class ErrorException extends Exception +class ErrorException extends Exception { /** * 用于保存错误级别 @@ -35,7 +35,7 @@ class ErrorException extends Exception * @param integer $line 出错行号 * @param array $context 错误上下文,会包含错误触发处作用域内所有变量的数组 */ - public function __construct($severity, $message, $file, $line, $context) + public function __construct($severity, $message, $file, $line, array $context = []) { $this->severity = $severity; $this->message = $message;