diff --git a/Application/Component/DebugBarComponent.php b/Application/Component/DebugBarComponent.php index 228b520..375d783 100644 --- a/Application/Component/DebugBarComponent.php +++ b/Application/Component/DebugBarComponent.php @@ -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()); } /** diff --git a/Application/Models/Collectors/OxidConfigCollector.php b/Application/Models/Collectors/OxidConfigCollector.php new file mode 100644 index 0000000..a09a67f --- /dev/null +++ b/Application/Models/Collectors/OxidConfigCollector.php @@ -0,0 +1,142 @@ + + * @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, + ], + ]; + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index db8bff1..fc113f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 \ No newline at end of file diff --git a/README.en.md b/README.en.md index 59c70b4..a788f05 100644 --- a/README.en.md +++ b/README.en.md @@ -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. diff --git a/README.md b/README.md index fd334ca..adc6479 100644 --- a/README.md +++ b/README.md @@ -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