X-Git-Url: https://git.cweiske.de/php-sqllint.git/blobdiff_plain/0f7963bb111a1a08ca51531c9b28681b2c33f1e9..89726a06721c1c91569426b98d2187316a9253d9:/bin/php-sqllint diff --git a/bin/php-sqllint b/bin/php-sqllint index 69372a0..f746813 100755 --- a/bin/php-sqllint +++ b/bin/php-sqllint @@ -1,68 +1,26 @@ #!/usr/bin/env php errors) == 0) { - echo "No syntax errors detected\n"; - exit(0); -} - -$lines = array(1 => 0); -$pos = -1; -$line = 1; -while (false !== $pos = strpos($sql, "\n", ++$pos)) { - $lines[++$line] = $pos; -} - -echo "Syntax errors found\n"; -foreach ($parser->errors as $error) { - reset($lines); - $line = 1; - while (next($lines) && $error->token->position >= current($lines)) { - ++$line; - } - $col = $error->token->position - $lines[$line]; - - /** @var SqlParser\Exceptions\ParserException $error) */ - echo 'Line ' . $line - . ' col ' . $col - //FIXME: ->token or ->value? - . ' at "' . niceToken($error->token->token) . '":' - . ' ' . $error->getMessage() - . "\n"; - //var_dump($error->token); -} - -function niceToken($str) -{ - return str_replace( - ["\n", "\r", "\t"], - ['\n', '\r', '\t'], - $str - ); -} +/** + * SQL linter (syntax checker) written in PHP + * + * PHP version 5 + * + * @category Tools + * @package PHP-SQLlint + * @author Christian Weiske + * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3 + * @link http://cweiske.de/php-sqllint.htm + */ +namespace phpsqllint; + +if (file_exists(__DIR__ . '/../vendor/autoload.php')) { + include_once __DIR__ . '/../vendor/autoload.php'; +} +if (file_exists(__DIR__ . '/../src/phpsqllint/Autoloader.php')) { + include_once __DIR__ . '/../src/phpsqllint/Autoloader.php'; + Autoloader::register(); +} + +$cli = new Cli(); +$cli->run(); ?> \ No newline at end of file