complete configuration collector by module settings, improve displaying

This commit is contained in:
Daniel Seifert 2025-03-24 10:46:25 +01:00
parent 8f0c912dca
commit 556379bc46

View File

@ -20,37 +20,63 @@ use DebugBar\DataCollector\Renderable;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\ConfigFile; use OxidEsales\Eshop\Core\ConfigFile;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridge;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionClass; use ReflectionClass;
use ReflectionException; use ReflectionException;
class OxidConfigCollector extends DataCollector implements Renderable class OxidConfigCollector extends DataCollector implements Renderable
{ {
/** @var Config */ public const HIDDEN_TEXT = '[hidden]';
protected $config;
/** @var array */ protected array $configVars = [];
protected $configVars = [];
/**
* @var bool
*/
protected $useHtmlVarDumper = false;
/** /**
* @param Config $config * @param Config $config
* *
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException * @throws ReflectionException
*/ */
public function __construct(Config $config) public function __construct(Config $config)
{ {
$config->init(); $config->init();
$this->config = $config;
$this->configVars = array_merge( $this->configVars['config table'] = (array) $this->getNonPublicProperty($config, '_aConfigParams');
(array) $this->getNonPublicProperty($this->config, '_aConfigParams'), $this->configVars['config file'] = Registry::get(ConfigFile::class)->getVars();
Registry::get(ConfigFile::class)->getVars() $this->configVars = array_merge($this->configVars, $this->getModuleSettings());
);
$this->sanitizeCriticalProperties(); $this->sanitizeCriticalProperties();
$this->useHtmlVarDumper(false);
}
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
protected function getModuleSettings(): array
{
$container = ContainerFactory::getInstance()->getContainer();
/** @var ShopConfigurationDaoBridge $shopConfigurationDaoBridge */
$shopConfigurationDaoBridge = $container->get(ShopConfigurationDaoBridgeInterface::class);
$shopConfiguration = $shopConfigurationDaoBridge->get();
$moduleSettings = [];
foreach ($shopConfiguration->getModuleConfigurations() as $moduleConfiguration) {
foreach ($moduleConfiguration->getModuleSettings() as $setting) {
$moduleSettings[$moduleConfiguration->getId()][$setting->getName()] = $setting->getType() == 'hidden' ?
self::HIDDEN_TEXT :
$setting->getValue();
}
}
return $moduleSettings;
} }
/** /**
@ -62,11 +88,13 @@ class OxidConfigCollector extends DataCollector implements Renderable
$specific = ['sSerialNr', 'aSerials', 'dbPwd']; $specific = ['sSerialNr', 'aSerials', 'dbPwd'];
$search = array_merge($generic, $specific); $search = array_merge($generic, $specific);
array_walk($this->configVars, function ($item, $key) use ($search) { foreach ($this->configVars as $group => $values) {
if (in_array($key, $search)) { array_walk( $this->configVars[$group], function( $item, $key ) use ( $group, $search ) {
$this->configVars[$key] = '[hidden]'; if ( in_array( $key, $search ) ) {
} $this->configVars[$group][ $key ] = self::HIDDEN_TEXT;
}); }
} );
}
} }
/** /**
@ -76,7 +104,7 @@ class OxidConfigCollector extends DataCollector implements Renderable
* @return mixed * @return mixed
* @throws ReflectionException * @throws ReflectionException
*/ */
protected function getNonPublicProperty(object $object, string $propName) protected function getNonPublicProperty(object $object, string $propName): mixed
{ {
$reflection = new ReflectionClass($object); $reflection = new ReflectionClass($object);
$property = $reflection->getProperty($propName); $property = $reflection->getProperty($propName);
@ -112,17 +140,6 @@ class OxidConfigCollector extends DataCollector implements Renderable
return ['vars' => $data, 'count' => count($data)]; return ['vars' => $data, 'count' => count($data)];
} }
/**
* Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable
* rendering.
*
* @return bool
*/
public function isHtmlVarDumperUsed(): bool
{
return $this->useHtmlVarDumper;
}
/** /**
* @return array * @return array
*/ */