File: cli.php

package info (click to toggle)
php-sql-formatter 1.2.17-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 432 kB
  • ctags: 298
  • sloc: php: 924; sql: 221; makefile: 17
file content (17 lines) | stat: -rw-r--r-- 669 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
if(php_sapi_name() !== "cli") {
	echo "<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>";
	echo "<pre><code>php examples/cli.php \"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 examples/cli.php</code></pre>";
}

if(isset($argv[1])) {
	$sql = $argv[1];
}
else {
	$sql = stream_get_contents(fopen("php://stdin", "r"));
}

require_once('SqlFormatter/autoload.php');

echo SqlFormatter::format($sql);