8
0

Commits vergleichen

...

8 Commits

18 geänderte Dateien mit 242 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -15,10 +15,12 @@ declare(strict_types=1);
namespace D3\DebugBar\Application\Component;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\Collectors\OxidConfigCollector;
use D3\DebugBar\Application\Models\Collectors\OxidShopCollector;
use D3\DebugBar\Application\Models\Collectors\OxidVersionCollector;
use D3\DebugBar\Application\Models\Collectors\SmartyCollector;
use D3\DebugBar\Application\Models\Exceptions\UnavailableException;
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
use DebugBar\Bridge\DoctrineCollector;
use DebugBar\Bridge\MonologCollector;
@ -43,8 +45,8 @@ use ReflectionException;
class DebugBarComponent extends BaseController
{
/** @var DebugBar */
protected $debugBar;
/** @var DebugBar|null */
protected $debugBar = null;
/** @var JavascriptRenderer */
protected $debugBarRenderer;
@ -63,7 +65,7 @@ class DebugBarComponent extends BaseController
{
parent::__construct();
if (false === isAdmin()) {
if (AvailabilityCheck::isAvailable()) {
$debugbar = new DebugBar();
$this->addCollectors($debugbar);
@ -180,6 +182,10 @@ class DebugBarComponent extends BaseController
*/
public function addTimelineMessures(): void
{
if (false === $this->debugBar instanceof DebugBar) {
throw new UnavailableException();
}
$collectors = $this->debugBar->getCollectors();
$collectors['time'] = TimeDataCollectorHandler::getInstance();
@ -191,9 +197,14 @@ class DebugBarComponent extends BaseController
/**
* @return DebugBar
* @throws UnavailableException
*/
public function getDebugBar(): DebugBar
{
if (false === $this->debugBar instanceof DebugBar) {
throw new UnavailableException();
}
return $this->debugBar;
}

Datei anzeigen

@ -0,0 +1,83 @@
<?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 OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;
class AvailabilityCheck
{
/**
* @return bool
*/
public static function isAvailable(): bool
{
return !isAdmin() && (
Registry::getConfig()->getShopConfVar('d3debugbar_showForAdminUsersOnly') != true ||
self::userIsMallAdmin()
);
}
/**
* @return bool
*/
public static function userIsMallAdmin(): bool
{
$user = Registry::getConfig()->getUser();
return $user != null &&
$user->isMallAdmin();
}
/**
* @return bool
*/
public static function ifDebugBarNotSet(): bool
{
global $debugBarSet;
return $debugBarSet !== 1;
}
/**
* @return void
*/
public static function markDebugBarAsSet(): void
{
global $debugBarSet;
$debugBarSet = 1;
}
/**
* @return bool
*/
public static function ifNoErrorOccured(): bool
{
global $debugBarErrorOccured;
return $debugBarErrorOccured !== 1;
}
/**
* @return void
*/
public static function markErrorOccured(): void
{
global $debugBarErrorOccured;
$debugBarErrorOccured = 1;
}
}

Datei anzeigen

@ -27,7 +27,7 @@ class DebugBarHandler
*/
public function setErrorHandler(): void
{
if ($this->d3CanActivateDebugBar()) {
if (AvailabilityCheck::isAvailable()) {
/** @var callable $callable */
$callable = [
new DebugBarErrorHandler(),
@ -50,7 +50,7 @@ class DebugBarHandler
*/
public function setExceptionHandler(): void
{
if ($this->d3CanActivateDebugBar()) {
if (AvailabilityCheck::isAvailable()) {
set_exception_handler([
new DebugBarExceptionHandler(),
'handleUncaughtException',
@ -63,7 +63,7 @@ class DebugBarHandler
*/
public function addDebugBarComponent(): void
{
if ($this->d3CanActivateDebugBar()) {
if (AvailabilityCheck::isAvailable()) {
$userComponentNames = Registry::getConfig()->getConfigParam('aUserComponentNames');
$d3CmpName = DebugBarComponent::class;
$blDontUseCache = 1;
@ -78,12 +78,4 @@ class DebugBarHandler
}
}
}
/**
* @return bool
*/
protected function d3CanActivateDebugBar(): bool
{
return false === isAdmin();
}
}

Datei anzeigen

@ -0,0 +1,22 @@
<?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\Exceptions;
use OxidEsales\Eshop\Core\Exception\StandardException;
class UnavailableException extends StandardException
{
}

Datei anzeigen

@ -0,0 +1,26 @@
<?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);
$sLangName = "Deutsch";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = [
//Navigation
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_d3debugbar_general' => 'Grundeinstellungen',
'SHOP_MODULE_d3debugbar_showForAdminUsersOnly' => 'DebugBar nur anzeigen, wenn angemeldeter Benutzer ein Adminbenutzer ist',
];

Datei anzeigen

@ -0,0 +1,26 @@
<?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);
$sLangName = "English";
// -------------------------------
// RESOURCE IDENTITFIER = STRING
// -------------------------------
$aLang = [
//Navigation
'charset' => 'UTF-8',
'SHOP_MODULE_GROUP_d3debugbar_general' => 'Default settings',
'SHOP_MODULE_d3debugbar_showForAdminUsersOnly' => 'show DebugBar only if logged in user is an admin user',
];

Datei anzeigen

@ -4,7 +4,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.d3data.de/D3Public/DebugBar/compare/1.1.0.0...rel_1.x)
## [Unreleased](https://git.d3data.de/D3Public/DebugBar/compare/1.2.0.0...rel_1.x)
## [1.2.0.0](https://git.d3data.de/D3Public/DebugBar/compare/1.1.0.0...1.2.0.0) - 2023-01-03
### Added
- make installable in OXID 6.5.x (CE 6.12 + 6.13)
- collect unhandled exceptions, errors from Smarty and PHP
- show warning on activation if asset files doesn't exist
- catch all possible exceptions and errors
- add option to show DebugBar only if logged in user is an admin user
### Changed
- remove extra config item for current theme
- throw error exceptions on error levels only
- throw error type dependend exceptions
### Fixed
- fix not existing component issue in admin panels login controller
## [1.1.0.0](https://git.d3data.de/D3Public/DebugBar/compare/1.0.0.0...1.1.0.0) - 2022-08-05
### Added

Datei anzeigen

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\DebugBar\Core;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\Exceptions\CompileErrorException;
use D3\DebugBar\Application\Models\Exceptions\CoreErrorException;
use D3\DebugBar\Application\Models\Exceptions\ParseException;
@ -39,8 +40,7 @@ class DebugBarErrorHandler
*/
public function callback(int $severity, string $message, string $file, int $line)
{
global $debugBarErrorOccured;
$debugBarErrorOccured = 1;
AvailabilityCheck::markErrorOccured();
if (0 === error_reporting() || !(error_reporting() & $severity)) {
// This error code is not included in error_reporting.

Datei anzeigen

@ -16,6 +16,8 @@ declare(strict_types=1);
namespace D3\DebugBar\Core;
use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\Exceptions\UnavailableException;
use DebugBar\DataCollector\ExceptionsCollector;
use DebugBar\DebugBarException;
use OxidEsales\Eshop\Core\ConfigFile;
@ -42,7 +44,7 @@ class DebugBarExceptionHandler
$defaultExceptionHandler->writeExceptionToLog($exception);
} catch (Throwable $loggerException) {
/**
* Its not possible to get the logger from the DI container.
* It's not possible to get the logger from the DI container.
* Try again to log original exception (without DI container) in order to show the root cause of a problem.
*/
try {
@ -50,13 +52,11 @@ class DebugBarExceptionHandler
$logger = $loggerServiceFactory->getLogger();
$logger->error($exception->getTraceAsString());
} catch (Throwable $throwableWithoutPossibilityToWriteToLogFile) {
// It is not possible to log because e.g. the log file is not writable.
// It's not possible to log because e.g. the log file is not writable.
}
}
global $debugBarSet;
if ($debugBarSet !== 1 && false === isAdmin()) {
if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet()) {
try {
/** @var DebugBarComponent $debugBarComponent */
$debugBarComponent = oxNew(DebugBarComponent::class);
@ -77,13 +77,13 @@ HTML;
</head>
<body>
HTML;
$debugBarSet = 1;
AvailabilityCheck::markDebugBarAsSet();
echo $debugBarComponent->getRenderer()->render();
echo <<<HTML
</body>
</html>
HTML;
} catch (DebugBarException $e) {
} catch (DebugBarException|UnavailableException $e) {
Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
}

Datei anzeigen

@ -15,15 +15,21 @@ declare(strict_types=1);
namespace D3\DebugBar\Modules\Core;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Core\DebugBarExceptionHandler;
use OxidEsales\Eshop\Core\Exception\ExceptionHandler;
class Config_DebugBar extends Config_DebugBar_parent
{
/**
* @return DebugBarExceptionHandler
* @return DebugBarExceptionHandler|ExceptionHandler
*/
protected function getExceptionHandler()
{
return new DebugBarExceptionHandler();
if (AvailabilityCheck::isAvailable()) {
return new DebugBarExceptionHandler();
}
return parent::getExceptionHandler();
}
}

Datei anzeigen

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\DebugBar\Modules\Core;
use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\DebugBarHandler;
use D3\DebugBar\Core\DebugBarExceptionHandler;
use OxidEsales\Eshop\Core\Exception\StandardException;
@ -45,14 +46,14 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
{
parent::start();
global $debugBarSet, $debugBarErrorOccured;
if (!isAdmin() && $debugBarSet !== 1 && $debugBarErrorOccured !== 1) {
if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet() && AvailabilityCheck::ifNoErrorOccured()) {
$activeView = Registry::getConfig()->getTopActiveView();
/** @var DebugBarComponent|null $debugBarComponent */
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
$debugBarComponent = method_exists($activeView, 'getComponent')
? $activeView->getComponent(DebugBarComponent::class)
: null;
if ($debugBarComponent) {
$debugBarSet = 1;
AvailabilityCheck::markDebugBarAsSet();
echo $debugBarComponent->getRenderer()->renderHead();
$debugBarComponent->addTimelineMessures();
echo $debugBarComponent->getRenderer()->render();

Datei anzeigen

@ -14,6 +14,8 @@
declare(strict_types=1);
use D3\DebugBar\Application\Component\DebugBarComponent;
use D3\DebugBar\Application\Models\AvailabilityCheck;
use D3\DebugBar\Application\Models\Exceptions\UnavailableException;
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DebugBarException;
@ -60,7 +62,6 @@ function stopProfile(string $sProfileName): void
$timeDataCollector = TimeDataCollectorHandler::getInstance();
$timeDataCollector->stopMeasure($hash);
global $aStartTimes;
global $executionCounts;
if (!isset($executionCounts[$sProfileName])) {
@ -90,17 +91,25 @@ function debugVar($mVar, bool $blToFile = false): void
fclose($f);
}
} else {
if (!isAdmin()) {
try {
if (! AvailabilityCheck::isAvailable()) {
throw new UnavailableException();
}
$activeView = Registry::getConfig()->getTopActiveView();
/** @var DebugBarComponent $debugBarComponent */
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
/** @var DebugBarComponent|null $debugBarComponent */
$debugBarComponent = method_exists($activeView, 'getComponent')
? $activeView->getComponent(DebugBarComponent::class)
: null;
if ($debugBarComponent === null) {
throw new UnavailableException();
}
/** @var MessagesCollector $messages */
$messages = $debugBarComponent->getDebugBar()->getCollector('messages');
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
//$location = $trace[1]['class'] . '::' . $trace[1]['function']. '(' . $trace[0]['line'] . ')';
$location = $trace[1]['class'] . '::' . $trace[1]['function'];
$messages->addMessage($mVar, $location);
} else {
} catch (UnavailableException $e) {
dumpVar($mVar, $blToFile);
}
}

Datei anzeigen

@ -27,7 +27,7 @@ class Events
/** @var string $shopDir */
$shopDir = Registry::getConfig()->getConfigParam('sShopDir');
if (false === file_exists(
rtrim($shopDir, '/').'/out/debugbar/debugbar.jas'
rtrim($shopDir, '/').'/out/debugbar/debugbar.js'
)) {
Registry::getUtilsView()->addErrorToDisplay(
'The asset files cannot be found. Have you forgotten an installation step described in <a href="https://git.d3data.de/D3Public/DebugBar/src/branch/main/README.en.md">README</a>? Then please run the installation again.'.

Datei anzeigen

@ -3,4 +3,3 @@
- clear tpl cache button
- phpinfo() overview
- automatic switch between Smarty and Twig
- displayed in live shop when logged in as admin

Datei anzeigen

@ -1,6 +1,6 @@
{
"name": "d3/oxid-debugbar",
"description": "add the DegugBar to OXID eShop",
"description": "add the DebugBar to OXID eShop",
"type": "oxideshop-module",
"keywords": [
"oxid",
@ -26,7 +26,7 @@
],
"require": {
"php": ">=7.3",
"oxid-esales/oxideshop-ce": "6.8 - 6.10",
"oxid-esales/oxideshop-ce": "6.8 - 6.13",
"maximebf/debugbar": "^1.18",
"ajgl/composer-symlinker": "^0.3.1",
"cweagans/composer-patches": "^1.7.2"

Datei anzeigen

@ -33,7 +33,7 @@ $aModule = [
'de' => '',
'en' => '',
],
'version' => '1.0.0.0',
'version' => '1.2.0.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
@ -46,6 +46,13 @@ $aModule = [
'onActivate' => '\D3\DebugBar\Setup\Events::onActivate',
],
'templates' => [],
'settings' => [],
'settings' => [
[
'group' => $sModuleId.'_general',
'name' => $sModuleId.'_showForAdminUsersOnly',
'type' => 'bool',
'value' => false,
],
],
'blocks' => [],
];

Datei anzeigen

@ -12,6 +12,5 @@ parameters:
- '#Offset .* does not exist on array{function: .*}.#'
- '#ShopControl_DebugBar::_handle.*Exception\(\) has no return type specified#'
- '#ShopControl_DebugBar::start\(\) has no return type specified.#'
- '#Config_DebugBar::getExceptionHandler\(\) should be compatible with return type #'
- '#UtilsView::addErrorToDisplay\(\) expects OxidEsales\\Eshop\\Core\\Contract\\IDisplayError#'
- '#PHPDoc tag @throws with type .*\\ContainerExceptionInterface is not subtype of Throwable#'

Datei anzeigen

@ -5,5 +5,5 @@ services:
Psr\Log\LoggerInterface:
class: Monolog\Logger
factory: 'OxidEsales\EshopCommunity\Internal\Framework\Logger\Factory\LoggerFactoryInterface:create'
factory: ['@OxidEsales\EshopCommunity\Internal\Framework\Logger\Factory\LoggerFactoryInterface', 'create']
public: true