mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进页面trace信息记录不全的问题
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,14 +185,12 @@ 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');
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
||||||
$contentType = $response->getHeader('Content-Type');
|
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
|
||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
if (class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
$trace = new $class($config);
|
$trace = new $class($config);
|
||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -170,14 +177,14 @@ class Response
|
|||||||
public function content($content)
|
public function content($content)
|
||||||
{
|
{
|
||||||
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
if (null !== $content && !is_string($content) && !is_numeric($content) && !is_callable([
|
||||||
$content,
|
$content,
|
||||||
'__toString',
|
'__toString',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -248,7 +255,7 @@ class Response
|
|||||||
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
|
$this->header['Content-Type'] = $contentType . '; charset=' . $charset;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取头部信息
|
* 获取头部信息
|
||||||
* @param string $name 头部名称
|
* @param string $name 头部名称
|
||||||
@@ -274,18 +281,18 @@ 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([
|
||||||
$content,
|
$content,
|
||||||
'__toString',
|
'__toString',
|
||||||
])
|
])
|
||||||
) {
|
) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user