File: cli.php

package info (click to toggle)
php-sql-formatter 1.2.17%2Bdct1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 692 kB
  • sloc: php: 1,819; sql: 301; xml: 18; makefile: 17
file content (31 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

declare(strict_types=1);

if (PHP_SAPI !== 'cli') :?>
    <p>
        Run this php script from the command line to see CLI syntax highlighting and
        formatting.  It support Unix pipes or command line argument style.
    </p>
    <pre><code>php examples/cli.php \
"SELECT * FROM MyTable WHERE (id>5 AND \`name\` LIKE \&quot;testing\&quot;);"</code></pre>
    <pre><code>echo "SELECT * FROM MyTable WHERE (id>5 AND \`name\` LIKE \&quot;testing\&quot;);"\
 | php examples/cli.php</code></pre>
    <?php
    exit;
endif;

if (isset($argv[1])) {
    $sql = $argv[1];
} else {
    $fp = fopen('php://stdin', 'r');
    assert($fp !== false);
    $sql = stream_get_contents($fp);
}

require_once('SqlFormatter/autoload.php');

use Doctrine\SqlFormatter\SqlFormatter;
use Doctrine\SqlFormatter\Tokenizer;

echo (new SqlFormatter())->format($sql);