From a322a28f27c3ff970d1850ba91a30b346358f684 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 3 Jul 2016 14:56:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BTrave=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E8=BE=93=E5=87=BA=20socket=E6=96=B9=E5=BC=8F=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Debug.php | 6 +----- library/think/debug/Console.php | 15 +++++++++++++-- library/think/debug/Html.php | 16 +++++++++++++--- library/think/debug/Socket.php | 5 +++-- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/library/think/Debug.php b/library/think/Debug.php index 8dee74fe..28b6ab1e 100644 --- a/library/think/Debug.php +++ b/library/think/Debug.php @@ -201,12 +201,8 @@ class Debug if ($response instanceof Redirect) { //TODO 记录 - } elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) { - //TODO 记录 - } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { - //TODO 记录 } else { - $output = $trace->output(Log::getLog()); + $output = $trace->output($response, Log::getLog()); if (is_string($output)) { // trace调试信息注入 $content = $response->getContent(); diff --git a/library/think/debug/Console.php b/library/think/debug/Console.php index 6eacf23c..fa7e912a 100644 --- a/library/think/debug/Console.php +++ b/library/think/debug/Console.php @@ -15,6 +15,8 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; +use think\Request; +use think\Response; /** * 浏览器调试输出 @@ -36,11 +38,20 @@ class Console /** * 调试输出接口 * @access public - * @param array $log 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $log = []) + public function output(Response $response, array $log = []) { + $request = Request::instance(); + $contentType = $response->getHeader('Content-Type'); + $accept = $request->header('accept'); + if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + return false; + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + return false; + } // 获取基本信息 $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); diff --git a/library/think/debug/Html.php b/library/think/debug/Html.php index 7f16dc0e..8425cadc 100644 --- a/library/think/debug/Html.php +++ b/library/think/debug/Html.php @@ -15,6 +15,8 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; +use think\Request; +use think\Response; /** * 页面Trace调试 @@ -36,12 +38,20 @@ class Html /** * 调试输出接口 * @access public - * @param array $log 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $log = []) + public function output(Response $response, array $log = []) { - + $request = Request::instance(); + $contentType = $response->getHeader('Content-Type'); + $accept = $request->header('accept'); + if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + return false; + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + return false; + } // 获取基本信息 $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); diff --git a/library/think/debug/Socket.php b/library/think/debug/Socket.php index ae018a04..01aaa7c6 100644 --- a/library/think/debug/Socket.php +++ b/library/think/debug/Socket.php @@ -57,10 +57,11 @@ class Socket /** * 调试输出接口 * @access public - * @param array $logs 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $logs = []) + public function output(Response $response, array $log = []) { if (!$this->check()) { return false;