8
0

Commits vergleichen

..

1 Commits

Autor SHA1 Nachricht Datum
153643f0f1
add Twig Collector 2022-08-16 22:59:44 +02:00
18 geänderte Dateien mit 65 neuen und 242 gelöschten Zeilen

Datei anzeigen

@ -15,15 +15,16 @@ 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;
use DebugBar\Bridge\NamespacedTwigProfileCollector;
use DebugBar\Bridge\Twig\TwigCollector;
use DebugBar\Bridge\TwigProfileCollector;
use DebugBar\DataCollector\ExceptionsCollector;
use DebugBar\DataCollector\MemoryCollector;
use DebugBar\DataCollector\MessagesCollector;
@ -40,13 +41,18 @@ use OxidEsales\Eshop\Core\Controller\BaseController;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\Twig\Loader\ContentTemplateLoader;
use ReflectionClass;
use ReflectionException;
use Twig\Environment;
use Twig\Extension\ProfilerExtension;
use Twig\Profiler\Profile;
class DebugBarComponent extends BaseController
{
/** @var DebugBar|null */
protected $debugBar = null;
/** @var DebugBar */
protected $debugBar;
/** @var JavascriptRenderer */
protected $debugBarRenderer;
@ -65,7 +71,7 @@ class DebugBarComponent extends BaseController
{
parent::__construct();
if (AvailabilityCheck::isAvailable()) {
if (false === isAdmin()) {
$debugbar = new DebugBar();
$this->addCollectors($debugbar);
@ -168,10 +174,22 @@ class DebugBarComponent extends BaseController
$debugbar->addCollector(new MemoryCollector());
$debugbar->addCollector(new ExceptionsCollector());
/*
$container = ContainerFactory::getInstance()->getContainer();
/** @var ContentTemplateLoader $contentTemplateLoader */
/*
$contentTemplateLoader = $container->get(ContentTemplateLoader::class);
$twigEnv = new Environment($contentTemplateLoader);
$twigProfile = new Profile();
$twigEnv->addExtension(new ProfilerExtension($twigProfile));
*/
// add custom collectors
$debugbar->addCollector($this->getOxidShopCollector());
$debugbar->addCollector($this->getOxidConfigCollector());
$debugbar->addCollector($this->getSmartyCollector());
//$debugbar->addCollector(new NamespacedTwigProfileCollector($twigProfile, $contentTemplateLoader));
$debugbar->addCollector($this->getMonologCollector());
$debugbar->addCollector($this->getDoctrineCollector());
$debugbar->addCollector($this->getOxidVersionCollector());
@ -182,10 +200,6 @@ 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();
@ -197,14 +211,9 @@ 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

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

Datei anzeigen

@ -1,22 +0,0 @@
<?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

@ -1,26 +0,0 @@
<?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

@ -1,26 +0,0 @@
<?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,23 +4,7 @@ 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.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
## [Unreleased](https://git.d3data.de/D3Public/DebugBar/compare/1.1.0.0...rel_1.x)
## [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,7 +15,6 @@ 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;
@ -40,7 +39,8 @@ class DebugBarErrorHandler
*/
public function callback(int $severity, string $message, string $file, int $line)
{
AvailabilityCheck::markErrorOccured();
global $debugBarErrorOccured;
$debugBarErrorOccured = 1;
if (0 === error_reporting() || !(error_reporting() & $severity)) {
// This error code is not included in error_reporting.

Datei anzeigen

@ -16,8 +16,6 @@ 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;
@ -44,7 +42,7 @@ class DebugBarExceptionHandler
$defaultExceptionHandler->writeExceptionToLog($exception);
} catch (Throwable $loggerException) {
/**
* It's not possible to get the logger from the DI container.
* Its 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 {
@ -52,11 +50,13 @@ class DebugBarExceptionHandler
$logger = $loggerServiceFactory->getLogger();
$logger->error($exception->getTraceAsString());
} catch (Throwable $throwableWithoutPossibilityToWriteToLogFile) {
// It's not possible to log because e.g. the log file is not writable.
// It is not possible to log because e.g. the log file is not writable.
}
}
if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet()) {
global $debugBarSet;
if ($debugBarSet !== 1 && false === isAdmin()) {
try {
/** @var DebugBarComponent $debugBarComponent */
$debugBarComponent = oxNew(DebugBarComponent::class);
@ -77,13 +77,13 @@ HTML;
</head>
<body>
HTML;
AvailabilityCheck::markDebugBarAsSet();
$debugBarSet = 1;
echo $debugBarComponent->getRenderer()->render();
echo <<<HTML
</body>
</html>
HTML;
} catch (DebugBarException|UnavailableException $e) {
} catch (DebugBarException $e) {
Registry::getLogger()->error($e->getMessage());
Registry::getUtilsView()->addErrorToDisplay($e);
}

Datei anzeigen

@ -15,21 +15,15 @@ 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|ExceptionHandler
* @return DebugBarExceptionHandler
*/
protected function getExceptionHandler()
{
if (AvailabilityCheck::isAvailable()) {
return new DebugBarExceptionHandler();
}
return parent::getExceptionHandler();
return new DebugBarExceptionHandler();
}
}

Datei anzeigen

@ -16,7 +16,6 @@ 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;
@ -46,14 +45,14 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
{
parent::start();
if (AvailabilityCheck::isAvailable() && AvailabilityCheck::ifDebugBarNotSet() && AvailabilityCheck::ifNoErrorOccured()) {
global $debugBarSet, $debugBarErrorOccured;
if (!isAdmin() && $debugBarSet !== 1 && $debugBarErrorOccured !== 1) {
$activeView = Registry::getConfig()->getTopActiveView();
/** @var DebugBarComponent|null $debugBarComponent */
$debugBarComponent = method_exists($activeView, 'getComponent')
? $activeView->getComponent(DebugBarComponent::class)
: null;
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
if ($debugBarComponent) {
AvailabilityCheck::markDebugBarAsSet();
$debugBarSet = 1;
echo $debugBarComponent->getRenderer()->renderHead();
$debugBarComponent->addTimelineMessures();
echo $debugBarComponent->getRenderer()->render();

Datei anzeigen

@ -14,8 +14,6 @@
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;
@ -62,6 +60,7 @@ function stopProfile(string $sProfileName): void
$timeDataCollector = TimeDataCollectorHandler::getInstance();
$timeDataCollector->stopMeasure($hash);
global $aStartTimes;
global $executionCounts;
if (!isset($executionCounts[$sProfileName])) {
@ -91,25 +90,17 @@ function debugVar($mVar, bool $blToFile = false): void
fclose($f);
}
} else {
try {
if (! AvailabilityCheck::isAvailable()) {
throw new UnavailableException();
}
if (!isAdmin()) {
$activeView = Registry::getConfig()->getTopActiveView();
/** @var DebugBarComponent|null $debugBarComponent */
$debugBarComponent = method_exists($activeView, 'getComponent')
? $activeView->getComponent(DebugBarComponent::class)
: null;
if ($debugBarComponent === null) {
throw new UnavailableException();
}
/** @var DebugBarComponent $debugBarComponent */
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
/** @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);
} catch (UnavailableException $e) {
} else {
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.js'
rtrim($shopDir, '/').'/out/debugbar/debugbar.jas'
)) {
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,3 +3,4 @@
- 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 DebugBar to OXID eShop",
"description": "add the DegugBar to OXID eShop",
"type": "oxideshop-module",
"keywords": [
"oxid",
@ -26,7 +26,7 @@
],
"require": {
"php": ">=7.3",
"oxid-esales/oxideshop-ce": "6.8 - 6.13",
"oxid-esales/oxideshop-ce": "6.8 - 6.10",
"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.2.0.0',
'version' => '1.0.0.0',
'author' => 'D&sup3; Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/',
@ -46,13 +46,6 @@ $aModule = [
'onActivate' => '\D3\DebugBar\Setup\Events::onActivate',
],
'templates' => [],
'settings' => [
[
'group' => $sModuleId.'_general',
'name' => $sModuleId.'_showForAdminUsersOnly',
'type' => 'bool',
'value' => false,
],
],
'settings' => [],
'blocks' => [],
];

Datei anzeigen

@ -12,5 +12,6 @@ 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