2022-07-30 20:58:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace D3\DebugBar\Application\Component;
|
|
|
|
|
2022-07-31 21:58:12 +02:00
|
|
|
use D3\DebugBar\Application\Models\Collectors\SmartyCollector;
|
2022-08-01 01:24:44 +02:00
|
|
|
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
|
2022-07-30 20:58:10 +02:00
|
|
|
use DebugBar\Bridge\DoctrineCollector;
|
|
|
|
use DebugBar\Bridge\MonologCollector;
|
|
|
|
use DebugBar\DebugBarException;
|
|
|
|
use DebugBar\JavascriptRenderer;
|
|
|
|
use DebugBar\StandardDebugBar;
|
|
|
|
use Doctrine\DBAL\Logging\DebugStack;
|
|
|
|
use OxidEsales\Eshop\Core\Controller\BaseController;
|
|
|
|
use OxidEsales\Eshop\Core\DatabaseProvider;
|
|
|
|
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
use ReflectionClass;
|
|
|
|
use ReflectionException;
|
|
|
|
|
|
|
|
class DebugBarComponent extends BaseController
|
|
|
|
{
|
2022-07-31 22:56:02 +02:00
|
|
|
/** @var StandardDebugBar */
|
2022-08-01 22:44:05 +02:00
|
|
|
protected $debugBar;
|
2022-07-30 20:58:10 +02:00
|
|
|
/** @var JavascriptRenderer */
|
2022-08-01 22:44:05 +02:00
|
|
|
protected $debugBarRenderer;
|
2022-07-30 20:58:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Marking object as component
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $_blIsComponent = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws DebugBarException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws ReflectionException
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
if (false === isAdmin()) {
|
|
|
|
$debugbar = new StandardDebugBar();
|
|
|
|
|
2022-07-31 21:58:12 +02:00
|
|
|
$this->addCollectors($debugbar);
|
2022-07-30 20:58:10 +02:00
|
|
|
|
|
|
|
$debugbarRenderer = $debugbar->getJavascriptRenderer();
|
|
|
|
$debugbarRenderer->setBaseUrl(Registry::getConfig()->getOutUrl() . 'debugbar');
|
2022-07-31 22:56:02 +02:00
|
|
|
$this->debugBar = $debugbar;
|
2022-07-30 20:58:10 +02:00
|
|
|
$this->debugBarRenderer = $debugbarRenderer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return MonologCollector
|
|
|
|
* @throws ReflectionException
|
|
|
|
*/
|
|
|
|
public function getMonologCollector(): MonologCollector
|
|
|
|
{
|
|
|
|
$loggerWrapper = Registry::getLogger();
|
|
|
|
$monolog = $this->getNonPublicProperty($loggerWrapper, 'logger');
|
|
|
|
return new MonologCollector($monolog);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DoctrineCollector
|
|
|
|
* @throws ReflectionException
|
|
|
|
* @throws DebugBarException
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
*/
|
|
|
|
public function getDoctrineCollector(): DoctrineCollector
|
|
|
|
{
|
|
|
|
$db = DatabaseProvider::getDb();
|
|
|
|
$debugStack = new DebugStack();
|
|
|
|
$connection = $this->getNonPublicProperty($db, 'connection');
|
|
|
|
$connection->getConfiguration()->setSQLLogger($debugStack);
|
|
|
|
return new DoctrineCollector($debugStack);
|
|
|
|
}
|
|
|
|
|
2022-07-31 21:58:12 +02:00
|
|
|
/**
|
|
|
|
* @return SmartyCollector
|
|
|
|
*/
|
|
|
|
public function getSmartyCollector(): SmartyCollector
|
|
|
|
{
|
|
|
|
return new SmartyCollector(Registry::getUtilsView()->getSmarty());
|
|
|
|
}
|
|
|
|
|
2022-07-30 20:58:10 +02:00
|
|
|
/**
|
|
|
|
* @param $object
|
|
|
|
* @param $propName
|
|
|
|
* @return mixed
|
|
|
|
* @throws ReflectionException
|
|
|
|
*/
|
|
|
|
protected function getNonPublicProperty($object, $propName)
|
|
|
|
{
|
|
|
|
$reflection = new ReflectionClass($object);
|
|
|
|
$property = $reflection->getProperty($propName);
|
|
|
|
$property->setAccessible(true);
|
|
|
|
return $property->getValue($object);
|
|
|
|
}
|
2022-07-31 21:58:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param StandardDebugBar $debugbar
|
|
|
|
* @return void
|
|
|
|
* @throws DatabaseConnectionException
|
|
|
|
* @throws DebugBarException
|
|
|
|
* @throws ReflectionException
|
|
|
|
*/
|
|
|
|
public function addCollectors(StandardDebugBar $debugbar): void
|
|
|
|
{
|
|
|
|
$debugbar->addCollector($this->getMonologCollector());
|
|
|
|
$debugbar->addCollector($this->getDoctrineCollector());
|
|
|
|
$debugbar->addCollector($this->getSmartyCollector());
|
|
|
|
}
|
2022-07-31 22:56:02 +02:00
|
|
|
|
2022-08-01 01:24:44 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addTimelineMessures(): void
|
2022-07-31 22:56:02 +02:00
|
|
|
{
|
2022-08-01 01:24:44 +02:00
|
|
|
$collectors = $this->debugBar->getCollectors();
|
|
|
|
$collectors['time'] = TimeDataCollectorHandler::getInstance();
|
|
|
|
|
|
|
|
$reflection = new ReflectionClass($this->debugBar);
|
|
|
|
$property = $reflection->getProperty('collectors');
|
|
|
|
$property->setAccessible(true);
|
|
|
|
$property->setValue($this->debugBar, $collectors);
|
2022-07-31 22:56:02 +02:00
|
|
|
}
|
2022-08-01 01:24:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return JavascriptRenderer
|
|
|
|
*/
|
|
|
|
public function getRenderer(): JavascriptRenderer
|
2022-07-31 22:56:02 +02:00
|
|
|
{
|
2022-08-01 01:24:44 +02:00
|
|
|
return $this->debugBarRenderer;
|
2022-07-31 22:56:02 +02:00
|
|
|
}
|
2022-08-01 22:27:28 +02:00
|
|
|
}
|