| Server IP : 165.22.154.248 / Your IP : 216.73.216.251 [ Web Server : Apache/2.4.29 (Ubuntu) System : Linux droplet-integra 4.15.0-197-generic #208-Ubuntu SMP Tue Nov 1 17:23:37 UTC 2022 x86_64 User : www-data ( 33) PHP Version : 7.2.24-0ubuntu0.18.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, Domains : 1 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/phpmyadmin/libraries/sql-parser/src/Utils/ |
Upload File : |
<?php
/**
* CLI interface.
*/
namespace SqlParser\Utils;
use SqlParser\Parser;
use SqlParser\Lexer;
/**
* CLI interface.
*
* @category Exceptions
*
* @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+
*/
class CLI
{
public function mergeLongOpts(&$params, &$longopts)
{
foreach ($longopts as $value) {
$value = rtrim($value, ':');
if (isset($params[$value])) {
$params[$value[0]] = $params[$value];
}
}
}
public function usageHighlight()
{
echo "Usage: highlight-query --query SQL [--format html|cli|text]\n";
}
public function getopt($opt, $long)
{
return getopt($opt, $long);
}
public function parseHighlight()
{
$longopts = array('help', 'query:', 'format:');
$params = $this->getopt(
'hq:f:', $longopts
);
if ($params === false) {
return false;
}
$this->mergeLongOpts($params, $longopts);
if (!isset($params['f'])) {
$params['f'] = 'cli';
}
if (!in_array($params['f'], array('html', 'cli', 'text'))) {
echo "ERROR: Invalid value for format!\n";
return false;
}
return $params;
}
public function runHighlight()
{
$params = $this->parseHighlight();
if ($params === false) {
return 1;
}
if (isset($params['h'])) {
$this->usageHighlight();
return 0;
}
if (isset($params['q'])) {
echo Formatter::format(
$params['q'], array('type' => $params['f'])
);
echo "\n";
return 0;
}
echo "ERROR: Missing parameters!\n";
$this->usageHighlight();
return 1;
}
public function usageLint()
{
echo "Usage: lint-query --query SQL\n";
}
public function parseLint()
{
$longopts = array('help', 'query:');
$params = $this->getopt(
'hq:', $longopts
);
$this->mergeLongOpts($params, $longopts);
return $params;
}
public function runLint()
{
$params = $this->parseLint();
if ($params === false) {
return 1;
}
if (isset($params['h'])) {
$this->usageLint();
return 0;
}
if (isset($params['q'])) {
$lexer = new Lexer($params['q'], false);
$parser = new Parser($lexer->list);
$errors = Error::get(array($lexer, $parser));
if (count($errors) == 0) {
return 0;
}
$output = Error::format($errors);
echo implode("\n", $output);
echo "\n";
return 10;
}
echo "ERROR: Missing parameters!\n";
$this->usageLint();
return 1;
}
}