mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进页面trace信息记录不全的问题
This commit is contained in:
@@ -161,11 +161,6 @@ class App
|
||||
// 监听app_end
|
||||
Hook::listen('app_end', $response);
|
||||
|
||||
// Trace调试注入
|
||||
if (Config::get('app_trace')) {
|
||||
Debug::inject($response);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,14 +185,12 @@ class Debug
|
||||
}
|
||||
}
|
||||
|
||||
public static function inject(Response $response)
|
||||
public static function inject(Response $response, &$content)
|
||||
{
|
||||
$config = Config::get('trace');
|
||||
$type = isset($config['type']) ? $config['type'] : 'Html';
|
||||
$request = Request::instance();
|
||||
$accept = $request->header('accept');
|
||||
$contentType = $response->getHeader('Content-Type');
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
||||
$config = Config::get('trace');
|
||||
$type = isset($config['type']) ? $config['type'] : 'Html';
|
||||
$request = Request::instance();
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
||||
unset($config['type']);
|
||||
if (class_exists($class)) {
|
||||
$trace = new $class($config);
|
||||
@@ -206,14 +204,12 @@ class Debug
|
||||
$output = $trace->output($response, Log::getLog());
|
||||
if (is_string($output)) {
|
||||
// trace调试信息注入
|
||||
$content = $response->getContent();
|
||||
$pos = strripos($content, '</body>');
|
||||
$pos = strripos($content, '</body>');
|
||||
if (false !== $pos) {
|
||||
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
|
||||
} else {
|
||||
$content = $content . $output;
|
||||
}
|
||||
$response->content($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\Debug;
|
||||
use think\response\Json as JsonResponse;
|
||||
use think\response\Jsonp as JsonpResponse;
|
||||
use think\response\Redirect as RedirectResponse;
|
||||
@@ -93,6 +95,11 @@ class Response
|
||||
// 处理输出数据
|
||||
$data = $this->getContent();
|
||||
|
||||
// Trace调试注入
|
||||
if (Config::get('app_trace')) {
|
||||
Debug::inject($this, $data);
|
||||
}
|
||||
|
||||
if (!headers_sent() && !empty($this->header)) {
|
||||
// 发送状态码
|
||||
http_response_code($this->code);
|
||||
@@ -170,14 +177,14 @@ class Response
|
||||
public function content($content)
|
||||
{
|
||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||
$content,
|
||||
'__toString',
|
||||
])
|
||||
$content,
|
||||
'__toString',
|
||||
])
|
||||
) {
|
||||
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||
}
|
||||
|
||||
$this->content = (string)$content;
|
||||
$this->content = (string) $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -248,7 +255,7 @@ class Response
|
||||
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取头部信息
|
||||
* @param string $name 头部名称
|
||||
@@ -274,18 +281,18 @@ class Response
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
if ($this->content == null) {
|
||||
if (null == $this->content) {
|
||||
$content = $this->output($this->data);
|
||||
|
||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||
$content,
|
||||
'__toString',
|
||||
])
|
||||
$content,
|
||||
'__toString',
|
||||
])
|
||||
) {
|
||||
throw new \InvalidArgumentException(sprintf('variable type error: %s', gettype($content)));
|
||||
}
|
||||
|
||||
$this->content = (string)$content;
|
||||
$this->content = (string) $content;
|
||||
}
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user