Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By Manuel Raynaud (92) and others
# Via Manuel Raynaud (28) and others
* 'master' of https://github.com/thelia/thelia: (212 commits)
  fix typo
  add some php doc
  integrate swiftMailer as mailer solution
  add swiftmailer in composer
  use dump autoloader in all compser scripts
  remove script part of composer.json file
  fix typo
  add some information for OSX requirements
  No alert bloc
  default country
  Autofocus on username field for better use
  Beautiful login page
  feed loop is now countable
  Change error page design
  Add validation button on form
  - Edit country view creation - Delete and edit modalbox creation - Countries routes management
  Completed template management
  fix faker
  fix faker script
  Working : Fixture : cleaning
  ...
This commit is contained in:
gmorel
2013-09-16 22:07:09 +02:00
638 changed files with 59830 additions and 12723 deletions

View File

@@ -30,7 +30,7 @@
<services>
<service id="debugBar" class="DebugBar\StandardDebugBar"/>
<service id="debugBar" class="DebugBar\DebugBar"/>
<service id="smarty.debugbar" class="DebugBar\Smarty\Plugin\DebugBar">
<argument type="service" id="debugBar"/>

View File

@@ -40,7 +40,9 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
protected $peakMemory = 0;
public function __construct()
protected $alternativeLogger;
public function __construct(LoggerInterface $alternativeLogger = null)
{
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setLogger('defaultLogger', $this);
@@ -54,6 +56,8 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
'commit',
'rollBack',
));
$this->alternativeLogger = $alternativeLogger;
}
/**
@@ -66,8 +70,8 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
return array(
'nb_statements' => count($this->statements),
'nb_failed_statements' => 0,
'accumulated_duration' => '10',
'accumulated_duration_str' => $this->formatDuration(1),
'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
@@ -115,14 +119,56 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function log($level, $message, array $context = array())
{
list($sql, $duration_str) = $this->parseAndLogSqlQuery($message);
$message = "$sql ($duration_str)";
if ($this->alternativeLogger) {
$this->alternativeLogger->log($level, $message);
}
}
/**
* Parse a log line to extract query information
*
* @param string $message
*/
protected function parseAndLogSqlQuery($message)
{
$parts = explode('|', $message, 3);
$duration = 0;
$memory = 0;
if (count($parts) > 1) {
$sql = trim($parts[2]);
if (preg_match('/([0-9]+\.[0-9]+)/', $parts[0], $matches)) {
$duration = (float) $matches[1];
}
if (preg_match('/([0-9]+\.[0-9]+)([A-Z]{1,2})/', $parts[1], $matches)) {
$memory = (float) $matches[1];
if ($matches[2] == 'KB') {
$memory *= 1024;
} else if ($matches[2] == 'MB') {
$memory *= 1024 * 1024;
}
}
} else {
$sql = $parts[0];
}
$this->statements[] = array(
'sql' => $message,
'sql' => $sql,
'is_success' => true,
'duration' => 0,
'duration_str' => $this->formatDuration(1),
'memory' => 1,
'memory_str' => $this->formatBytes(1)
'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));
}
/**
@@ -134,7 +180,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function emergency($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::EMERGENCY, $message, $context);
}
/**
@@ -149,7 +195,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function alert($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::ALERT, $message, $context);
}
/**
@@ -163,7 +209,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function critical($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::CRITICAL, $message, $context);
}
/**
@@ -176,7 +222,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function error($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::ERROR, $message, $context);
}
/**
@@ -191,7 +237,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function warning($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::WARNING, $message, $context);
}
/**
@@ -203,7 +249,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function notice($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::NOTICE, $message, $context);
}
/**
@@ -217,7 +263,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function info($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::INFO, $message, $context);
}
/**
@@ -229,7 +275,7 @@ class PropelCollector extends DataCollector implements Renderable, LoggerInterfa
*/
public function debug($message, array $context = array())
{
$this->log(null, $message, $context);
$this->log(\Thelia\Log\Tlog::DEBUG, $message, $context);
}

View File

@@ -22,7 +22,11 @@
/*************************************************************************************/
namespace DebugBar\Listeners;
use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DataCollector\PhpInfoCollector;
use DebugBar\DataCollector\PropelCollector;
use DebugBar\DataCollector\TimeDataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Thelia\Action\BaseAction;
@@ -40,7 +44,13 @@ class DebugBarListeners extends BaseAction implements EventSubscriberInterface {
{
$debugBar = $this->container->get("debugBar");
$debugBar->addCollector(new PropelCollector());
$debugBar->addCollector(new PhpInfoCollector());
//$debugBar->addCollector(new MessagesCollector());
//$debugBar->addCollector(new RequestDataCollector());
$debugBar->addCollector(new TimeDataCollector());
$debugBar->addCollector(new MemoryCollector());
$debugBar->addCollector(new PropelCollector(\Thelia\Log\Tlog::getInstance()));
}
/**

View File

@@ -26,6 +26,7 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
use Thelia\Core\Template\Smarty\an;
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
use DebugBar\DebugBar as BaseDebugBar;
use Thelia\Tools\URL;
/**
* Class DebugBar
@@ -52,20 +53,54 @@ class DebugBar extends AbstractSmartyPlugin
return $render;
}
public function renderHead($params, \Smarty_Internal_Template $template)
public function renderCss($params, \Smarty_Internal_Template $template)
{
$render = "";
if ($this->debugMode) {
$javascriptRenderer = $this->debugBar->getJavascriptRenderer();
$assets = $javascriptRenderer->getAsseticCollection();
if($this->debugMode)
{
$webFile = "cache/debugbar.css";
$cssFile = THELIA_WEB_DIR ."/".$webFile;
$cssCollection = $assets[0];
$jsCollection = $assets[1];
if(!file_exists($cssFile)) {
$javascriptRenderer = $this->debugBar->getJavascriptRenderer();
$assetCss = $javascriptRenderer->getAsseticCollection("css");
$render .= sprintf('<style media="screen" type="text/css">%s</style>', $cssCollection->dump());
$render .= sprintf('<script>%s</script>', $jsCollection->dump());
foreach($assetCss->all() as $asset) {
if(strpos($asset->getSourcePath(), "font-awesome") !== false) {
$assetCss->removeLeaf($asset);
}
}
file_put_contents($cssFile, $assetCss->dump());
}
$render = sprintf('<link rel="stylesheet" href="%s">', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE));
}
return $render;
}
public function renderJs($params, \Smarty_Internal_Template $template)
{
$render = "";
if($this->debugMode)
{
$webFile = "cache/debugbar.js";
$cacheFile = THELIA_WEB_DIR ."/".$webFile;
if (!file_exists($cacheFile)) {
$javascriptRenderer = $this->debugBar->getJavascriptRenderer();
$assetJs = $javascriptRenderer->getAsseticCollection("js");
foreach($assetJs->all() as $asset) {
if(strpos($asset->getSourcePath(), "jquery") !== false) {
$assetJs->removeLeaf($asset);
}
}
file_put_contents($cacheFile, $assetJs->dump());
}
$render = sprintf('<script src="%s"></script>', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE));
}
return $render;
}
@@ -75,8 +110,9 @@ class DebugBar extends AbstractSmartyPlugin
public function getPluginDescriptors()
{
return array(
new SmartyPluginDescriptor("function", "debugbar_renderHead", $this, "renderHead"),
new SmartyPluginDescriptor("function", "debugbar_render", $this, "render")
new SmartyPluginDescriptor("function", "debugbar_rendercss", $this, "renderCss"),
new SmartyPluginDescriptor("function", "debugbar_renderjs", $this, "renderJs"),
new SmartyPluginDescriptor("function", "debugbar_renderresult", $this, "render")
);
}
}