DebugBar/Application/Models/DebugBarHandler.php

90 lines
2.3 KiB
PHP
Raw Normal View History

<?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\Models;
use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Core\DebugBarErrorHandler;
use D3\DebugBar\Core\DebugBarExceptionHandler;
use OxidEsales\Eshop\Core\Registry;
class DebugBarHandler
{
/**
* @return void
*/
public function setErrorHandler(): void
{
if ($this->d3CanActivateDebugBar()) {
2022-08-16 11:08:53 +02:00
/** @var callable $callable */
$callable = [
new DebugBarErrorHandler(),
'callback',
];
set_error_handler($callable, $this->getHandledErrorTypes());
}
}
/**
* @return int
*/
protected function getHandledErrorTypes(): int
{
return E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_PARSE;
}
/**
* @return void
*/
public function setExceptionHandler(): void
{
if ($this->d3CanActivateDebugBar()) {
2022-08-16 11:08:53 +02:00
set_exception_handler([
new DebugBarExceptionHandler(),
2022-08-16 11:08:53 +02:00
'handleUncaughtException',
]);
}
}
/**
* @return void
*/
public function addDebugBarComponent(): void
{
if ($this->d3CanActivateDebugBar()) {
2022-08-16 11:08:53 +02:00
$userComponentNames = Registry::getConfig()->getConfigParam('aUserComponentNames');
$d3CmpName = DebugBarComponent::class;
$blDontUseCache = 1;
2022-08-16 11:08:53 +02:00
if (! is_array($userComponentNames)) {
$userComponentNames = [];
}
2022-08-16 11:08:53 +02:00
if (! in_array($d3CmpName, array_keys($userComponentNames))) {
$userComponentNames[ $d3CmpName ] = $blDontUseCache;
2022-08-16 11:08:53 +02:00
Registry::getConfig()->setConfigParam('aUserComponentNames', $userComponentNames);
}
}
}
/**
* @return bool
*/
protected function d3CanActivateDebugBar(): bool
{
return false === isAdmin();
}
2022-08-16 11:08:53 +02:00
}