支持配置批量注册根命名空间

This commit is contained in:
thinkphp
2016-02-02 17:20:00 +08:00
parent b67be77f1c
commit 5234d3c7f6
4 changed files with 15 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ return [
// 应用模式状态
'app_status' => '',
// 注册的根命名空间
'root_namespace' => [],
// 扩展配置文件
'extra_config_list' => ['database', 'route'],
// 扩展函数文件

View File

@@ -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) {

View File

@@ -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;
}
}
// 注册自动加载机制

View File

@@ -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;