Added syntax highlighting to the SQL Queries log in the profiler.

Fix #15
This commit is contained in:
William DURAND 2011-05-24 11:38:05 +02:00
parent 7fd1dbe72b
commit c6d997cded
3 changed files with 40 additions and 1 deletions

View file

@ -10,6 +10,7 @@
<parameter key="propel.logger.class">Propel\PropelBundle\Logger\PropelLogger</parameter>
<parameter key="propel.data_collector.class">Propel\PropelBundle\DataCollector\PropelDataCollector</parameter>
<parameter key="propel.build_properties.class">Propel\PropelBundle\DependencyInjection\Properties</parameter>
<parameter key="propel.twig.extension.syntax.class">Propel\PropelBundle\Twig\Extension\SyntaxExtension</parameter>
</parameters>
<services>
@ -29,5 +30,8 @@
<argument type="service" id="propel.configuration" />
</service>
<service id="propel.twig.extension.syntax" class="%propel.twig.extension.syntax.class%">
<tag name="twig.extension" />
</service>
</services>
</container>

View file

@ -30,6 +30,11 @@
{% block panel %}
{# the panel content #}
<style type="text/css">
.SQLKeyword {
color: blue;
}
</style>
<h2>Queries</h2>
<table summary="Show logged queries">
@ -45,7 +50,7 @@
{% for query in collector.queries %}
<tr>
<td>
<code>{{ query.sql }}</code>
<code>{{ query.sql|formatSQL }}</code>
<div style="color: gray;font-size: 0.9em;">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
</td>
</tr>

View file

@ -0,0 +1,30 @@
<?php
namespace Propel\PropelBundle\Twig\Extension;
/**
* SyntaxExtension class
*
* @package PropelBundle
* @subpackage Extension
* @author William DURAND <william.durand1@gmail.com>
*/
class SyntaxExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
'formatSQL' => new \Twig_Filter_Method($this, 'formatSQL', array('is_safe' => array('html'))),
);
}
public function getName()
{
return 'propel_syntax_extension';
}
public function formatSQL($sql)
{
return 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)\b/', '<span class="SQLKeyword">\\1</span>', $sql);
}
}