改进页面trace信息记录不全的问题

This commit is contained in:
thinkphp
2016-08-22 11:53:29 +08:00
parent 87ae363fb8
commit 1a5f9dc5e1
3 changed files with 23 additions and 25 deletions

View File

@@ -161,11 +161,6 @@ class App
// 监听app_end // 监听app_end
Hook::listen('app_end', $response); Hook::listen('app_end', $response);
// Trace调试注入
if (Config::get('app_trace')) {
Debug::inject($response);
}
return $response; return $response;
} }

View File

@@ -185,13 +185,11 @@ class Debug
} }
} }
public static function inject(Response $response) public static function inject(Response $response, &$content)
{ {
$config = Config::get('trace'); $config = Config::get('trace');
$type = isset($config['type']) ? $config['type'] : 'Html'; $type = isset($config['type']) ? $config['type'] : 'Html';
$request = Request::instance(); $request = Request::instance();
$accept = $request->header('accept');
$contentType = $response->getHeader('Content-Type');
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type); $class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
unset($config['type']); unset($config['type']);
if (class_exists($class)) { if (class_exists($class)) {
@@ -206,14 +204,12 @@ class Debug
$output = $trace->output($response, Log::getLog()); $output = $trace->output($response, Log::getLog());
if (is_string($output)) { if (is_string($output)) {
// trace调试信息注入 // trace调试信息注入
$content = $response->getContent();
$pos = strripos($content, '</body>'); $pos = strripos($content, '</body>');
if (false !== $pos) { if (false !== $pos) {
$content = substr($content, 0, $pos) . $output . substr($content, $pos); $content = substr($content, 0, $pos) . $output . substr($content, $pos);
} else { } else {
$content = $content . $output; $content = $content . $output;
} }
$response->content($content);
} }
} }
} }

View File

@@ -11,6 +11,8 @@
namespace think; namespace think;
use think\Config;
use think\Debug;
use think\response\Json as JsonResponse; use think\response\Json as JsonResponse;
use think\response\Jsonp as JsonpResponse; use think\response\Jsonp as JsonpResponse;
use think\response\Redirect as RedirectResponse; use think\response\Redirect as RedirectResponse;
@@ -93,6 +95,11 @@ class Response
// 处理输出数据 // 处理输出数据
$data = $this->getContent(); $data = $this->getContent();
// Trace调试注入
if (Config::get('app_trace')) {
Debug::inject($this, $data);
}
if (!headers_sent() && !empty($this->header)) { if (!headers_sent() && !empty($this->header)) {
// 发送状态码 // 发送状态码
http_response_code($this->code); http_response_code($this->code);
@@ -177,7 +184,7 @@ class Response
throw new \InvalidArgumentException(sprintf('variable type error %s', gettype($content))); throw new \InvalidArgumentException(sprintf('variable type error %s', gettype($content)));
} }
$this->content = (string)$content; $this->content = (string) $content;
return $this; return $this;
} }
@@ -274,7 +281,7 @@ class Response
*/ */
public function getContent() public function getContent()
{ {
if ($this->content == null) { if (null == $this->content) {
$content = $this->output($this->data); $content = $this->output($this->data);
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([ if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
@@ -285,7 +292,7 @@ class Response
throw new \InvalidArgumentException(sprintf('variable type error %s', gettype($content))); throw new \InvalidArgumentException(sprintf('variable type error %s', gettype($content)));
} }
$this->content = (string)$content; $this->content = (string) $content;
} }
return $this->content; return $this->content;
} }