This commit is contained in:
zimoyin
2026-04-03 11:32:19 +08:00
parent 4c841b9dbf
commit 1a84e92384
30 changed files with 403 additions and 1030 deletions
+3 -2
View File
@@ -30,8 +30,9 @@ class SqlDebug implements Bootstrap
}
$appPath = app_path();
$pluginPath = dirname($appPath) . DIRECTORY_SEPARATOR . 'plugin';
if (Config::getInstance()->dbDebug) Db::connection()->listen(function (QueryExecuted $queryExecuted) use ($appPath) {
if (Config::getInstance()->dbDebug) Db::connection()->listen(function (QueryExecuted $queryExecuted) use ($pluginPath, $appPath) {
// 过滤掉 "select 1" 这类心跳检测SQL
if (isset($queryExecuted->sql) && $queryExecuted->sql !== "select 1") {
$bindings = $queryExecuted->bindings;
@@ -60,7 +61,7 @@ class SqlDebug implements Bootstrap
// 定位产生SQL的业务文件/行号/方法
$traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
foreach ($traces as $trace) {
if (isset($trace['file'], $trace['function']) && str_contains($trace['file'], $appPath)) {
if (isset($trace['file'], $trace['function']) && (str_contains($trace['file'], $appPath) || str_contains($trace['file'], $pluginPath))) {
// 格式化文件路径(去掉项目根目录,只保留相对路径)
$file = str_replace(base_path(), '', $trace['file']);
$file = ltrim($file, '/\\');