From e4a66b73b63613f30ae90222970dc849285a4d30 Mon Sep 17 00:00:00 2001 From: huangdijia Date: Wed, 23 Dec 2015 18:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Response=E7=B1=BB=EF=BC=8C?= =?UTF-8?q?=E5=85=BC=E5=AE=B9rest=E6=8E=A7=E5=88=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/app.php | 4 ++-- library/think/response.php | 16 +++++++++++----- start.php | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/library/think/app.php b/library/think/app.php index ddfa715d..ab635bd0 100644 --- a/library/think/app.php +++ b/library/think/app.php @@ -111,7 +111,7 @@ class App // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); // 输出数据 - return Response::send($data, Config::get('default_return_type'), Config::get('response_return')); + return Response::send($data, Response::type(), Config::get('response_return')); } else { // 操作方法不是Public 抛出异常 throw new \ReflectionException(); @@ -124,7 +124,7 @@ class App // 操作方法执行完成监听 APP_HOOK && Hook::listen('action_end', $data); // 输出数据 - return Response::send($data, Config::get('default_return_type'), Config::get('response_return')); + return Response::send($data, Response::type(), Config::get('response_return')); } else { throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ', 10002); } diff --git a/library/think/response.php b/library/think/response.php index ecdf0bc5..22388cc9 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -92,8 +92,9 @@ class Response * @param string $type 输出内容的格式类型 * @return void */ - public static function type($type) + public static function type($type = null) { + if(is_null($type)) return self::$type; self::$type = $type; } @@ -137,6 +138,7 @@ class Response 'time' => NOW_TIME, 'data' => $data, ]; + if($type) self::type($type); return $result; } @@ -158,12 +160,14 @@ class Response 'url' => $url ?: $_SERVER["HTTP_REFERER"], 'wait' => $wait, ]; + $type = Config::get('default_return_type'); if(IS_AJAX){ - Config::set('default_return_type', Config::get('default_ajax_return')); + $type = Config::get('default_ajax_return'); } - if ('html' == Config::get('default_return_type')) { + if ('html' == $type) { $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result); } + self::type($type); return $result; } @@ -185,12 +189,14 @@ class Response 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait, ]; + $type = Config::get('default_return_type'); if(IS_AJAX){ - Config::set('default_return_type', Config::get('default_ajax_return')); + $type = Config::get('default_ajax_return'); } - if ('html' == Config::get('default_return_type')) { + if ('html' == $type) { $result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result); } + self::type($type); return $result; } diff --git a/start.php b/start.php index 765aa00e..cb3b98a8 100644 --- a/start.php +++ b/start.php @@ -46,6 +46,6 @@ if (APP_HOOK && isset($mode['tags'])) { if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) { Build::run(include APP_PATH . 'build.php'); } -Loader::addNamespace('tests', TEST_PATH); + // 执行应用 !IN_UNIT_TEST && App::run();