diff --git a/local/modules/DebugBar/Config/config.xml b/local/modules/DebugBar/Config/config.xml new file mode 100644 index 000000000..6713c8ce6 --- /dev/null +++ b/local/modules/DebugBar/Config/config.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + %kernel.debug% + + + + + + + + + + + diff --git a/local/modules/DebugBar/Config/plugin.xml b/local/modules/DebugBar/Config/plugin.xml new file mode 100644 index 000000000..e69de29bb diff --git a/local/modules/DebugBar/Config/schema.xml b/local/modules/DebugBar/Config/schema.xml new file mode 100644 index 000000000..86ccca913 --- /dev/null +++ b/local/modules/DebugBar/Config/schema.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/local/modules/DebugBar/DebugBar.php b/local/modules/DebugBar/DebugBar.php new file mode 100644 index 000000000..7dde5fa8d --- /dev/null +++ b/local/modules/DebugBar/DebugBar.php @@ -0,0 +1,44 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace DebugBar; + +use Thelia\Module\BaseModule; + +class DebugBar extends BaseModule +{ + /** + * YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class + * Like install and destroy + */ + + public function install() + { + // TODO: Implement install() method. + } + + public function destroy() + { + // TODO: Implement destroy() method. + } +} diff --git a/local/modules/DebugBar/Listeners/DebugBarListeners.php b/local/modules/DebugBar/Listeners/DebugBarListeners.php new file mode 100644 index 000000000..2c2a1a08c --- /dev/null +++ b/local/modules/DebugBar/Listeners/DebugBarListeners.php @@ -0,0 +1,78 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace DebugBar\Listeners; +use DebugBar\DataCollector\PDO\PDOCollector; +use DebugBar\DataCollector\PDO\TraceablePDO; +use Propel\Runtime\Propel; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; +use Thelia\Action\BaseAction; +use Thelia\Core\Event\TheliaEvents; + + +/** + * Class DebugBarListeners + * @package DebugBar\Listeners + * @author Manuel Raynaud + */ +class DebugBarListeners extends BaseAction implements EventSubscriberInterface { + + public function initDebugBar() + { + $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)); + } + + /** + * Returns an array of event names this subscriber wants to listen to. + * + * The array keys are event names and the value can be: + * + * * The method name to call (priority defaults to 0) + * * An array composed of the method name to call and the priority + * * An array of arrays composed of the method names to call and respective + * priorities, or 0 if unset + * + * For instance: + * + * * array('eventName' => 'methodName') + * * array('eventName' => array('methodName', $priority)) + * * array('eventName' => array(array('methodName1', $priority), array('methodName2')) + * + * @return array The event names to listen to + * + * @api + */ + public static function getSubscribedEvents() + { + return array( + TheliaEvents::BOOT => array("initDebugBar", 128) + ); + } +} \ No newline at end of file diff --git a/local/modules/DebugBar/Smarty/Plugin/DebugBar.php b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php new file mode 100644 index 000000000..9a333b1d6 --- /dev/null +++ b/local/modules/DebugBar/Smarty/Plugin/DebugBar.php @@ -0,0 +1,82 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace DebugBar\Smarty\Plugin; +use Thelia\Core\Template\Smarty\AbstractSmartyPlugin; +use Thelia\Core\Template\Smarty\an; +use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; +use DebugBar\DebugBar as BaseDebugBar; + +/** + * Class DebugBar + * @author Manuel Raynaud + */ +class DebugBar extends AbstractSmartyPlugin +{ + protected $debugBar; + protected $debugMode; + + public function __construct(BaseDebugBar $debugbar, $debugMode) + { + $this->debugBar = $debugbar; + $this->debugMode = $debugMode; + } + + public function render($params, \Smarty_Internal_Template $template) + { + $render = ""; + if ($this->debugMode) { + $render = $this->debugBar->getJavascriptRenderer()->render(); + } + + return $render; + } + + public function renderHead($params, \Smarty_Internal_Template $template) + { + $render = ""; + if ($this->debugMode) { + $javascriptRenderer = $this->debugBar->getJavascriptRenderer(); + $assets = $javascriptRenderer->getAsseticCollection(); + + $cssCollection = $assets[0]; + $jsCollection = $assets[1]; + + $render .= sprintf('', $cssCollection->dump()); + $render .= sprintf('', $jsCollection->dump()); + } + + return $render; + } + + /** + * @return an array of SmartyPluginDescriptor + */ + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor("function", "debugbar_renderHead", $this, "renderHead"), + new SmartyPluginDescriptor("function", "debugbar_render", $this, "render") + ); + } +} \ No newline at end of file