add OXID config vars tab

This commit is contained in:
Daniel Seifert 2022-08-03 09:57:50 +02:00
parent 48ba33562e
commit 1f7306b436
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
5 changed files with 173 additions and 3 deletions

View File

@ -15,6 +15,7 @@ declare(strict_types=1);
namespace D3\DebugBar\Application\Component;
use D3\DebugBar\Application\Models\Collectors\OxidConfigCollector;
use D3\DebugBar\Application\Models\Collectors\SmartyCollector;
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
use DebugBar\Bridge\DoctrineCollector;
@ -101,6 +102,14 @@ class DebugBarComponent extends BaseController
return new SmartyCollector($smarty);
}
/**
* @return OxidConfigCollector
*/
public function getOxidConfigCollector(): OxidConfigCollector
{
return oxNew(OxidConfigCollector::class, Registry::getConfig());
}
/**
* @param object $object
* @param string $propName
@ -128,6 +137,7 @@ class DebugBarComponent extends BaseController
$debugbar->addCollector($this->getMonologCollector());
$debugbar->addCollector($this->getDoctrineCollector());
$debugbar->addCollector($this->getSmartyCollector());
$debugbar->addCollector($this->getOxidConfigCollector());
}
/**

View File

@ -0,0 +1,142 @@
<?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\Collectors;
use DebugBar\DataCollector\DataCollector;
use DebugBar\DataCollector\Renderable;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\ConfigFile;
use OxidEsales\Eshop\Core\Registry;
use ReflectionClass;
use ReflectionException;
class OxidConfigCollector extends DataCollector implements Renderable
{
/** @var Config */
protected $config;
/** @var array */
protected $configVars = [];
/**
* @var bool
*/
protected $useHtmlVarDumper = false;
public function __construct(Config $config)
{
$config->init();
$this->config = $config;
$this->configVars = array_merge(
(array) $this->getNonPublicProperty($this->config, '_aConfigParams'),
Registry::get(ConfigFile::class)->getVars()
);
$this->sanitizeCriticalProperties();
}
/**
* @return void
*/
protected function sanitizeCriticalProperties(): void
{
$generic = (array) preg_grep('/Password/', array_keys($this->configVars));
$specific = ['sSerialNr', 'aSerials', 'dbPwd'];
$search = array_merge($generic, $specific);
array_walk($this->configVars, function ($item, $key) use ($search) {
if (in_array($key, $search)) {
$this->configVars[$key] = '[hidden]';
}
});
}
/**
* @param object $object
* @param string $propName
*
* @return mixed
* @throws ReflectionException
*/
protected function getNonPublicProperty(object $object, string $propName)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($propName);
$property->setAccessible(true);
return $property->getValue($object);
}
/**
* @return string
*/
public function getName(): string
{
return 'oxidconfig';
}
/**
* @return array
*/
public function collect(): array
{
$data = [];
$vars = $this->configVars;
foreach ($vars as $idx => $var) {
if ($this->isHtmlVarDumperUsed()) {
$data[$idx] = $this->getVarDumper()->renderVar($var);
} else {
$data[$idx] = $this->getDataFormatter()->formatVar($var);
}
}
return ['vars' => $data, 'count' => count($data)];
}
/**
* Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable
* rendering.
*
* @return mixed
*/
public function isHtmlVarDumperUsed()
{
return $this->useHtmlVarDumper;
}
/**
* @return array
*/
public function getWidgets(): array
{
$widget = $this->isHtmlVarDumperUsed()
? "PhpDebugBar.Widgets.HtmlVariableListWidget"
: "PhpDebugBar.Widgets.VariableListWidget";
return [
"Configuration" => [
"icon" => "tags",
"widget" => $widget,
"map" => "oxidconfig.vars",
"default" => "{}",
],
"Configuration:badge" => [
"map" => "oxidconfig.count",
"default" => 0,
],
];
}
}

View File

@ -14,4 +14,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Doctrine database queries collector
- Smarty variables collector
- Timeline profiling collector
- Shop configuration collector
- Collector for freely definable debug messages

View File

@ -46,6 +46,24 @@ If necessary, please confirm that you allow `composer-symlinker` to execute code
Activate the module in Shopadmin under "Extensions -> Modules".
## How to use
The DebugBar displays the following tabs:
- Messages
can contain individual debug output. Messages can be set within the PHP code with `debugVar($message)` and corresponds to the OXID function `dumpVar(...)`
- Request
shows all information from GET and POST requests, as well as session, cookie and server variables
- Timeline
displays all areas defined with `startProfile` and `stopProfile` with single and summed execution time as well as a waterfall diagram
- Monolog
lists all log messages passed to the Monolog Logger
- Database
shows all database queries necessary to generate the current page
- Smarty
lists all Smarty variables available on the current shop page
- Configuration
Provides all configuration settings of the shop (from database and file).
## Changelog
See [CHANGELOG](CHANGELOG.md) for further informations.

View File

@ -46,9 +46,6 @@ Sofern nötig, bestätigen Sie bitte, dass Sie `composer-symlinker` erlauben, Co
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
```
include './modules/d3/debugbar/Modules/functions.php';
```
## Verwendung
Die DebugBar stellt folgende Tabs dar:
@ -64,6 +61,8 @@ Die DebugBar stellt folgende Tabs dar:
zeigt alle zur Generierung der aktuellen Seite nötigen Datenbankabfragen
- Smarty
listet alle Smarty-Variablen, die auf der aktuellen Shopseite zur Verfügung stehen
- Configuration
stellt alle Konfigurationseinstellungen des Shops aus Datenbank und Dateien zur Verfügung
## Changelog