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; }
/** * Formats a query. * * @param string $query The query to be formatted * @param array $options The formatting options. * * @return string The formatted string. */ public static function format($query, array $options = array()) { $lexer = new Lexer($query); $formatter = new Formatter($options); return $formatter->formatList($lexer->list); }
/** * @dataProvider formatQueries */ public function testFormat($query, $expected, $options) { $this->assertEquals($expected, Formatter::format($query, $options)); }
/** * Reformat the given file */ protected function formatFile($filename) { $this->renderer->startRendering($filename); $sql = $this->loadSql($filename); if ($sql === false) { return false; } $typeMap = array('none' => 'text', 'ansi' => 'cli', 'html' => 'html'); $options = array('type' => $typeMap[$this->highlight]); echo \SqlParser\Utils\Formatter::format($sql, $options) . "\n"; }