diff --git a/Application/Component/DebugBarComponent.php b/Application/Component/DebugBarComponent.php index 375d783..ce64934 100644 --- a/Application/Component/DebugBarComponent.php +++ b/Application/Component/DebugBarComponent.php @@ -16,6 +16,8 @@ declare(strict_types=1); namespace D3\DebugBar\Application\Component; 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\TimeDataCollectorHandler; use DebugBar\Bridge\DoctrineCollector; @@ -102,6 +104,14 @@ class DebugBarComponent extends BaseController return new SmartyCollector($smarty); } + /** + * @return OxidShopCollector + */ + public function getOxidShopCollector(): OxidShopCollector + { + return oxNew(OxidShopCollector::class); + } + /** * @return OxidConfigCollector */ @@ -110,6 +120,14 @@ class DebugBarComponent extends BaseController return oxNew(OxidConfigCollector::class, Registry::getConfig()); } + /** + * @return OxidVersionCollector + */ + public function getOxidVersionCollector(): OxidVersionCollector + { + return oxNew(OxidVersionCollector::class); + } + /** * @param object $object * @param string $propName @@ -134,10 +152,12 @@ class DebugBarComponent extends BaseController */ public function addCollectors(StandardDebugBar $debugbar): void { + $debugbar->addCollector($this->getOxidShopCollector()); + $debugbar->addCollector($this->getOxidConfigCollector()); + $debugbar->addCollector($this->getSmartyCollector()); $debugbar->addCollector($this->getMonologCollector()); $debugbar->addCollector($this->getDoctrineCollector()); - $debugbar->addCollector($this->getSmartyCollector()); - $debugbar->addCollector($this->getOxidConfigCollector()); + $debugbar->addCollector($this->getOxidVersionCollector()); } /** diff --git a/Application/Models/Collectors/OxidConfigCollector.php b/Application/Models/Collectors/OxidConfigCollector.php index a09a67f..320deff 100644 --- a/Application/Models/Collectors/OxidConfigCollector.php +++ b/Application/Models/Collectors/OxidConfigCollector.php @@ -128,7 +128,7 @@ class OxidConfigCollector extends DataCollector implements Renderable : "PhpDebugBar.Widgets.VariableListWidget"; return [ "Configuration" => [ - "icon" => "tags", + "icon" => "database", "widget" => $widget, "map" => "oxidconfig.vars", "default" => "{}", diff --git a/Application/Models/Collectors/OxidShopCollector.php b/Application/Models/Collectors/OxidShopCollector.php new file mode 100644 index 0000000..d7f7654 --- /dev/null +++ b/Application/Models/Collectors/OxidShopCollector.php @@ -0,0 +1,143 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\DebugBar\Application\Models\Collectors; + +use Composer\InstalledVersions; +use DebugBar\DataCollector\DataCollector; +use DebugBar\DataCollector\Renderable; +use OxidEsales\Eshop\Core\Config; +use OxidEsales\Eshop\Core\Module\Module; +use OxidEsales\Eshop\Core\ShopVersion; +use OxidEsales\Eshop\Core\Theme; +use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; +use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ShopConfigurationDaoBridgeInterface; +use OxidEsales\Facts\Facts; + +class OxidShopCollector extends DataCollector implements Renderable +{ + /** @var Config */ + protected $config; + + /** @var array */ + protected $configVars = []; + + /** + * @var bool + */ + protected $useHtmlVarDumper = true; + + public function __construct() + { + $facts = new Facts(); + $theme = new Theme(); + $parentThemeId = $theme->getParent() ? $theme->getParent()->getId() : '--'; + + $moduleList = $this->getInstalledModules(); + array_walk( + $moduleList, + function (Module &$module) { + $str = trim(strip_tags($module->getTitle())).' - '.$module->getInfo('version').' '; + $module = $str; + } + ); + + $this->configVars = [ + 'Shop Edition:' => $facts->getEdition(), + 'Shop Version:' => ShopVersion::getVersion(), + 'CE Version:' => InstalledVersions::getVersion('oxid-esales/oxideshop-ce'), + 'Theme:' => $theme->getActiveThemeId(), + 'Parent Theme:' => $parentThemeId, + 'Modules:' => implode(chr(10), $moduleList) + ]; + } + + /** + * @return string + */ + public function getName(): string + { + return 'oxidshop'; + } + + /** + * @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 [ + "Shop" => [ + "icon" => "shopping-cart", + "widget" => $widget, + "map" => $this->getName().".vars", + "default" => "{}", + ], + ]; + } + + protected function getInstalledModules(): array + { + $container = ContainerFactory::getInstance()->getContainer(); + $shopConfiguration = $container->get(ShopConfigurationDaoBridgeInterface::class)->get(); + + $modules = []; + + foreach ($shopConfiguration->getModuleConfigurations() as $moduleConfiguration) { + $module = oxNew(Module::class); + $module->load($moduleConfiguration->getId()); + $modules[] = $module; + } + + usort($modules, function ($a, $b) { + return strcmp($a->getTitle(), $b->getTitle()); + }); + + return $modules; + } +} diff --git a/Application/Models/Collectors/OxidVersionCollector.php b/Application/Models/Collectors/OxidVersionCollector.php new file mode 100644 index 0000000..c14f4d1 --- /dev/null +++ b/Application/Models/Collectors/OxidVersionCollector.php @@ -0,0 +1,66 @@ + + * @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\ShopVersion; +use OxidEsales\Eshop\Core\Theme; +use OxidEsales\Facts\Facts; + +/** + * Collects info about OXID shop + */ +class OxidVersionCollector extends DataCollector implements Renderable +{ + /** + * @return string + */ + public function getName() + { + return 'oxidversion'; + } + + /** + * @return array + */ + public function collect() + { + $facts = new Facts(); + $theme = new Theme(); + $parentThemeId = $theme->getParent() ? $theme->getParent()->getId() : '--'; + + return array( + 'version' => $facts->getEdition().' '.ShopVersion::getVersion() + ); + } + + /** + * {@inheritDoc} + */ + public function getWidgets() + { + $collect = $this->collect(); + + return [ + "oxidversion" => [ + "icon" => "shopping-cart", + "tooltip" => 'OXID Version', + "map" => $this->getName().".version", + "default" => "" + ], + ]; + } +} diff --git a/Application/Models/Collectors/SmartyCollector.php b/Application/Models/Collectors/SmartyCollector.php index 2747a37..8912bd6 100644 --- a/Application/Models/Collectors/SmartyCollector.php +++ b/Application/Models/Collectors/SmartyCollector.php @@ -101,12 +101,12 @@ class SmartyCollector extends DataCollector implements Renderable : "PhpDebugBar.Widgets.VariableListWidget"; return [ "smarty" => [ - "icon" => "tags", + "icon" => "file-text", "widget" => $widget, "map" => "smarty.vars", "default" => "{}", ], - "smarty:badge" => [ + "smarty:badge" => [ "map" => "smarty.count", "default" => 0, ],