内核更新,多余文件清理
This commit is contained in:
@@ -11,6 +11,13 @@
|
||||
|
||||
namespace think;
|
||||
|
||||
use think\Config;
|
||||
use think\exception\ClassNotFoundException;
|
||||
use think\Log;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
use think\response\Redirect;
|
||||
|
||||
class Debug
|
||||
{
|
||||
// 区间时间信息
|
||||
@@ -56,7 +63,7 @@ class Debug
|
||||
*/
|
||||
public static function getUseTime($dec = 6)
|
||||
{
|
||||
return number_format((microtime(true) - START_TIME), $dec);
|
||||
return number_format((microtime(true) - THINK_START_TIME), $dec);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +104,7 @@ class Debug
|
||||
*/
|
||||
public static function getUseMem($dec = 2)
|
||||
{
|
||||
$size = memory_get_usage() - START_MEM;
|
||||
$size = memory_get_usage() - THINK_START_MEM;
|
||||
$a = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$pos = 0;
|
||||
while ($size >= 1024) {
|
||||
@@ -177,4 +184,43 @@ class Debug
|
||||
}
|
||||
}
|
||||
|
||||
public static function inject(Response $response)
|
||||
{
|
||||
$config = Config::get('trace');
|
||||
$type = isset($config['type']) ? $config['type'] : 'Html';
|
||||
|
||||
if (false !== $type) {
|
||||
$request = Request::instance();
|
||||
$accept = $request->header('accept');
|
||||
$contentType = $response->getHeader('Content-Type');
|
||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
||||
unset($config['type']);
|
||||
if (class_exists($class)) {
|
||||
$trace = new $class($config);
|
||||
} else {
|
||||
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||
}
|
||||
|
||||
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());
|
||||
if (is_string($output)) {
|
||||
// trace调试信息注入
|
||||
$content = $response->getContent();
|
||||
$pos = strripos($content, '</body>');
|
||||
if (false !== $pos) {
|
||||
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
|
||||
} else {
|
||||
$content = $content . $output;
|
||||
}
|
||||
$response->content($content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user