diff --git a/Resources/views/Collector/db.html.twig b/Resources/views/Collector/db.html.twig
index 75f7c314c..170c9088d 100644
--- a/Resources/views/Collector/db.html.twig
+++ b/Resources/views/Collector/db.html.twig
@@ -239,7 +239,7 @@
{{ '%0.2f'|format(query.executionMS * 1000) }} ms |
{% endif %}
- {{ query.sql|doctrine_pretty_query(highlight_only = true) }}
+ {{ query.sql|doctrine_prettify_sql }}
Parameters: {{ profiler_dump(query.params, 2) }}
@@ -265,15 +265,14 @@
- {% set formatted_sql = query.sql|doctrine_pretty_query %}
- {{ formatted_sql|raw }}
-
+ {{ query.sql|doctrine_format_sql(highlight = true) }}
+
{% if query.runnable %}
{% set runnable_sql = (query.sql ~ ';')|doctrine_replace_query_parameters(query.params) %}
- {{ runnable_sql|doctrine_pretty_query(highlight_only = true) }}
+ {{ runnable_sql|doctrine_prettify_sql }}
{% endif %}
diff --git a/Tests/ProfilerTest.php b/Tests/ProfilerTest.php
index e7245fea9..43a76ef13 100644
--- a/Tests/ProfilerTest.php
+++ b/Tests/ProfilerTest.php
@@ -67,7 +67,7 @@ public function testRender()
{
$this->logger->queries = [
[
- 'sql' => 'SELECT * FROM foo WHERE bar IN (?, ?)',
+ 'sql' => 'SELECT * FROM foo WHERE bar IN (?, ?) AND "" >= ""',
'params' => ['foo', 'bar'],
'types' => null,
'executionMS' => 1,
@@ -88,6 +88,16 @@ public function testRender()
]);
$output = str_replace(["\e[37m", "\e[0m", "\e[32;1m", "\e[34;1m"], '', $output);
- $this->assertContains("SELECT * FROM foo WHERE bar IN ('foo', 'bar');", $output);
+ $this->assertContains("SELECT * FROM foo WHERE bar IN ('foo', 'bar') AND \"\" >= \"\";", $output);
+
+ $expectedEscapedSql = 'SELECT
*
FROM
foo
WHERE
bar IN (?, ?)
AND "" >= ""';
+ $this->assertSame('SELECT
+ *
+FROM
+ foo
+WHERE
+ bar IN (?, ?)
+ AND "" >= ""', html_entity_decode($expectedEscapedSql));
+ $this->assertContains($expectedEscapedSql, $output);
}
}
diff --git a/Twig/DoctrineExtension.php b/Twig/DoctrineExtension.php
index b06ac94c9..0fe5478b5 100644
--- a/Twig/DoctrineExtension.php
+++ b/Twig/DoctrineExtension.php
@@ -20,7 +20,9 @@ class DoctrineExtension extends AbstractExtension
public function getFilters()
{
return [
- new TwigFilter('doctrine_pretty_query', [$this, 'formatQuery'], ['is_safe' => ['html']]),
+ new TwigFilter('doctrine_pretty_query', [$this, 'formatQuery'], ['is_safe' => ['html'], 'deprecated' => true]),
+ new TwigFilter('doctrine_prettify_sql', [$this, 'prettifySql'], ['is_safe' => ['html']]),
+ new TwigFilter('doctrine_format_sql', [$this, 'formatSql'], ['is_safe' => ['html']]),
new TwigFilter('doctrine_replace_query_parameters', [$this, 'replaceQueryParameters']),
];
}
@@ -169,16 +171,9 @@ static function ($matches) use ($parameters, &$i) {
*/
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"';
+ @trigger_error(sprintf('The "%s()" method is deprecated and will be removed in DoctrineBundle 3.0.', __METHOD__), E_USER_DEPRECATED);
+
+ $this->setUpSqlFormatter();
if ($highlightOnly) {
$html = SqlFormatter::highlight($sql);
@@ -191,6 +186,34 @@ public function formatQuery($sql, $highlightOnly = false)
return $html;
}
+ public function prettifySql(string $sql)
+ {
+ $this->setUpSqlFormatter();
+
+ return SqlFormatter::highlight($sql);
+ }
+
+ public function formatSql(string $sql, bool $highlight)
+ {
+ $this->setUpSqlFormatter();
+
+ return SqlFormatter::format($sql, $highlight);
+ }
+
+ private function setUpSqlFormatter()
+ {
+ 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"';
+ }
+
/**
* Get the name of the extension
*
|