This commit is contained in:
Marek
2026-03-24 00:04:55 +01:00
commit c5229e48ed
4225 changed files with 511461 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
use Doctrine\SqlFormatter\CliHighlighter;
use Doctrine\SqlFormatter\HtmlHighlighter;
use Doctrine\SqlFormatter\NullHighlighter;
use Doctrine\SqlFormatter\SqlFormatter;
use Doctrine\SqlFormatter\Tests\SqlFormatterTest;
require __DIR__ . '/../vendor/autoload.php';
$formatter = new SqlFormatter(new HtmlHighlighter());
updateExpected('format-highlight.html', [$formatter, 'format']);
updateExpected('format.txt', [new SqlFormatter(new NullHighlighter()), 'format']);
updateExpected('highlight.html', [$formatter, 'highlight']);
updateExpected('clihighlight.txt', [new SqlFormatter(new CliHighlighter()), 'format']);
updateExpected('compress.txt', [$formatter, 'compress']);
function updateExpected(string $filename, callable $highlight): void
{
$data = [];
foreach (SqlFormatterTest::fileSqlData() as $sql) {
$data[] = rtrim($highlight($sql), "\n");
}
file_put_contents(__DIR__ . '/../tests/' . $filename, implode("\n---\n", $data) . "\n");
}

View File

@@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php
if("cli" !== php_sapi_name()) {
echo "<p>Run this PHP script from the command line to see CLI syntax highlighting and formatting. It supports Unix pipes or command line argument style.</p>";
echo "<pre><code>php bin/sql-formatter \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\"</code></pre>";
echo "<pre><code>echo \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\&quot;testing\\&quot;);\" | php bin/sql-formatter</code></pre>";
exit;
}
if(isset($argv[1])) {
$sql = $argv[1];
}
else {
$sql = stream_get_contents(fopen('php://stdin', 'r'));
}
$autoloadFiles = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php'
];
foreach ($autoloadFiles as $autoloadFile) {
if (file_exists($autoloadFile)) {
require_once $autoloadFile;
break;
}
}
echo (new \Doctrine\SqlFormatter\SqlFormatter())->format($sql);