Example #1
0
 /**
  * Formats and/or highlights the given SQL statement.
  *
  * @param  string $sql
  * @param  bool   $highlightOnly If true the query is not formatted, just highlighted
  *
  * @return string
  */
 public function formatQuery($sql, $highlightOnly = false)
 {
     \SqlFormatter::$pre_attributes = 'class="highlight highlight-sql"';
     \SqlFormatter::$quote_attributes = 'class="string"';
     \SqlFormatter::$backtick_quote_attributes = 'class="string"';
     \SqlFormatter::$reserved_attributes = 'class="keyword"';
     \SqlFormatter::$boundary_attributes = 'class="symbol"';
     \SqlFormatter::$number_attributes = 'class="number"';
     \SqlFormatter::$word_attributes = 'class="word"';
     \SqlFormatter::$error_attributes = 'class="error"';
     \SqlFormatter::$comment_attributes = 'class="comment"';
     \SqlFormatter::$variable_attributes = 'class="variable"';
     if ($highlightOnly) {
         $html = \SqlFormatter::highlight($sql);
         $html = preg_replace('/<pre class=".*">([^"]*+)<\\/pre>/Us', '\\1', $html);
     } else {
         $html = \SqlFormatter::format($sql);
         $html = preg_replace('/<pre class="(.*)">([^"]*+)<\\/pre>/Us', '<div class="\\1"><pre>\\2</pre></div>', $html);
     }
     return $html;
 }