Added syntax highlighting to the SQL Queries log in the profiler.
Fix #15
This commit is contained in:
parent
7fd1dbe72b
commit
c6d997cded
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
30
Twig/Extension/SyntaxExtension.php
Normal file
30
Twig/Extension/SyntaxExtension.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue