Пример #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;
 }
Пример #2
0
 function sy_format_sql($query, array $data = null)
 {
     if (!empty($data)) {
         foreach ($data as $name => $value) {
             $query = str_replace(':' . $name, \Simplify::db()->quote($value), $query);
         }
     }
     \SqlFormatter::$reserved_attributes = 'style="color: #F00; font-weight: bold;"';
     \SqlFormatter::$word_attributes = 'style="color: #00F;"';
     \SqlFormatter::$use_pre = false;
     return "\n" . \SqlFormatter::format($query) . "\n";
 }