From 95c92a5f923429293d076e426202de13c24ac838 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 29 Jun 2016 18:08:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Btrace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Response.php | 22 +--------------------- library/think/debug/Trace.php | 35 +++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/library/think/Response.php b/library/think/Response.php index 74c5a6c9..59d6a0cf 100644 --- a/library/think/Response.php +++ b/library/think/Response.php @@ -245,30 +245,10 @@ class Response */ public function contentType($contentType, $charset = 'utf-8') { - $this->contentType = $contentType; - $this->charset = $charset; - $this->header['Content-Type'] = $contentType . '; charset=' . $charset; return $this; } - - /** - * 获取页面输出类型 - * @return string - */ - public function getContentType() - { - return $this->contentType; - } - - /** - * 获取页面输出字符集 - */ - public function getCharset() - { - return $this->charset; - } - + /** * 获取头部信息 * @param string $name 头部名称 diff --git a/library/think/debug/Trace.php b/library/think/debug/Trace.php index 163f62ab..a626a0c7 100644 --- a/library/think/debug/Trace.php +++ b/library/think/debug/Trace.php @@ -14,6 +14,7 @@ use think\Config; use think\Log; use think\Request; use think\Response; +use think\response\Redirect; class Trace { @@ -23,25 +24,35 @@ class Trace $type = isset($config['type']) ? $config['type'] : 'Html'; - if ($type !== false && !Request::instance()->isAjax() && $response->getContentType() == 'text/html') { + if ($type !== false) { + $request = Request::instance(); + $accept = $request->header('accept'); + $contentType = $response->getHeader('Content-Type'); $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\trace\\' . ucwords($type); - unset($config['type']); $trace = new $class($config); - $output = $trace->output(Log::getLog()); - - $content = $response->getContent(); - - $pos = strripos($content, ''); - if (false !== $pos) { - $content = substr($content, 0, $pos) . $output . substr($content, $pos); + if ($response instanceof Redirect) { + //TODO 记录 + } elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + //TODO 记录 + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + //TODO 记录 } else { - $content = $content . $output; - } + $output = $trace->output(Log::getLog()); - $response->content($content); + $content = $response->getContent(); + + $pos = strripos($content, ''); + if (false !== $pos) { + $content = substr($content, 0, $pos) . $output . substr($content, $pos); + } else { + $content = $content . $output; + } + + $response->content($content); + } } } } \ No newline at end of file