add PropelDataCollector to debugbar, still missing some informations
This commit is contained in:
@@ -84,8 +84,7 @@ class Thelia extends Kernel
|
||||
$serviceContainer->setConnectionManager('thelia', $manager);
|
||||
|
||||
if ($this->isDebug()) {
|
||||
$serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
|
||||
|
||||
//$serviceContainer->setLogger('defaultLogger', Tlog::getInstance());
|
||||
$con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
|
||||
$con->useDebug(true);
|
||||
}
|
||||
|
||||
236
local/modules/DebugBar/DataCollector/PropelCollector.php
Normal file
236
local/modules/DebugBar/DataCollector/PropelCollector.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace DebugBar\DataCollector;
|
||||
use Propel\Runtime\Propel;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class PropelCollector
|
||||
* @package DebugBar\DataCollector
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class PropelCollector extends DataCollector implements Renderable, LoggerInterface
|
||||
{
|
||||
|
||||
protected $statements = array();
|
||||
|
||||
protected $accumulatedTime = 0;
|
||||
|
||||
protected $peakMemory = 0;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$serviceContainer = Propel::getServiceContainer();
|
||||
$serviceContainer->setLogger('defaultLogger', $this);
|
||||
|
||||
$con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
|
||||
$con->setLogMethods(array(
|
||||
'exec',
|
||||
'query',
|
||||
'execute', // these first three are the default
|
||||
'beginTransaction',
|
||||
'commit',
|
||||
'rollBack',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the DebugBar when data needs to be collected
|
||||
*
|
||||
* @return array Collected data
|
||||
*/
|
||||
function collect()
|
||||
{
|
||||
return array(
|
||||
'nb_statements' => count($this->statements),
|
||||
'nb_failed_statements' => 0,
|
||||
'accumulated_duration' => '10',
|
||||
'accumulated_duration_str' => $this->formatDuration(1),
|
||||
'peak_memory_usage' => $this->peakMemory,
|
||||
'peak_memory_usage_str' => $this->formatBytes($this->peakMemory),
|
||||
'statements' => $this->statements
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique name of the collector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'propel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash where keys are control names and their values
|
||||
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
"propel" => array(
|
||||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
|
||||
"map" => "propel",
|
||||
"default" => "[]"
|
||||
),
|
||||
"propel:badge" => array(
|
||||
"map" => "propel.nb_statements",
|
||||
"default" => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs with an arbitrary level.
|
||||
*
|
||||
* @param mixed $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function log($level, $message, array $context = array())
|
||||
{
|
||||
$this->statements[] = array(
|
||||
'sql' => $message,
|
||||
'is_success' => true,
|
||||
'duration' => 0,
|
||||
'duration_str' => $this->formatDuration(1),
|
||||
'memory' => 1,
|
||||
'memory_str' => $this->formatBytes(1)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* System is unusable.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function emergency($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action must be taken immediately.
|
||||
*
|
||||
* Example: Entire website down, database unavailable, etc. This should
|
||||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function alert($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical conditions.
|
||||
*
|
||||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function critical($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime errors that do not require immediate action but should typically
|
||||
* be logged and monitored.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function error($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptional occurrences that are not errors.
|
||||
*
|
||||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function warning($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal but significant events.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function notice($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interesting events.
|
||||
*
|
||||
* Example: User logs in, SQL logs.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function info($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed debug information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function debug($message, array $context = array())
|
||||
{
|
||||
$this->log(null, $message, $context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -22,9 +22,7 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace DebugBar\Listeners;
|
||||
use DebugBar\DataCollector\PDO\PDOCollector;
|
||||
use DebugBar\DataCollector\PDO\TraceablePDO;
|
||||
use Propel\Runtime\Propel;
|
||||
use DebugBar\DataCollector\PropelCollector;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Action\BaseAction;
|
||||
@@ -42,11 +40,7 @@ class DebugBarListeners extends BaseAction implements EventSubscriberInterface {
|
||||
{
|
||||
$debugBar = $this->container->get("debugBar");
|
||||
|
||||
$connection = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
|
||||
$connection = $connection->getWrappedConnection();
|
||||
|
||||
$pdo = new TraceablePDO($connection);
|
||||
$debugBar->addCollector(new PDOCollector($pdo));
|
||||
$debugBar->addCollector(new PropelCollector());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user