diff --git a/Resources/views/Collector/propel.html.twig b/Resources/views/Collector/propel.html.twig
index ff9973b..76fec15 100644
--- a/Resources/views/Collector/propel.html.twig
+++ b/Resources/views/Collector/propel.html.twig
@@ -29,6 +29,17 @@
@@ -47,7 +58,7 @@
{{ query.sql|format_sql }}
- Time: {{ query.time }} - Memory: {{ query.memory }}
+ Time: {{ query.time }} - Memory: {{ query.memory }}
|
{% endfor %}
diff --git a/Twig/Extension/SyntaxExtension.php b/Twig/Extension/SyntaxExtension.php
index 193bf1a..b9ddd50 100644
--- a/Twig/Extension/SyntaxExtension.php
+++ b/Twig/Extension/SyntaxExtension.php
@@ -33,9 +33,62 @@ class SyntaxExtension extends \Twig_Extension
public function formatSQL($sql)
{
- $sql = preg_replace('/\b(UPDATE|SET|SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES|ON|AND|OR)\b/', '\\1', $sql);
+ // list of keywords to prepend a newline in output
+ $newlines = array(
+ 'FROM',
+ '(((FULL|LEFT|RIGHT)? ?(OUTER|INNER)?|CROSS|NATURAL)? JOIN)',
+ 'VALUES',
+ 'WHERE',
+ 'ORDER BY',
+ 'GROUP BY',
+ 'HAVING',
+ 'LIMIT',
+ );
- $sql = preg_replace('/\b(FROM|WHERE|INNER JOIN|LEFT JOIN|RIGHT JOIN|ORDER BY|GROUP BY)\b/', '
\\1', $sql);
+ // list of keywords to highlight
+ $keywords = array_merge($newlines, array(
+ // base
+ 'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'REPLACE',
+ 'SET',
+ 'INTO',
+ 'AS',
+ 'DISTINCT',
+
+ // most used methods
+ 'COUNT',
+ 'AVG',
+ 'MIN',
+ 'MAX',
+
+ // joins
+ 'ON', 'USING',
+
+ // where clause
+ '(IS (NOT)?)?NULL',
+ '(NOT )?IN',
+ '(NOT )?I?LIKE',
+ 'AND', 'OR', 'XOR',
+ 'BETWEEN',
+
+ // order, group, limit ..
+ 'ASC',
+ 'DESC',
+ 'OFFSET',
+ ));
+
+ $sql = preg_replace(array(
+ '/\b('.implode('|', $newlines).')\b/',
+ '/\b('.implode('|', $keywords).')\b/',
+ '/(\/\*.*\*\/)/',
+ '/(`[^`.]*`)/',
+ '/(([0-9a-zA-Z$_]+)\.([0-9a-zA-Z$_]+))/',
+ ), array(
+ '
\\1',
+ '\\1',
+ '',
+ '\\1',
+ '\\1',
+ ), $sql);
return $sql;
}