Skip to content

Commit a84b1cc

Browse files
committed
Replaced the jdorn formatter with the doctrine formatter
1 parent 429ce6d commit a84b1cc

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
},
1818
"require": {
1919
"php": ">=7.3.0",
20-
"jdorn/sql-formatter": "^1.2.17",
21-
"symfony/var-dumper": "^5.1.3"
20+
"doctrine/sql-formatter": "^1.1",
21+
"symfony/var-dumper": "^5.2"
2222
},
2323
"require-dev": {
2424
"mako/framework": "^7.0.0-dev"

src/panels/DatabasePanel.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
namespace mako\toolbar\panels;
99

10+
use Doctrine\SqlFormatter\HtmlHighlighter;
11+
use Doctrine\SqlFormatter\SqlFormatter;
1012
use mako\database\ConnectionManager;
1113
use mako\view\ViewFactory;
12-
use SqlFormatter;
1314

1415
use function array_column;
1516
use function array_sum;
@@ -27,7 +28,7 @@ class DatabasePanel extends Panel implements PanelInterface
2728
/**
2829
* Conenction manager instance.
2930
*
30-
* @var array
31+
* @var \mako\database\ConnectionManager
3132
*/
3233
protected $database;
3334

@@ -87,17 +88,22 @@ public function getTabLabel(): string
8788
*/
8889
protected function getFormattedLog(array $logs): array
8990
{
90-
// Configure the SQL formatter
91+
// Configure the SQL highlighter
9192

92-
SqlFormatter::$pre_attributes = 'style="color: black; background-color: transparent;"';
93+
$highlighter = new HtmlHighlighter
94+
([
95+
HtmlHighlighter::HIGHLIGHT_PRE => 'style="color: inherit; background-color: transparent;"',
96+
]);
9397

9498
// Add syntax highlighting to SQL queries
9599

100+
$formatter = new SqlFormatter($highlighter);
101+
96102
foreach($logs as &$log)
97103
{
98104
foreach($log as $key => $query)
99105
{
100-
$log[$key]['query'] = SqlFormatter::format($query['query']);
106+
$log[$key]['query'] = $formatter->format($query['query']);
101107
}
102108
}
103109

0 commit comments

Comments
 (0)