diff --git a/Resources/views/Collector/db.html.twig b/Resources/views/Collector/db.html.twig index bdb55b897..d0c4b331f 100644 --- a/Resources/views/Collector/db.html.twig +++ b/Resources/views/Collector/db.html.twig @@ -164,7 +164,7 @@ {{ loop.index }} {{ '%0.2f'|format(query.executionMS * 1000) }} ms - {{ query.sql|doctrine_highlight_sql }} + {{ query.sql|doctrine_pretty_query(highlight_only = true) }}
Parameters: {{ query.params|yaml_encode }} @@ -188,7 +188,7 @@
{% if query.explainable %} diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php index ba4a58783..4add5be58 100644 --- a/Twig/DoctrineExtension.php +++ b/Twig/DoctrineExtension.php @@ -38,9 +38,8 @@ public function getFilters() { return array( new \Twig_SimpleFilter('doctrine_minify_query', array($this, 'minifyQuery'), array('deprecated' => true)), - new \Twig_SimpleFilter('doctrine_pretty_query', 'SqlFormatter::format', array('is_safe' => array('html'))), + new \Twig_SimpleFilter('doctrine_pretty_query', array($this, 'formatQuery'), array('is_safe' => array('html'))), new \Twig_SimpleFilter('doctrine_replace_query_parameters', array($this, 'replaceQueryParameters')), - new \Twig_SimpleFilter('doctrine_highlight_sql', array($this, 'highlightSqlSyntax'), array('is_safe' => array('html'))), ); } @@ -309,12 +308,14 @@ function ($matches) use ($parameters, &$i) { } /** - * Highlights the syntax of the given SQL statement. + * 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 highlightSqlSyntax($sql) + public function formatQuery($sql, $highlightOnly = false) { \SqlFormatter::$pre_attributes = 'class="highlight highlight-sql"'; \SqlFormatter::$quote_attributes = 'class="string"'; @@ -327,8 +328,13 @@ public function highlightSqlSyntax($sql) \SqlFormatter::$comment_attributes = 'class="comment"'; \SqlFormatter::$variable_attributes = 'class="variable"'; - $html = \SqlFormatter::highlight($sql); - $html = preg_replace('/
([^"]*+)<\/pre>/Us', '
\2
', $html); + if ($highlightOnly) { + $html = \SqlFormatter::highlight($sql); + $html = preg_replace('/
([^"]*+)<\/pre>/Us', '\1', $html);
+        } else {
+            $html = \SqlFormatter::format($sql);
+            $html = preg_replace('/
([^"]*+)<\/pre>/Us', '
\2
', $html); + } return $html; }