Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider formatQueries
  */
 public function testFormat($query, $expected, $options)
 {
     $this->assertEquals($expected, Formatter::format($query, $options));
 }
Ejemplo n.º 4
0
 /**
  * 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";
 }