Added query report in the Propel panel (profiler)
This commit is contained in:
parent
9ef9298728
commit
5c99ffd5cc
3 changed files with 89 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FOSPropel package.
|
||||
* This file is part of the Propel package.
|
||||
*
|
||||
* (c) William DURAND <william.durand1@gmail.com>
|
||||
*
|
||||
|
|
@ -28,9 +28,19 @@ class PropelDataCollector extends DataCollector
|
|||
* @var Propel\PropelBundle\Logger\PropelLogger
|
||||
*/
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* Connection name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $connectionName;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \Propel\PropelBundle\Logger\PropelLogger $logger A PropelLogger
|
||||
* @param string $connectionName A connection name
|
||||
*/
|
||||
public function __construct(\Propel\PropelBundle\Logger\PropelLogger $logger, $connectionName)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
|
@ -44,15 +54,46 @@ class PropelDataCollector extends DataCollector
|
|||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
{
|
||||
$this->data = array(
|
||||
'queries' => $this->logger->getQueries(),
|
||||
'connectionName' => $this->connectionName,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the collector name.
|
||||
*
|
||||
* @return string The collector name.
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'propel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns queries.
|
||||
*
|
||||
* @return array Queries
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
return $this->data['queries'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query count.
|
||||
*
|
||||
* @return integer The query count
|
||||
*/
|
||||
public function getQueryCount()
|
||||
{
|
||||
return count($this->data['queries']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection name.
|
||||
*
|
||||
* @return string The connection name
|
||||
*/
|
||||
public function getConnectionName()
|
||||
{
|
||||
return $this->data['connectionName'];
|
||||
|
|
|
|||
|
|
@ -20,7 +20,14 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
|||
*/
|
||||
class PropelLogger implements \BasicLogger
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $queries;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -29,7 +36,8 @@ class PropelLogger implements \BasicLogger
|
|||
*/
|
||||
public function __construct(LoggerInterface $logger = null)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
$this->logger = $logger;
|
||||
$this->queries = array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,8 +132,20 @@ class PropelLogger implements \BasicLogger
|
|||
*/
|
||||
public function debug($message)
|
||||
{
|
||||
$this->queries[] = $message;
|
||||
|
||||
if (null !== $this->logger) {
|
||||
$this->logger->debug($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns queries.
|
||||
*
|
||||
* @return array Queries
|
||||
*/
|
||||
public function getQueries()
|
||||
{
|
||||
return $this->queries;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,35 @@
|
|||
{# the menu content #}
|
||||
<span class="label">
|
||||
<span class="icon"><img src="{{ asset('bundles/propel/images/profiler/propel.png') }}" alt="" /></span>
|
||||
<strong>Propel</strong>
|
||||
|
||||
|
||||
<strong>Propel</strong>
|
||||
<span class="count">
|
||||
<span>{{ collector.querycount }}</span>
|
||||
</span>
|
||||
</span>
|
||||
{% endblock %}
|
||||
|
||||
{% block panel %}
|
||||
{# the panel content #}
|
||||
|
||||
<h2>Queries</h2>
|
||||
<table summary="Show logged queries">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>SQL queries</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% if not collector.querycount %}
|
||||
<tr><td>No queries.</td></tr>
|
||||
{% else %}
|
||||
{% for query in collector.queries %}
|
||||
<tr>
|
||||
<td><code>{{ query }}</code></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% render 'PropelBundle:Panel:configuration' with { 'collector': collector } %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue