diff --git a/system/libs/pot/OTS.php b/system/libs/pot/OTS.php index fb93afea..13b4c11a 100644 --- a/system/libs/pot/OTS.php +++ b/system/libs/pot/OTS.php @@ -372,8 +372,8 @@ class POT global $debugBar; if (isset($debugBar)) { - $this->db = new DebugBar\DataCollector\PDO\TraceablePDO(new OTS_DB_MySQL($params)); - $debugBar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($this->db)); + $this->db = new \MyAAC\Debug\TraceablePDOWithBacktrace(new OTS_DB_MySQL($params)); + $debugBar->addCollector(new \MyAAC\Debug\PDOCollectorWithBacktrace($this->db)); } else { $this->db = new OTS_DB_MySQL($params); diff --git a/system/src/Debug/PDOCollectorWithBacktrace.php b/system/src/Debug/PDOCollectorWithBacktrace.php new file mode 100644 index 00000000..86bc1afb --- /dev/null +++ b/system/src/Debug/PDOCollectorWithBacktrace.php @@ -0,0 +1,52 @@ +getBacktraces(); + foreach ($data['statements'] as $i => &$stmt) { + if (isset($backtraces[$i])) { + $stmt['backtrace'] = $this->formatBacktrace($backtraces[$i]); + } + } + unset($stmt); + } + + return $data; + } + + private function formatBacktrace(array $backtrace): array + { + $result = []; + foreach ($backtrace as $frame) { + if (!isset($frame['file'], $frame['line'])) { + continue; + } + + if (str_contains($frame['file'], DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR)) { + continue; + } + + if (str_contains($frame['file'], DIRECTORY_SEPARATOR . 'Debug' . DIRECTORY_SEPARATOR)) { + continue; + } + + $function = isset($frame['class']) + ? $frame['class'] . ($frame['type'] ?? '::') . ($frame['function'] ?? '') + : ($frame['function'] ?? ''); + + $result[] = ($function ? $function . '() ' : '') . $frame['file'] . ':' . $frame['line']; + } + return $result; + } +} diff --git a/system/src/Debug/TraceablePDOWithBacktrace.php b/system/src/Debug/TraceablePDOWithBacktrace.php new file mode 100644 index 00000000..c74f0630 --- /dev/null +++ b/system/src/Debug/TraceablePDOWithBacktrace.php @@ -0,0 +1,26 @@ +backtraces[] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + parent::addExecutedStatement($stmt); + } + + /** + * @return array[] + */ + public function getBacktraces(): array + { + return $this->backtraces; + } +}