diff --git a/src/DI/Pass/ConnectionPass.php b/src/DI/Pass/ConnectionPass.php index e0c5c6d..205f5e2 100644 --- a/src/DI/Pass/ConnectionPass.php +++ b/src/DI/Pass/ConnectionPass.php @@ -82,8 +82,9 @@ public function loadConnectionConfiguration(string $connectionName, mixed $conne // Middlewares: debug if ($config->debug->panel) { + $sourcePaths = $config->debug->sourcePaths; $builder->addDefinition($this->prefix(sprintf('connections.%s.middleware.internal.debug.stack', $connectionName))) - ->setFactory(DebugStack::class) + ->setFactory(DebugStack::class, ['sourcePaths' => $sourcePaths]) ->setAutowired(false); $builder->addDefinition($this->prefix(sprintf('connections.%s.middleware.internal.debug', $connectionName))) ->setFactory(DebugMiddleware::class, [$this->prefix(sprintf('@connections.%s.middleware.internal.debug.stack', $connectionName)), $connectionName]) diff --git a/src/Middleware/Debug/DebugStack.php b/src/Middleware/Debug/DebugStack.php index b469f1f..006b867 100644 --- a/src/Middleware/Debug/DebugStack.php +++ b/src/Middleware/Debug/DebugStack.php @@ -2,6 +2,8 @@ namespace Nettrine\DBAL\Middleware\Debug; +use Nettrine\DBAL\Utils\QueryUtils; + /** * @see https://github.com/symfony/doctrine-bridge * @internal @@ -12,13 +14,23 @@ class DebugStack /** @var array> */ private array $data = []; + public function __construct( + /** @var array */ + private array $sourcePaths + ) + { + } + public function addQuery(string $connectionName, DebugQuery $query): void { + $backtrace = debug_backtrace(); + $backtrace = QueryUtils::getSource($this->sourcePaths, $backtrace); $this->data[$connectionName][] = [ 'sql' => $query->getSql(), 'params' => $query->getParams(), 'types' => $query->getTypes(), 'duration' => $query->getDuration(...), // stop() may not be called at this point + 'source' => $backtrace, ]; } diff --git a/src/Tracy/ConnectionPanel.php b/src/Tracy/ConnectionPanel.php index cd63d73..2d2ce1d 100644 --- a/src/Tracy/ConnectionPanel.php +++ b/src/Tracy/ConnectionPanel.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Query\QueryException; use Nettrine\DBAL\Middleware\Debug\DebugStack; +use Nettrine\DBAL\Utils\Formatter; use PDO; use PDOException; use Throwable; @@ -22,15 +23,19 @@ class ConnectionPanel implements IBarPanel protected string $connectionName; - private function __construct(DebugStack $stack, string $connectionName) + protected Connection $connection; + + private function __construct(DebugStack $stack, string $connectionName, Connection $connection) { $this->stack = $stack; $this->connectionName = $connectionName; + $this->connection = $connection; } public static function initialize( DebugStack $stack, string $connectionName, + Connection $connection, ?Bar $bar = null, ?BlueScreen $blueScreen = null, ): self @@ -38,7 +43,7 @@ public static function initialize( $blueScreen ??= Debugger::getBlueScreen(); $blueScreen->addPanel(self::renderException(...)); - $panel = new self($stack, $connectionName); + $panel = new self($stack, $connectionName, $connection); $bar ??= Debugger::getBar(); $bar->addPanel($panel); @@ -107,6 +112,7 @@ public function getPanel(): string { // phpcs:disable return Helpers::capture(function (): void { + $connection = $this->connection; $queries = $this->stack->getDataBy($this->connectionName); $queriesNum = count($queries); $totalTime = 0; @@ -115,6 +121,23 @@ public function getPanel(): string $totalTime += $query['duration']; } + $formatter = new Formatter(); + + /** + * @var string[] $params + */ + $params = $this->connection->getParams(); + + $dbParams = [ + 'driver' => $params['driver'], + 'host' => $params['host'], + 'user' => $params['user'], + 'password' => '*****', + 'dbname' => $params['dbname'], + 'port' => $params['port'], + 'charset' => $params['charset'], + ]; + require __DIR__ . '/templates/panel.phtml'; }); // phpcs:enable diff --git a/src/Tracy/templates/panel.phtml b/src/Tracy/templates/panel.phtml index 34ad466..f8047ad 100644 --- a/src/Tracy/templates/panel.phtml +++ b/src/Tracy/templates/panel.phtml @@ -2,10 +2,17 @@ namespace Nettrine\DBAL\Tracy; +use Doctrine\DBAL\Connection; +use Nettrine\DBAL\Utils\Formatter; +use Nettrine\DBAL\Utils\QueryUtils; use Tracy\Dumper; +use Tracy\Helpers; +/** @var Connection $connection */ +/** @var Formatter $formatter */ /** @var int $queriesNum */ /** @var int $totalTime */ +/** @var array $dbParams */ /** @var array $queries */ ?>