mirror of
https://github.com/slawkens/myaac.git
synced 2026-04-25 11:53:31 +02:00
Merge branch 'develop' into blacktek-toml
This commit is contained in:
@@ -372,8 +372,8 @@ class POT
|
|||||||
|
|
||||||
global $debugBar;
|
global $debugBar;
|
||||||
if (isset($debugBar)) {
|
if (isset($debugBar)) {
|
||||||
$this->db = new DebugBar\DataCollector\PDO\TraceablePDO(new OTS_DB_MySQL($params));
|
$this->db = new \MyAAC\Debug\TraceablePDOWithBacktrace(new OTS_DB_MySQL($params));
|
||||||
$debugBar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($this->db));
|
$debugBar->addCollector(new \MyAAC\Debug\PDOCollectorWithBacktrace($this->db));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->db = new OTS_DB_MySQL($params);
|
$this->db = new OTS_DB_MySQL($params);
|
||||||
|
|||||||
52
system/src/Debug/PDOCollectorWithBacktrace.php
Normal file
52
system/src/Debug/PDOCollectorWithBacktrace.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MyAAC\Debug;
|
||||||
|
|
||||||
|
use DebugBar\DataCollector\PDO\PDOCollector;
|
||||||
|
use DebugBar\DataCollector\PDO\TraceablePDO;
|
||||||
|
use DebugBar\DataCollector\TimeDataCollector;
|
||||||
|
|
||||||
|
class PDOCollectorWithBacktrace extends PDOCollector
|
||||||
|
{
|
||||||
|
protected function collectPDO(TraceablePDO $pdo, ?TimeDataCollector $timeCollector = null, $connectionName = null): array
|
||||||
|
{
|
||||||
|
$data = parent::collectPDO($pdo, $timeCollector, $connectionName);
|
||||||
|
|
||||||
|
if ($pdo instanceof TraceablePDOWithBacktrace) {
|
||||||
|
$backtraces = $pdo->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
system/src/Debug/TraceablePDOWithBacktrace.php
Normal file
26
system/src/Debug/TraceablePDOWithBacktrace.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MyAAC\Debug;
|
||||||
|
|
||||||
|
use DebugBar\DataCollector\PDO\TraceablePDO;
|
||||||
|
use DebugBar\DataCollector\PDO\TracedStatement;
|
||||||
|
|
||||||
|
class TraceablePDOWithBacktrace extends TraceablePDO
|
||||||
|
{
|
||||||
|
/** @var array[] */
|
||||||
|
protected array $backtraces = [];
|
||||||
|
|
||||||
|
public function addExecutedStatement(TracedStatement $stmt): void
|
||||||
|
{
|
||||||
|
$this->backtraces[] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
|
parent::addExecutedStatement($stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function getBacktraces(): array
|
||||||
|
{
|
||||||
|
return $this->backtraces;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user