update v1.0.7.9 R.C.
This is a Release Candidate. We are still testing.
This commit is contained in:
62
vendor/maximebf/debugbar/src/DebugBar/Bridge/CacheCacheCollector.php
vendored
Normal file
62
vendor/maximebf/debugbar/src/DebugBar/Bridge/CacheCacheCollector.php
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use CacheCache\Cache;
|
||||
use CacheCache\LoggingBackend;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Collects CacheCache operations
|
||||
*
|
||||
* http://maximebf.github.io/CacheCache/
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $debugbar->addCollector(new CacheCacheCollector(CacheManager::get('default')));
|
||||
* // or
|
||||
* $debugbar->addCollector(new CacheCacheCollector());
|
||||
* $debugbar['cache']->addCache(CacheManager::get('default'));
|
||||
* </code>
|
||||
*/
|
||||
class CacheCacheCollector extends MonologCollector
|
||||
{
|
||||
protected $logger;
|
||||
|
||||
public function __construct(Cache $cache = null, Logger $logger = null, $level = Logger::DEBUG, $bubble = true)
|
||||
{
|
||||
parent::__construct(null, $level, $bubble);
|
||||
|
||||
if ($logger === null) {
|
||||
$logger = new Logger('Cache');
|
||||
}
|
||||
$this->logger = $logger;
|
||||
|
||||
if ($cache !== null) {
|
||||
$this->addCache($cache);
|
||||
}
|
||||
}
|
||||
|
||||
public function addCache(Cache $cache)
|
||||
{
|
||||
$backend = $cache->getBackend();
|
||||
if (!($backend instanceof LoggingBackend)) {
|
||||
$backend = new LoggingBackend($backend, $this->logger);
|
||||
}
|
||||
$cache->setBackend($backend);
|
||||
$this->addLogger($backend->getLogger());
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'cache';
|
||||
}
|
||||
}
|
||||
98
vendor/maximebf/debugbar/src/DebugBar/Bridge/DoctrineCollector.php
vendored
Normal file
98
vendor/maximebf/debugbar/src/DebugBar/Bridge/DoctrineCollector.php
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use DebugBar\DebugBarException;
|
||||
use Doctrine\DBAL\Logging\DebugStack;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
/**
|
||||
* Collects Doctrine queries
|
||||
*
|
||||
* http://doctrine-project.org
|
||||
*
|
||||
* Uses the DebugStack logger to collects data about queries
|
||||
*
|
||||
* <code>
|
||||
* $debugStack = new Doctrine\DBAL\Logging\DebugStack();
|
||||
* $entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
|
||||
* $debugbar->addCollector(new DoctrineCollector($debugStack));
|
||||
* </code>
|
||||
*/
|
||||
class DoctrineCollector extends DataCollector implements Renderable, AssetProvider
|
||||
{
|
||||
protected $debugStack;
|
||||
|
||||
public function __construct($debugStackOrEntityManager)
|
||||
{
|
||||
if ($debugStackOrEntityManager instanceof EntityManager) {
|
||||
$debugStackOrEntityManager = $debugStackOrEntityManager->getConnection()->getConfiguration()->getSQLLogger();
|
||||
}
|
||||
if (!($debugStackOrEntityManager instanceof DebugStack)) {
|
||||
throw new DebugBarException("'DoctrineCollector' requires an 'EntityManager' or 'DebugStack' object");
|
||||
}
|
||||
$this->debugStack = $debugStackOrEntityManager;
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
$queries = array();
|
||||
$totalExecTime = 0;
|
||||
foreach ($this->debugStack->queries as $q) {
|
||||
$queries[] = array(
|
||||
'sql' => $q['sql'],
|
||||
'params' => (object) $q['params'],
|
||||
'duration' => $q['executionMS'],
|
||||
'duration_str' => $this->formatDuration($q['executionMS'])
|
||||
);
|
||||
$totalExecTime += $q['executionMS'];
|
||||
}
|
||||
|
||||
return array(
|
||||
'nb_statements' => count($queries),
|
||||
'accumulated_duration' => $totalExecTime,
|
||||
'accumulated_duration_str' => $this->formatDuration($totalExecTime),
|
||||
'statements' => $queries
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'doctrine';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
"database" => array(
|
||||
"icon" => "arrow-right",
|
||||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
|
||||
"map" => "doctrine",
|
||||
"default" => "[]"
|
||||
),
|
||||
"database:badge" => array(
|
||||
"map" => "doctrine.nb_statements",
|
||||
"default" => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAssets()
|
||||
{
|
||||
return array(
|
||||
'css' => 'widgets/sqlqueries/widget.css',
|
||||
'js' => 'widgets/sqlqueries/widget.js'
|
||||
);
|
||||
}
|
||||
}
|
||||
103
vendor/maximebf/debugbar/src/DebugBar/Bridge/MonologCollector.php
vendored
Normal file
103
vendor/maximebf/debugbar/src/DebugBar/Bridge/MonologCollector.php
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use DebugBar\DataCollector\DataCollectorInterface;
|
||||
use DebugBar\DataCollector\MessagesAggregateInterface;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* A monolog handler as well as a data collector
|
||||
*
|
||||
* https://github.com/Seldaek/monolog
|
||||
*
|
||||
* <code>
|
||||
* $debugbar->addCollector(new MonologCollector($logger));
|
||||
* </code>
|
||||
*/
|
||||
class MonologCollector extends AbstractProcessingHandler implements DataCollectorInterface, Renderable, MessagesAggregateInterface
|
||||
{
|
||||
protected $name;
|
||||
|
||||
protected $records = array();
|
||||
|
||||
/**
|
||||
* @param Logger $logger
|
||||
* @param int $level
|
||||
* @param boolean $bubble
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct(Logger $logger = null, $level = Logger::DEBUG, $bubble = true, $name = 'monolog')
|
||||
{
|
||||
parent::__construct($level, $bubble);
|
||||
$this->name = $name;
|
||||
if ($logger !== null) {
|
||||
$this->addLogger($logger);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds logger which messages you want to log
|
||||
*
|
||||
* @param Logger $logger
|
||||
*/
|
||||
public function addLogger(Logger $logger)
|
||||
{
|
||||
$logger->pushHandler($this);
|
||||
}
|
||||
|
||||
protected function write(array $record)
|
||||
{
|
||||
$this->records[] = array(
|
||||
'message' => $record['formatted'],
|
||||
'is_string' => true,
|
||||
'label' => strtolower($record['level_name']),
|
||||
'time' => $record['datetime']->format('U')
|
||||
);
|
||||
}
|
||||
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->records;
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
return array(
|
||||
'count' => count($this->records),
|
||||
'records' => $this->records
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
$name = $this->getName();
|
||||
return array(
|
||||
$name => array(
|
||||
"icon" => "suitcase",
|
||||
"widget" => "PhpDebugBar.Widgets.MessagesWidget",
|
||||
"map" => "$name.records",
|
||||
"default" => "[]"
|
||||
),
|
||||
"$name:badge" => array(
|
||||
"map" => "$name.count",
|
||||
"default" => "null"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
307
vendor/maximebf/debugbar/src/DebugBar/Bridge/Propel2Collector.php
vendored
Normal file
307
vendor/maximebf/debugbar/src/DebugBar/Bridge/Propel2Collector.php
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use Propel\Runtime\Connection\ConnectionInterface;
|
||||
use Propel\Runtime\Connection\ProfilerConnectionWrapper;
|
||||
use Propel\Runtime\Propel;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* A Propel logger which acts as a data collector
|
||||
*
|
||||
* http://propelorm.org/
|
||||
*
|
||||
* Will log queries and display them using the SQLQueries widget.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $debugbar->addCollector(new \DebugBar\Bridge\Propel2Collector(\Propel\Runtime\Propel::getServiceContainer()->getReadConnection()));
|
||||
* </code>
|
||||
*/
|
||||
class Propel2Collector extends DataCollector implements Renderable, AssetProvider
|
||||
{
|
||||
/**
|
||||
* @var null|TestHandler
|
||||
*/
|
||||
protected $handler = null;
|
||||
|
||||
/**
|
||||
* @var null|Logger
|
||||
*/
|
||||
protected $logger = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $errors = array();
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $queryCount = 0;
|
||||
|
||||
/**
|
||||
* @param ConnectionInterface $connection Propel connection
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
array $logMethods = array(
|
||||
'beginTransaction',
|
||||
'commit',
|
||||
'rollBack',
|
||||
'forceRollBack',
|
||||
'exec',
|
||||
'query',
|
||||
'execute'
|
||||
)
|
||||
) {
|
||||
if ($connection instanceof ProfilerConnectionWrapper) {
|
||||
$connection->setLogMethods($logMethods);
|
||||
|
||||
$this->config = $connection->getProfiler()->getConfiguration();
|
||||
|
||||
$this->handler = new TestHandler();
|
||||
|
||||
if ($connection->getLogger() instanceof Logger) {
|
||||
$this->logger = $connection->getLogger();
|
||||
$this->logger->pushHandler($this->handler);
|
||||
} else {
|
||||
$this->errors[] = 'Supported only monolog logger';
|
||||
}
|
||||
} else {
|
||||
$this->errors[] = 'You need set ProfilerConnectionWrapper';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TestHandler|null
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Logger|null
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
protected function getDefaultLogger()
|
||||
{
|
||||
return Propel::getServiceContainer()->getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function getQueryCount()
|
||||
{
|
||||
return $this->queryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $records
|
||||
* @param array $config
|
||||
* @return array
|
||||
*/
|
||||
protected function getStatements($records, $config)
|
||||
{
|
||||
$statements = array();
|
||||
foreach ($records as $record) {
|
||||
$duration = null;
|
||||
$memory = null;
|
||||
|
||||
$isSuccess = ( LogLevel::INFO === strtolower($record['level_name']) );
|
||||
|
||||
$detailsCount = count($config['details']);
|
||||
$parameters = explode($config['outerGlue'], $record['message'], $detailsCount + 1);
|
||||
if (count($parameters) === ($detailsCount + 1)) {
|
||||
$parameters = array_map('trim', $parameters);
|
||||
$_details = array();
|
||||
foreach (array_splice($parameters, 0, $detailsCount) as $string) {
|
||||
list($key, $value) = array_map('trim', explode($config['innerGlue'], $string, 2));
|
||||
$_details[$key] = $value;
|
||||
}
|
||||
|
||||
$details = array();
|
||||
foreach ($config['details'] as $key => $detail) {
|
||||
if (isset($_details[$detail['name']])) {
|
||||
$value = $_details[$detail['name']];
|
||||
if ('time' === $key) {
|
||||
if (substr_count($value, 'ms')) {
|
||||
$value = (float)$value / 1000;
|
||||
} else {
|
||||
$value = (float)$value;
|
||||
}
|
||||
} else {
|
||||
$suffixes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
|
||||
$suffix = substr($value, -2);
|
||||
$i = array_search($suffix, $suffixes, true);
|
||||
$i = (false === $i) ? 0 : $i;
|
||||
|
||||
$value = ((float)$value) * pow(1024, $i);
|
||||
}
|
||||
$details[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($details['time'])) {
|
||||
$duration = $details['time'];
|
||||
}
|
||||
if (isset($details['memDelta'])) {
|
||||
$memory = $details['memDelta'];
|
||||
}
|
||||
|
||||
$message = end($parameters);
|
||||
|
||||
if ($isSuccess) {
|
||||
$this->queryCount++;
|
||||
}
|
||||
|
||||
} else {
|
||||
$message = $record['message'];
|
||||
}
|
||||
|
||||
$statement = array(
|
||||
'sql' => $message,
|
||||
'is_success' => $isSuccess,
|
||||
'duration' => $duration,
|
||||
'duration_str' => $this->getDataFormatter()->formatDuration($duration),
|
||||
'memory' => $memory,
|
||||
'memory_str' => $this->getDataFormatter()->formatBytes($memory),
|
||||
);
|
||||
|
||||
if (false === $isSuccess) {
|
||||
$statement['sql'] = '';
|
||||
$statement['error_code'] = $record['level'];
|
||||
$statement['error_message'] = $message;
|
||||
}
|
||||
|
||||
$statements[] = $statement;
|
||||
}
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function collect()
|
||||
{
|
||||
if (count($this->errors)) {
|
||||
return array(
|
||||
'statements' => array_map(function ($message) {
|
||||
return array('sql' => '', 'is_success' => false, 'error_code' => 500, 'error_message' => $message);
|
||||
}, $this->errors),
|
||||
'nb_statements' => 0,
|
||||
'nb_failed_statements' => count($this->errors),
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->getHandler() === null) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$statements = $this->getStatements($this->getHandler()->getRecords(), $this->getConfig());
|
||||
|
||||
$failedStatement = count(array_filter($statements, function ($statement) {
|
||||
return false === $statement['is_success'];
|
||||
}));
|
||||
$accumulatedDuration = array_reduce($statements, function ($accumulatedDuration, $statement) {
|
||||
|
||||
$time = isset($statement['duration']) ? $statement['duration'] : 0;
|
||||
return $accumulatedDuration += $time;
|
||||
});
|
||||
$memoryUsage = array_reduce($statements, function ($memoryUsage, $statement) {
|
||||
|
||||
$time = isset($statement['memory']) ? $statement['memory'] : 0;
|
||||
return $memoryUsage += $time;
|
||||
});
|
||||
|
||||
return array(
|
||||
'nb_statements' => $this->getQueryCount(),
|
||||
'nb_failed_statements' => $failedStatement,
|
||||
'accumulated_duration' => $accumulatedDuration,
|
||||
'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($accumulatedDuration),
|
||||
'memory_usage' => $memoryUsage,
|
||||
'memory_usage_str' => $this->getDataFormatter()->formatBytes($memoryUsage),
|
||||
'statements' => $statements
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
$additionalName = '';
|
||||
if ($this->getLogger() !== $this->getDefaultLogger()) {
|
||||
$additionalName = ' ('.$this->getLogger()->getName().')';
|
||||
}
|
||||
|
||||
return 'propel2'.$additionalName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
$this->getName() => array(
|
||||
'icon' => 'bolt',
|
||||
'widget' => 'PhpDebugBar.Widgets.SQLQueriesWidget',
|
||||
'map' => $this->getName(),
|
||||
'default' => '[]'
|
||||
),
|
||||
$this->getName().':badge' => array(
|
||||
'map' => $this->getName().'.nb_statements',
|
||||
'default' => 0
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAssets()
|
||||
{
|
||||
return array(
|
||||
'css' => 'widgets/sqlqueries/widget.css',
|
||||
'js' => 'widgets/sqlqueries/widget.js'
|
||||
);
|
||||
}
|
||||
}
|
||||
253
vendor/maximebf/debugbar/src/DebugBar/Bridge/PropelCollector.php
vendored
Normal file
253
vendor/maximebf/debugbar/src/DebugBar/Bridge/PropelCollector.php
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use BasicLogger;
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Propel;
|
||||
use PropelConfiguration;
|
||||
use PropelPDO;
|
||||
use Psr\Log\LogLevel;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* A Propel logger which acts as a data collector
|
||||
*
|
||||
* http://propelorm.org/
|
||||
*
|
||||
* Will log queries and display them using the SQLQueries widget.
|
||||
* You can provide a LoggerInterface object to forward non-query related message to.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $debugbar->addCollector(new PropelCollector($debugbar['messages']));
|
||||
* PropelCollector::enablePropelProfiling();
|
||||
* </code>
|
||||
*/
|
||||
class PropelCollector extends DataCollector implements BasicLogger, Renderable, AssetProvider
|
||||
{
|
||||
protected $logger;
|
||||
|
||||
protected $statements = array();
|
||||
|
||||
protected $accumulatedTime = 0;
|
||||
|
||||
protected $peakMemory = 0;
|
||||
|
||||
/**
|
||||
* Sets the needed configuration option in propel to enable query logging
|
||||
*
|
||||
* @param PropelConfiguration $config Apply profiling on a specific config
|
||||
*/
|
||||
public static function enablePropelProfiling(PropelConfiguration $config = null)
|
||||
{
|
||||
if ($config === null) {
|
||||
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
|
||||
}
|
||||
$config->setParameter('debugpdo.logging.details.method.enabled', true);
|
||||
$config->setParameter('debugpdo.logging.details.time.enabled', true);
|
||||
$config->setParameter('debugpdo.logging.details.mem.enabled', true);
|
||||
$allMethods = array(
|
||||
'PropelPDO::__construct', // logs connection opening
|
||||
'PropelPDO::__destruct', // logs connection close
|
||||
'PropelPDO::exec', // logs a query
|
||||
'PropelPDO::query', // logs a query
|
||||
'PropelPDO::beginTransaction', // logs a transaction begin
|
||||
'PropelPDO::commit', // logs a transaction commit
|
||||
'PropelPDO::rollBack', // logs a transaction rollBack (watch out for the capital 'B')
|
||||
'DebugPDOStatement::execute', // logs a query from a prepared statement
|
||||
);
|
||||
$config->setParameter('debugpdo.logging.methods', $allMethods, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoggerInterface $logger A logger to forward non-query log lines to
|
||||
* @param PropelPDO $conn Bound this collector to a connection only
|
||||
*/
|
||||
public function __construct(LoggerInterface $logger = null, PropelPDO $conn = null)
|
||||
{
|
||||
if ($conn) {
|
||||
$conn->setLogger($this);
|
||||
} else {
|
||||
Propel::setLogger($this);
|
||||
}
|
||||
$this->logger = $logger;
|
||||
$this->logQueriesToLogger = false;
|
||||
}
|
||||
|
||||
public function setLogQueriesToLogger($enable = true)
|
||||
{
|
||||
$this->logQueriesToLogger = $enable;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isLogQueriesToLogger()
|
||||
{
|
||||
return $this->logQueriesToLogger;
|
||||
}
|
||||
|
||||
public function emergency($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_EMERG);
|
||||
}
|
||||
|
||||
public function alert($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_ALERT);
|
||||
}
|
||||
|
||||
public function crit($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_CRIT);
|
||||
}
|
||||
|
||||
public function err($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_ERR);
|
||||
}
|
||||
|
||||
public function warning($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_WARNING);
|
||||
}
|
||||
|
||||
public function notice($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_NOTICE);
|
||||
}
|
||||
|
||||
public function info($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_INFO);
|
||||
}
|
||||
|
||||
public function debug($m)
|
||||
{
|
||||
$this->log($m, Propel::LOG_DEBUG);
|
||||
}
|
||||
|
||||
public function log($message, $severity = null)
|
||||
{
|
||||
if (strpos($message, 'DebugPDOStatement::execute') !== false) {
|
||||
list($sql, $duration_str) = $this->parseAndLogSqlQuery($message);
|
||||
if (!$this->logQueriesToLogger) {
|
||||
return;
|
||||
}
|
||||
$message = "$sql ($duration_str)";
|
||||
}
|
||||
|
||||
if ($this->logger !== null) {
|
||||
$this->logger->log($this->convertLogLevel($severity), $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Propel log levels to PSR log levels
|
||||
*
|
||||
* @param int $level
|
||||
* @return string
|
||||
*/
|
||||
protected function convertLogLevel($level)
|
||||
{
|
||||
$map = array(
|
||||
Propel::LOG_EMERG => LogLevel::EMERGENCY,
|
||||
Propel::LOG_ALERT => LogLevel::ALERT,
|
||||
Propel::LOG_CRIT => LogLevel::CRITICAL,
|
||||
Propel::LOG_ERR => LogLevel::ERROR,
|
||||
Propel::LOG_WARNING => LogLevel::WARNING,
|
||||
Propel::LOG_NOTICE => LogLevel::NOTICE,
|
||||
Propel::LOG_DEBUG => LogLevel::DEBUG
|
||||
);
|
||||
return $map[$level];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a log line to extract query information
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
protected function parseAndLogSqlQuery($message)
|
||||
{
|
||||
$parts = explode('|', $message, 4);
|
||||
$sql = trim($parts[3]);
|
||||
|
||||
$duration = 0;
|
||||
if (preg_match('/([0-9]+\.[0-9]+)/', $parts[1], $matches)) {
|
||||
$duration = (float) $matches[1];
|
||||
}
|
||||
|
||||
$memory = 0;
|
||||
if (preg_match('/([0-9]+\.[0-9]+) ([A-Z]{1,2})/', $parts[2], $matches)) {
|
||||
$memory = (float) $matches[1];
|
||||
if ($matches[2] == 'KB') {
|
||||
$memory *= 1024;
|
||||
} elseif ($matches[2] == 'MB') {
|
||||
$memory *= 1024 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
$this->statements[] = array(
|
||||
'sql' => $sql,
|
||||
'is_success' => true,
|
||||
'duration' => $duration,
|
||||
'duration_str' => $this->formatDuration($duration),
|
||||
'memory' => $memory,
|
||||
'memory_str' => $this->formatBytes($memory)
|
||||
);
|
||||
$this->accumulatedTime += $duration;
|
||||
$this->peakMemory = max($this->peakMemory, $memory);
|
||||
return array($sql, $this->formatDuration($duration));
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
return array(
|
||||
'nb_statements' => count($this->statements),
|
||||
'nb_failed_statements' => 0,
|
||||
'accumulated_duration' => $this->accumulatedTime,
|
||||
'accumulated_duration_str' => $this->formatDuration($this->accumulatedTime),
|
||||
'peak_memory_usage' => $this->peakMemory,
|
||||
'peak_memory_usage_str' => $this->formatBytes($this->peakMemory),
|
||||
'statements' => $this->statements
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'propel';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
"propel" => array(
|
||||
"icon" => "bolt",
|
||||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
|
||||
"map" => "propel",
|
||||
"default" => "[]"
|
||||
),
|
||||
"propel:badge" => array(
|
||||
"map" => "propel.nb_statements",
|
||||
"default" => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAssets()
|
||||
{
|
||||
return array(
|
||||
'css' => 'widgets/sqlqueries/widget.css',
|
||||
'js' => 'widgets/sqlqueries/widget.js'
|
||||
);
|
||||
}
|
||||
}
|
||||
66
vendor/maximebf/debugbar/src/DebugBar/Bridge/SlimCollector.php
vendored
Normal file
66
vendor/maximebf/debugbar/src/DebugBar/Bridge/SlimCollector.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge;
|
||||
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use Psr\Log\LogLevel;
|
||||
use Slim\Log;
|
||||
use Slim\Slim;
|
||||
|
||||
/**
|
||||
* Collects messages from a Slim logger
|
||||
*
|
||||
* http://slimframework.com
|
||||
*/
|
||||
class SlimCollector extends MessagesCollector
|
||||
{
|
||||
protected $slim;
|
||||
|
||||
protected $originalLogWriter;
|
||||
|
||||
public function __construct(Slim $slim)
|
||||
{
|
||||
$this->slim = $slim;
|
||||
if ($log = $slim->getLog()) {
|
||||
$this->originalLogWriter = $log->getWriter();
|
||||
$log->setWriter($this);
|
||||
$log->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function write($message, $level)
|
||||
{
|
||||
if ($this->originalLogWriter) {
|
||||
$this->originalLogWriter->write($message, $level);
|
||||
}
|
||||
$this->addMessage($message, $this->getLevelName($level));
|
||||
}
|
||||
|
||||
protected function getLevelName($level)
|
||||
{
|
||||
$map = array(
|
||||
Log::EMERGENCY => LogLevel::EMERGENCY,
|
||||
Log::ALERT => LogLevel::ALERT,
|
||||
Log::CRITICAL => LogLevel::CRITICAL,
|
||||
Log::ERROR => LogLevel::ERROR,
|
||||
Log::WARN => LogLevel::WARNING,
|
||||
Log::NOTICE => LogLevel::NOTICE,
|
||||
Log::INFO => LogLevel::INFO,
|
||||
Log::DEBUG => LogLevel::DEBUG
|
||||
);
|
||||
return $map[$level];
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'slim';
|
||||
}
|
||||
}
|
||||
44
vendor/maximebf/debugbar/src/DebugBar/Bridge/SwiftMailer/SwiftLogCollector.php
vendored
Normal file
44
vendor/maximebf/debugbar/src/DebugBar/Bridge/SwiftMailer/SwiftLogCollector.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge\SwiftMailer;
|
||||
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use Swift_Mailer;
|
||||
use Swift_Plugins_Logger;
|
||||
use Swift_Plugins_LoggerPlugin;
|
||||
|
||||
/**
|
||||
* Collects log messages
|
||||
*
|
||||
* http://swiftmailer.org/
|
||||
*/
|
||||
class SwiftLogCollector extends MessagesCollector implements Swift_Plugins_Logger
|
||||
{
|
||||
public function __construct(Swift_Mailer $mailer)
|
||||
{
|
||||
$mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this));
|
||||
}
|
||||
|
||||
public function add($entry)
|
||||
{
|
||||
$this->addMessage($entry);
|
||||
}
|
||||
|
||||
public function dump()
|
||||
{
|
||||
return implode(PHP_EOL, $this->_log);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'swiftmailer_logs';
|
||||
}
|
||||
}
|
||||
92
vendor/maximebf/debugbar/src/DebugBar/Bridge/SwiftMailer/SwiftMailCollector.php
vendored
Normal file
92
vendor/maximebf/debugbar/src/DebugBar/Bridge/SwiftMailer/SwiftMailCollector.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge\SwiftMailer;
|
||||
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Swift_Mailer;
|
||||
use Swift_Plugins_MessageLogger;
|
||||
|
||||
/**
|
||||
* Collects data about sent mails
|
||||
*
|
||||
* http://swiftmailer.org/
|
||||
*/
|
||||
class SwiftMailCollector extends DataCollector implements Renderable, AssetProvider
|
||||
{
|
||||
protected $messagesLogger;
|
||||
|
||||
public function __construct(Swift_Mailer $mailer)
|
||||
{
|
||||
$this->messagesLogger = new Swift_Plugins_MessageLogger();
|
||||
$mailer->registerPlugin($this->messagesLogger);
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
$mails = array();
|
||||
foreach ($this->messagesLogger->getMessages() as $msg) {
|
||||
$mails[] = array(
|
||||
'to' => $this->formatTo($msg->getTo()),
|
||||
'subject' => $msg->getSubject(),
|
||||
'headers' => $msg->getHeaders()->toString()
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'count' => count($mails),
|
||||
'mails' => $mails
|
||||
);
|
||||
}
|
||||
|
||||
protected function formatTo($to)
|
||||
{
|
||||
if (!$to) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$f = array();
|
||||
foreach ($to as $k => $v) {
|
||||
$f[] = (empty($v) ? '' : "$v ") . "<$k>";
|
||||
}
|
||||
return implode(', ', $f);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'swiftmailer_mails';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
'emails' => array(
|
||||
'icon' => 'inbox',
|
||||
'widget' => 'PhpDebugBar.Widgets.MailsWidget',
|
||||
'map' => 'swiftmailer_mails.mails',
|
||||
'default' => '[]',
|
||||
'title' => 'Mails'
|
||||
),
|
||||
'emails:badge' => array(
|
||||
'map' => 'swiftmailer_mails.count',
|
||||
'default' => 'null'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAssets()
|
||||
{
|
||||
return array(
|
||||
'css' => 'widgets/mails/widget.css',
|
||||
'js' => 'widgets/mails/widget.js'
|
||||
);
|
||||
}
|
||||
}
|
||||
417
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigEnvironment.php
vendored
Normal file
417
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigEnvironment.php
vendored
Normal file
@@ -0,0 +1,417 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge\Twig;
|
||||
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use Twig_CompilerInterface;
|
||||
use Twig_Environment;
|
||||
use Twig_ExtensionInterface;
|
||||
use Twig_LexerInterface;
|
||||
use Twig_LoaderInterface;
|
||||
use Twig_NodeInterface;
|
||||
use Twig_NodeVisitorInterface;
|
||||
use Twig_ParserInterface;
|
||||
use Twig_TokenParserInterface;
|
||||
use Twig_TokenStream;
|
||||
|
||||
/**
|
||||
* Wrapped a Twig Environment to provide profiling features
|
||||
*/
|
||||
class TraceableTwigEnvironment extends Twig_Environment
|
||||
{
|
||||
protected $twig;
|
||||
|
||||
protected $renderedTemplates = array();
|
||||
|
||||
protected $timeDataCollector;
|
||||
|
||||
/**
|
||||
* @param Twig_Environment $twig
|
||||
* @param TimeDataCollector $timeDataCollector
|
||||
*/
|
||||
public function __construct(Twig_Environment $twig, TimeDataCollector $timeDataCollector = null)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
$this->timeDataCollector = $timeDataCollector;
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return call_user_func_array(array($this->twig, $name), $arguments);
|
||||
}
|
||||
|
||||
public function getRenderedTemplates()
|
||||
{
|
||||
return $this->renderedTemplates;
|
||||
}
|
||||
|
||||
public function addRenderedTemplate(array $info)
|
||||
{
|
||||
$this->renderedTemplates[] = $info;
|
||||
}
|
||||
|
||||
public function getTimeDataCollector()
|
||||
{
|
||||
return $this->timeDataCollector;
|
||||
}
|
||||
|
||||
public function getBaseTemplateClass()
|
||||
{
|
||||
return $this->twig->getBaseTemplateClass();
|
||||
}
|
||||
|
||||
public function setBaseTemplateClass($class)
|
||||
{
|
||||
$this->twig->setBaseTemplateClass($class);
|
||||
}
|
||||
|
||||
public function enableDebug()
|
||||
{
|
||||
$this->twig->enableDebug();
|
||||
}
|
||||
|
||||
public function disableDebug()
|
||||
{
|
||||
$this->twig->disableDebug();
|
||||
}
|
||||
|
||||
public function isDebug()
|
||||
{
|
||||
return $this->twig->isDebug();
|
||||
}
|
||||
|
||||
public function enableAutoReload()
|
||||
{
|
||||
$this->twig->enableAutoReload();
|
||||
}
|
||||
|
||||
public function disableAutoReload()
|
||||
{
|
||||
$this->twig->disableAutoReload();
|
||||
}
|
||||
|
||||
public function isAutoReload()
|
||||
{
|
||||
return $this->twig->isAutoReload();
|
||||
}
|
||||
|
||||
public function enableStrictVariables()
|
||||
{
|
||||
$this->twig->enableStrictVariables();
|
||||
}
|
||||
|
||||
public function disableStrictVariables()
|
||||
{
|
||||
$this->twig->disableStrictVariables();
|
||||
}
|
||||
|
||||
public function isStrictVariables()
|
||||
{
|
||||
return $this->twig->isStrictVariables();
|
||||
}
|
||||
|
||||
public function getCache($original = true)
|
||||
{
|
||||
return $this->twig->getCache($original);
|
||||
}
|
||||
|
||||
public function setCache($cache)
|
||||
{
|
||||
$this->twig->setCache($cache);
|
||||
}
|
||||
|
||||
public function getCacheFilename($name)
|
||||
{
|
||||
return $this->twig->getCacheFilename($name);
|
||||
}
|
||||
|
||||
public function getTemplateClass($name, $index = null)
|
||||
{
|
||||
return $this->twig->getTemplateClass($name, $index);
|
||||
}
|
||||
|
||||
public function getTemplateClassPrefix()
|
||||
{
|
||||
return $this->twig->getTemplateClassPrefix();
|
||||
}
|
||||
|
||||
public function render($name, array $context = array())
|
||||
{
|
||||
return $this->loadTemplate($name)->render($context);
|
||||
}
|
||||
|
||||
public function display($name, array $context = array())
|
||||
{
|
||||
$this->loadTemplate($name)->display($context);
|
||||
}
|
||||
|
||||
public function loadTemplate($name, $index = null)
|
||||
{
|
||||
$cls = $this->twig->getTemplateClass($name, $index);
|
||||
|
||||
if (isset($this->twig->loadedTemplates[$cls])) {
|
||||
return $this->twig->loadedTemplates[$cls];
|
||||
}
|
||||
|
||||
if (!class_exists($cls, false)) {
|
||||
if (false === $cache = $this->getCacheFilename($name)) {
|
||||
eval('?>'.$this->compileSource($this->getLoader()->getSource($name), $name));
|
||||
} else {
|
||||
if (!is_file($cache) || ($this->isAutoReload() && !$this->isTemplateFresh($name, filemtime($cache)))) {
|
||||
$this->writeCacheFile($cache, $this->compileSource($this->getLoader()->getSource($name), $name));
|
||||
}
|
||||
|
||||
require_once $cache;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->twig->runtimeInitialized) {
|
||||
$this->initRuntime();
|
||||
}
|
||||
|
||||
return $this->twig->loadedTemplates[$cls] = new TraceableTwigTemplate($this, new $cls($this));
|
||||
}
|
||||
|
||||
public function isTemplateFresh($name, $time)
|
||||
{
|
||||
return $this->twig->isTemplateFresh($name, $time);
|
||||
}
|
||||
|
||||
public function resolveTemplate($names)
|
||||
{
|
||||
return $this->twig->resolveTemplate($names);
|
||||
}
|
||||
|
||||
public function clearTemplateCache()
|
||||
{
|
||||
$this->twig->clearTemplateCache();
|
||||
}
|
||||
|
||||
public function clearCacheFiles()
|
||||
{
|
||||
$this->twig->clearCacheFiles();
|
||||
}
|
||||
|
||||
public function getLexer()
|
||||
{
|
||||
return $this->twig->getLexer();
|
||||
}
|
||||
|
||||
public function setLexer(Twig_LexerInterface $lexer)
|
||||
{
|
||||
$this->twig->setLexer($lexer);
|
||||
}
|
||||
|
||||
public function tokenize($source, $name = null)
|
||||
{
|
||||
return $this->twig->tokenize($source, $name);
|
||||
}
|
||||
|
||||
public function getParser()
|
||||
{
|
||||
return $this->twig->getParser();
|
||||
}
|
||||
|
||||
public function setParser(Twig_ParserInterface $parser)
|
||||
{
|
||||
$this->twig->setParser($parser);
|
||||
}
|
||||
|
||||
public function parse(Twig_TokenStream $tokens)
|
||||
{
|
||||
return $this->twig->parse($tokens);
|
||||
}
|
||||
|
||||
public function getCompiler()
|
||||
{
|
||||
return $this->twig->getCompiler();
|
||||
}
|
||||
|
||||
public function setCompiler(Twig_CompilerInterface $compiler)
|
||||
{
|
||||
$this->twig->setCompiler($compiler);
|
||||
}
|
||||
|
||||
public function compile(Twig_NodeInterface $node)
|
||||
{
|
||||
return $this->twig->compile($node);
|
||||
}
|
||||
|
||||
public function compileSource($source, $name = null)
|
||||
{
|
||||
return $this->twig->compileSource($source, $name);
|
||||
}
|
||||
|
||||
public function setLoader(Twig_LoaderInterface $loader)
|
||||
{
|
||||
$this->twig->setLoader($loader);
|
||||
}
|
||||
|
||||
public function getLoader()
|
||||
{
|
||||
return $this->twig->getLoader();
|
||||
}
|
||||
|
||||
public function setCharset($charset)
|
||||
{
|
||||
$this->twig->setCharset($charset);
|
||||
}
|
||||
|
||||
public function getCharset()
|
||||
{
|
||||
return $this->twig->getCharset();
|
||||
}
|
||||
|
||||
public function initRuntime()
|
||||
{
|
||||
$this->twig->initRuntime();
|
||||
}
|
||||
|
||||
public function hasExtension($name)
|
||||
{
|
||||
return $this->twig->hasExtension($name);
|
||||
}
|
||||
|
||||
public function getExtension($name)
|
||||
{
|
||||
return $this->twig->getExtension($name);
|
||||
}
|
||||
|
||||
public function addExtension(Twig_ExtensionInterface $extension)
|
||||
{
|
||||
$this->twig->addExtension($extension);
|
||||
}
|
||||
|
||||
public function removeExtension($name)
|
||||
{
|
||||
$this->twig->removeExtension($name);
|
||||
}
|
||||
|
||||
public function setExtensions(array $extensions)
|
||||
{
|
||||
$this->twig->setExtensions($extensions);
|
||||
}
|
||||
|
||||
public function getExtensions()
|
||||
{
|
||||
return $this->twig->getExtensions();
|
||||
}
|
||||
|
||||
public function addTokenParser(Twig_TokenParserInterface $parser)
|
||||
{
|
||||
$this->twig->addTokenParser($parser);
|
||||
}
|
||||
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return $this->twig->getTokenParsers();
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
return $this->twig->getTags();
|
||||
}
|
||||
|
||||
public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
|
||||
{
|
||||
$this->twig->addNodeVisitor($visitor);
|
||||
}
|
||||
|
||||
public function getNodeVisitors()
|
||||
{
|
||||
return $this->twig->getNodeVisitors();
|
||||
}
|
||||
|
||||
public function addFilter($name, $filter = null)
|
||||
{
|
||||
$this->twig->addFilter($name, $filter);
|
||||
}
|
||||
|
||||
public function getFilter($name)
|
||||
{
|
||||
return $this->twig->getFilter($name);
|
||||
}
|
||||
|
||||
public function registerUndefinedFilterCallback($callable)
|
||||
{
|
||||
$this->twig->registerUndefinedFilterCallback($callable);
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->twig->getFilters();
|
||||
}
|
||||
|
||||
public function addTest($name, $test = null)
|
||||
{
|
||||
$this->twig->addTest($name, $test);
|
||||
}
|
||||
|
||||
public function getTests()
|
||||
{
|
||||
return $this->twig->getTests();
|
||||
}
|
||||
|
||||
public function getTest($name)
|
||||
{
|
||||
return $this->twig->getTest($name);
|
||||
}
|
||||
|
||||
public function addFunction($name, $function = null)
|
||||
{
|
||||
$this->twig->addFunction($name, $function);
|
||||
}
|
||||
|
||||
public function getFunction($name)
|
||||
{
|
||||
return $this->twig->getFunction($name);
|
||||
}
|
||||
|
||||
public function registerUndefinedFunctionCallback($callable)
|
||||
{
|
||||
$this->twig->registerUndefinedFunctionCallback($callable);
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return $this->twig->getFunctions();
|
||||
}
|
||||
|
||||
public function addGlobal($name, $value)
|
||||
{
|
||||
$this->twig->addGlobal($name, $value);
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
return $this->twig->getGlobals();
|
||||
}
|
||||
|
||||
public function mergeGlobals(array $context)
|
||||
{
|
||||
return $this->twig->mergeGlobals($context);
|
||||
}
|
||||
|
||||
public function getUnaryOperators()
|
||||
{
|
||||
return $this->twig->getUnaryOperators();
|
||||
}
|
||||
|
||||
public function getBinaryOperators()
|
||||
{
|
||||
return $this->twig->getBinaryOperators();
|
||||
}
|
||||
|
||||
public function computeAlternatives($name, $items)
|
||||
{
|
||||
return $this->twig->computeAlternatives($name, $items);
|
||||
}
|
||||
}
|
||||
131
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigTemplate.php
vendored
Normal file
131
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigTemplate.php
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge\Twig;
|
||||
|
||||
use Twig_Template;
|
||||
use Twig_TemplateInterface;
|
||||
|
||||
/**
|
||||
* Wraps a Twig_Template to add profiling features
|
||||
*/
|
||||
class TraceableTwigTemplate implements Twig_TemplateInterface
|
||||
{
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @param TraceableTwigEnvironment $env
|
||||
* @param Twig_Template $template
|
||||
*/
|
||||
public function __construct(TraceableTwigEnvironment $env, Twig_Template $template)
|
||||
{
|
||||
$this->env = $env;
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
return call_user_func_array(array($this->template, $name), $arguments);
|
||||
}
|
||||
|
||||
public function getTemplateName()
|
||||
{
|
||||
return $this->template->getTemplateName();
|
||||
}
|
||||
|
||||
public function getEnvironment()
|
||||
{
|
||||
return $this->template->getEnvironment();
|
||||
}
|
||||
|
||||
public function getParent(array $context)
|
||||
{
|
||||
return $this->template->getParent($context);
|
||||
}
|
||||
|
||||
public function isTraitable()
|
||||
{
|
||||
return $this->template->isTraitable();
|
||||
}
|
||||
|
||||
public function displayParentBlock($name, array $context, array $blocks = array())
|
||||
{
|
||||
$this->template->displayParentBlock($name, $context, $blocks);
|
||||
}
|
||||
|
||||
public function displayBlock($name, array $context, array $blocks = array(), $useBlocks = true)
|
||||
{
|
||||
$this->template->displayBlock($name, $context, $blocks, $useBlocks);
|
||||
}
|
||||
|
||||
public function renderParentBlock($name, array $context, array $blocks = array())
|
||||
{
|
||||
return $this->template->renderParentBlock($name, $context, $blocks);
|
||||
}
|
||||
|
||||
public function renderBlock($name, array $context, array $blocks = array(), $useBlocks = true)
|
||||
{
|
||||
return $this->template->renderBlock($name, $context, $blocks, $useBlocks);
|
||||
}
|
||||
|
||||
public function hasBlock($name)
|
||||
{
|
||||
return $this->template->hasBlock($name);
|
||||
}
|
||||
|
||||
public function getBlockNames()
|
||||
{
|
||||
return $this->template->getBlockNames();
|
||||
}
|
||||
|
||||
public function getBlocks()
|
||||
{
|
||||
return $this->template->getBlocks();
|
||||
}
|
||||
|
||||
public function display(array $context, array $blocks = array())
|
||||
{
|
||||
$start = microtime(true);
|
||||
$this->template->display($context, $blocks);
|
||||
$end = microtime(true);
|
||||
|
||||
if ($timeDataCollector = $this->env->getTimeDataCollector()) {
|
||||
$name = sprintf("twig.render(%s)", $this->template->getTemplateName());
|
||||
$timeDataCollector->addMeasure($name, $start, $end);
|
||||
}
|
||||
|
||||
$this->env->addRenderedTemplate(array(
|
||||
'name' => $this->template->getTemplateName(),
|
||||
'render_time' => $end - $start
|
||||
));
|
||||
}
|
||||
|
||||
public function render(array $context)
|
||||
{
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
try {
|
||||
$this->display($context);
|
||||
} catch (Exception $e) {
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function clearCache()
|
||||
{
|
||||
Twig_Template::clearCache();
|
||||
}
|
||||
}
|
||||
87
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TwigCollector.php
vendored
Normal file
87
vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TwigCollector.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the DebugBar package.
|
||||
*
|
||||
* (c) 2013 Maxime Bouroumeau-Fuseau
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace DebugBar\Bridge\Twig;
|
||||
|
||||
use DebugBar\DataCollector\AssetProvider;
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
|
||||
/**
|
||||
* Collects data about rendered templates
|
||||
*
|
||||
* http://twig.sensiolabs.org/
|
||||
*
|
||||
* Your Twig_Environment object needs to be wrapped in a
|
||||
* TraceableTwigEnvironment object
|
||||
*
|
||||
* <code>
|
||||
* $env = new TraceableTwigEnvironment(new Twig_Environment($loader));
|
||||
* $debugbar->addCollector(new TwigCollector($env));
|
||||
* </code>
|
||||
*/
|
||||
class TwigCollector extends DataCollector implements Renderable, AssetProvider
|
||||
{
|
||||
public function __construct(TraceableTwigEnvironment $twig)
|
||||
{
|
||||
$this->twig = $twig;
|
||||
}
|
||||
|
||||
public function collect()
|
||||
{
|
||||
$templates = array();
|
||||
$accuRenderTime = 0;
|
||||
|
||||
foreach ($this->twig->getRenderedTemplates() as $tpl) {
|
||||
$accuRenderTime += $tpl['render_time'];
|
||||
$templates[] = array(
|
||||
'name' => $tpl['name'],
|
||||
'render_time' => $tpl['render_time'],
|
||||
'render_time_str' => $this->formatDuration($tpl['render_time'])
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'nb_templates' => count($templates),
|
||||
'templates' => $templates,
|
||||
'accumulated_render_time' => $accuRenderTime,
|
||||
'accumulated_render_time_str' => $this->formatDuration($accuRenderTime)
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'twig';
|
||||
}
|
||||
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
'twig' => array(
|
||||
'icon' => 'leaf',
|
||||
'widget' => 'PhpDebugBar.Widgets.TemplatesWidget',
|
||||
'map' => 'twig',
|
||||
'default' => '[]'
|
||||
),
|
||||
'twig:badge' => array(
|
||||
'map' => 'twig.nb_templates',
|
||||
'default' => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getAssets()
|
||||
{
|
||||
return array(
|
||||
'css' => 'widgets/templates/widget.css',
|
||||
'js' => 'widgets/templates/widget.js'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user