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\Modules\Core;
|
|
|
|
|
|
|
|
use D3\DebugBar\Application\Component\DebugBarComponent;
|
2022-08-14 01:08:02 +02:00
|
|
|
use D3\DebugBar\Core\DebugBarExceptionHandler;
|
|
|
|
use DebugBar\DataCollector\ExceptionsCollector;
|
|
|
|
use ErrorException;
|
2022-08-03 09:12:45 +02:00
|
|
|
use OxidEsales\Eshop\Application\Controller\FrontendController;
|
2022-07-30 20:58:10 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
|
|
|
class ShopControl_DebugBar extends ShopControl_DebugBar_parent
|
|
|
|
{
|
2022-08-14 01:08:02 +02:00
|
|
|
/**
|
|
|
|
* @throws ErrorException
|
|
|
|
*/
|
2022-08-01 01:24:44 +02:00
|
|
|
public function __construct()
|
2022-07-30 20:58:10 +02:00
|
|
|
{
|
2022-08-14 01:08:02 +02:00
|
|
|
$this->d3DebugBarSetErrorHandler();;
|
|
|
|
$this->d3DebugBarSetExceptionHandler();
|
|
|
|
$this->d3AddDebugBarComponent();
|
2022-07-30 20:58:10 +02:00
|
|
|
|
2022-08-01 01:24:44 +02:00
|
|
|
parent::__construct();
|
2022-07-30 20:58:10 +02:00
|
|
|
}
|
|
|
|
|
2022-08-14 01:08:02 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
* @throws ErrorException
|
|
|
|
*/
|
|
|
|
public function d3DebugBarSetErrorHandler()
|
|
|
|
{
|
|
|
|
set_error_handler(function ($severity, $message, $file, $line) {
|
|
|
|
if (!(error_reporting() & $severity)) {
|
|
|
|
// This error code is not included in error_reporting.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$smartyTemplate = $this->getSmartyTemplateLocationFromError($message);
|
|
|
|
if (is_array($smartyTemplate)) {
|
|
|
|
[$file, $line] = $smartyTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ErrorException($message, 0, $severity, $file, $line);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function d3DebugBarSetExceptionHandler(): void
|
|
|
|
{
|
|
|
|
set_exception_handler([
|
|
|
|
new DebugBarExceptionHandler(),
|
|
|
|
'handleUncaughtException'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $messsage
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
protected function getSmartyTemplateLocationFromError($messsage)
|
|
|
|
{
|
|
|
|
if (stristr($messsage, 'Smarty error: [in ')) {
|
|
|
|
$start = strpos($messsage, '[')+1;
|
|
|
|
$end = strpos($messsage, ']');
|
|
|
|
$parts = explode(' ', substr($messsage, $start, $end - $start));
|
|
|
|
return [Registry::getConfig()->getTemplateDir(isAdmin()).$parts[1], (int) $parts[3]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-07-30 20:58:10 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-08-14 01:08:02 +02:00
|
|
|
protected function d3AddDebugBarComponent(): void
|
2022-07-30 20:58:10 +02:00
|
|
|
{
|
|
|
|
$userComponentNames = Registry::getConfig()->getConfigParam('aUserComponentNames');
|
|
|
|
$d3CmpName = DebugBarComponent::class;
|
|
|
|
$blDontUseCache = 1;
|
|
|
|
|
|
|
|
if (!is_array($userComponentNames)) {
|
|
|
|
$userComponentNames = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($d3CmpName, array_keys($userComponentNames))) {
|
|
|
|
$userComponentNames[$d3CmpName] = $blDontUseCache;
|
|
|
|
Registry::getConfig()->setConfigParam('aUserComponentNames', $userComponentNames);
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 01:24:44 +02:00
|
|
|
|
|
|
|
public function __destruct()
|
|
|
|
{
|
2022-08-14 01:08:02 +02:00
|
|
|
global $debugBarSet;
|
|
|
|
if (!isAdmin() && $debugBarSet !== 1) {
|
2022-08-03 00:32:09 +02:00
|
|
|
$activeView = Registry::getConfig()->getTopActiveView();
|
2022-08-03 09:12:45 +02:00
|
|
|
/** @var DebugBarComponent|null $debugBarComponent */
|
|
|
|
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
|
|
|
|
if ($debugBarComponent) {
|
2022-08-02 09:15:02 +02:00
|
|
|
echo $debugBarComponent->getRenderer()->renderHead();
|
|
|
|
$debugBarComponent->addTimelineMessures();
|
|
|
|
echo $debugBarComponent->getRenderer()->render();
|
|
|
|
}
|
2022-08-01 01:24:44 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-01 22:27:28 +02:00
|
|
|
}
|