Skip to content

Commit de66dd0

Browse files
committed
Migrate SqlFormatter usage from jdorn/sql-formatter to doctrine/sql-formatter
The jdorn package was removed but its global SqlFormatter class was still used in two templates. Move formatting to controllers using Doctrine's SqlFormatter with NullHighlighter, matching the existing pattern in CakeExamplesController.
1 parent 70fb491 commit de66dd0

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

plugins/Sandbox/src/Controller/GeoExamplesController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Cake\Core\Configure;
66
use Cake\Database\Driver\Mysql;
77
use Cake\Utility\Text;
8+
use Doctrine\SqlFormatter\NullHighlighter;
9+
use Doctrine\SqlFormatter\SqlFormatter;
810
use Exception;
911
use Geo\Exception\InconclusiveException;
1012
use Geo\Geocoder\Geocoder;
@@ -227,6 +229,7 @@ public function filter() {
227229

228230
$sandboxCities = [];
229231
$sqlQuery = null;
232+
$sqlQueryFormatted = null;
230233
$queryTime = null;
231234
$explainResult = null;
232235
if ($this->request->getData('city_id')) {
@@ -244,6 +247,7 @@ public function filter() {
244247
->contain(['Countries'])
245248
->limit(10);
246249
$sqlQuery = (string)$query;
250+
$sqlQueryFormatted = (new SqlFormatter(new NullHighlighter()))->format($sqlQuery);
247251

248252
// Get EXPLAIN output for the query
249253
if ($spatialAvailable && $this->request->getQuery('spatial')) {
@@ -255,7 +259,7 @@ public function filter() {
255259
$queryTime = (microtime(true) - $startTime) * 1000; // in milliseconds
256260
}
257261

258-
$this->set(compact('cities', 'sandboxCities', 'sqlQuery', 'spatialAvailable', 'spatialInfo', 'queryTime', 'explainResult'));
262+
$this->set(compact('cities', 'sandboxCities', 'sqlQuery', 'sqlQueryFormatted', 'spatialAvailable', 'spatialInfo', 'queryTime', 'explainResult'));
259263
}
260264

261265
/**

plugins/Sandbox/src/Controller/ToolsExamplesController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Sandbox\Controller;
44

55
use Cake\Event\EventInterface;
6+
use Doctrine\SqlFormatter\NullHighlighter;
7+
use Doctrine\SqlFormatter\SqlFormatter;
68
use RuntimeException;
79
use Sandbox\Model\Entity\BitmaskedRecord;
810
use Sandbox\Model\Enum\Flag;
@@ -194,6 +196,7 @@ public function bitmaskSearch() {
194196

195197
$query = $bitmaskedRecordsTable->find('search', search: $this->request->getQuery());
196198
$sql = (string)$query;
199+
$sqlFormatted = (new SqlFormatter(new NullHighlighter()))->format($sql);
197200

198201
$bitmaskedRecords = $this->paginate($query);
199202

@@ -206,7 +209,7 @@ public function bitmaskSearch() {
206209
if ($type !== 'multiOr' && $type !== 'multiAnd') {
207210
$flags[0] = ' - n/a (no flags) - ';
208211
}
209-
$this->set(compact('bitmaskedRecords', 'flags', 'type', 'sql'));
212+
$this->set(compact('bitmaskedRecords', 'flags', 'type', 'sql', 'sqlFormatted'));
210213
}
211214

212215
/**

plugins/Sandbox/templates/GeoExamples/filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147

148148
<details>
149149
<summary>SQL Query</summary>
150-
<?php echo SqlFormatter::format($sqlQuery); ?>
150+
<?php echo $sqlQueryFormatted; ?>
151151
</details>
152152

153153
<?php } ?>

plugins/Sandbox/templates/ToolsExamples/bitmask_search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@
6666
<h3>SQL query</h3>
6767
For example/demo purposes here the query it runs as per your filter selection above:
6868
<div>
69-
<?php echo SqlFormatter::format($sql); ?>
69+
<?php echo $sqlFormatted; ?>
7070
</div>
7171

0 commit comments

Comments
 (0)