diff --git a/library/think/Error.php b/library/think/Error.php index 0f237aed..7a5fb4db 100644 --- a/library/think/Error.php +++ b/library/think/Error.php @@ -69,6 +69,7 @@ class Error // 记录异常日志 Log::record($log, 'error'); + Log::save(); /* 非API模式下的部署模式,跳转到指定的 Error Page */ $error_page = Config::get('error_page'); diff --git a/library/think/Response.php b/library/think/Response.php index 45507c35..536be418 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -61,17 +61,11 @@ class Response $handler = !empty($_GET[Config::get('var_jsonp_handler')]) ? $_GET[Config::get('var_jsonp_handler')] : Config::get('default_jsonp_handler'); $data = $handler . '(' . json_encode($data, JSON_UNESCAPED_UNICODE) . ');'; break; - case '': - case 'html': - case 'text': - // 不做处理 - break; - default: - // 用于扩展其他返回格式数据 - APP_HOOK && Hook::listen('return_data', $data); } } + APP_HOOK && Hook::listen('return_data', $data); + if ($return) { return $data; } diff --git a/library/think/console/output/Null.php b/library/think/console/output/Nothing.php similarity index 98% rename from library/think/console/output/Null.php rename to library/think/console/output/Nothing.php index 4e8f355c..93ca6fe8 100644 --- a/library/think/console/output/Null.php +++ b/library/think/console/output/Nothing.php @@ -14,7 +14,7 @@ namespace think\console\output; use think\console\Output; -class Null extends Output +class Nothing extends Output { /** @noinspection PhpMissingParentConstructorInspection */ public function __construct() diff --git a/mode/console.php b/mode/console.php index a4aff296..5f0c488e 100644 --- a/mode/console.php +++ b/mode/console.php @@ -27,17 +27,6 @@ return [ 'think\Error' => MODE_PATH . 'console/Error' . EXT ], // 配置文件 - 'config' => [ - 'log' => [ - 'type' => 'File', // 支持 file socket trace sae - 'path' => LOG_PATH, - ], - 'cache' => [ - 'type' => 'File', - 'path' => CACHE_PATH, - 'prefix' => '', - 'expire' => 0, - ] - ] + 'config' => THINK_PATH . 'convention' . EXT ]; diff --git a/mode/console/App.php b/mode/console/App.php index 4c1c13fe..d3672af4 100644 --- a/mode/console/App.php +++ b/mode/console/App.php @@ -23,6 +23,8 @@ class App */ public static function run() { + self::init(); + // 实例化console $console = new Console('Think Console', '0.1'); // 读取指令集 @@ -40,4 +42,67 @@ class App // 运行 $console->run(); } + + private static function init() + { + // 加载初始化文件 + if (is_file(APP_PATH . 'init' . EXT)) { + include APP_PATH . 'init' . EXT; + + // 加载模块配置 + $config = Config::get(); + } else { + // 加载模块配置 + $config = Config::load(APP_PATH . 'config' . EXT); + + // 加载应用状态配置 + if ($config['app_status']) { + $config = Config::load(APP_PATH . $config['app_status'] . EXT); + } + + // 读取扩展配置文件 + if ($config['extra_config_list']) { + foreach ($config['extra_config_list'] as $name => $file) { + $filename = APP_PATH . $file . EXT; + Config::load($filename, is_string($name) ? $name : pathinfo($filename, PATHINFO_FILENAME)); + } + } + + // 加载别名文件 + if (is_file(APP_PATH . 'alias' . EXT)) { + Loader::addMap(include APP_PATH . 'alias' . EXT); + } + + // 加载行为扩展文件 + if (APP_HOOK && is_file(APP_PATH . 'tags' . EXT)) { + Hook::import(include APP_PATH . 'tags' . EXT); + } + + // 加载公共文件 + if (is_file(APP_PATH . 'common' . EXT)) { + include APP_PATH . 'common' . EXT; + } + } + + // 注册根命名空间 + if (!empty($config['root_namespace'])) { + Loader::addNamespace($config['root_namespace']); + } + + // 加载额外文件 + if (!empty($config['extra_file_list'])) { + foreach ($config['extra_file_list'] as $file) { + $file = strpos($file, '.') ? $file : APP_PATH . $file . EXT; + if (is_file($file)) { + include_once $file; + } + } + } + + // 设置系统时区 + date_default_timezone_set($config['default_timezone']); + + // 监听app_init + APP_HOOK && Hook::listen('app_init'); + } } \ No newline at end of file