From b1dbe6854dd3088e5903014d4b32d27783ae770a Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 31 Jul 2022 21:58:12 +0200 Subject: [PATCH] add smarty collector --- Application/Component/DebugBarComponent.php | 27 ++++- .../Models/Collectors/SmartyCollector.php | 114 ++++++++++++++++++ README.en.md | 32 ++++- README.md | 32 ++++- 4 files changed, 200 insertions(+), 5 deletions(-) create mode 100644 Application/Models/Collectors/SmartyCollector.php diff --git a/Application/Component/DebugBarComponent.php b/Application/Component/DebugBarComponent.php index 1adf85d..dfd54a5 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\SmartyCollector; use DebugBar\Bridge\DoctrineCollector; use DebugBar\Bridge\MonologCollector; use DebugBar\DataCollector\PDO\PDOCollector; @@ -51,10 +52,8 @@ class DebugBarComponent extends BaseController if (false === isAdmin()) { $debugbar = new StandardDebugBar(); - $debugbar->addCollector(new PDOCollector()); - $debugbar->addCollector($this->getMonologCollector()); - $debugbar->addCollector($this->getDoctrineCollector()); + $this->addCollectors($debugbar); $debugbarRenderer = $debugbar->getJavascriptRenderer(); $debugbarRenderer->setBaseUrl(Registry::getConfig()->getOutUrl() . 'debugbar'); @@ -88,6 +87,14 @@ class DebugBarComponent extends BaseController return new DoctrineCollector($debugStack); } + /** + * @return SmartyCollector + */ + public function getSmartyCollector(): SmartyCollector + { + return new SmartyCollector(Registry::getUtilsView()->getSmarty()); + } + /** * @return string|null */ @@ -110,4 +117,18 @@ class DebugBarComponent extends BaseController $property->setAccessible(true); return $property->getValue($object); } + + /** + * @param StandardDebugBar $debugbar + * @return void + * @throws DatabaseConnectionException + * @throws DebugBarException + * @throws ReflectionException + */ + public function addCollectors(StandardDebugBar $debugbar): void + { + $debugbar->addCollector($this->getMonologCollector()); + $debugbar->addCollector($this->getDoctrineCollector()); + $debugbar->addCollector($this->getSmartyCollector()); + } } \ No newline at end of file diff --git a/Application/Models/Collectors/SmartyCollector.php b/Application/Models/Collectors/SmartyCollector.php new file mode 100644 index 0000000..53df3a4 --- /dev/null +++ b/Application/Models/Collectors/SmartyCollector.php @@ -0,0 +1,114 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\DebugBar\Application\Models\Collectors; + +use DebugBar\DataCollector\DataCollector; +use DebugBar\DataCollector\Renderable; +use Smarty; + +class SmartyCollector extends DataCollector implements Renderable +{ + /** @var Smarty */ + protected $smarty; + + /** + * @var bool + */ + protected $useHtmlVarDumper = false; + + /** + * Sets a flag indicating whether the Symfony HtmlDumper will be used to dump variables for + * rich variable rendering. + * + * @param bool $value + * @return $this + */ + public function useHtmlVarDumper($value = true) + { + $this->useHtmlVarDumper = $value; + + return $this; + } + + /** + * Indicates whether the Symfony HtmlDumper will be used to dump variables for rich variable + * rendering. + * + * @return mixed + */ + public function isHtmlVarDumperUsed() + { + return $this->useHtmlVarDumper; + } + + /** + * @param Smarty $smarty + */ + public function __construct(Smarty $smarty) + { + $this->smarty = $smarty; + } + + /** + * @return array + */ + public function collect(): array + { + $data = []; + + $vars = $this->smarty->get_template_vars(); + + 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)]; + } + + /** + * @return string + */ + public function getName(): string + { + return 'smarty'; + } + + /** + * @return array + */ + public function getWidgets(): array + { + $widget = $this->isHtmlVarDumperUsed() + ? "PhpDebugBar.Widgets.HtmlVariableListWidget" + : "PhpDebugBar.Widgets.VariableListWidget"; + return array( + "smarty" => array( + "icon" => "tags", + "widget" => $widget, + "map" => "smarty.vars", + "default" => "{}" + ), + "smarty:badge" => array( + "map" => "smarty.count", + "default" => 0 + ) + ); + } +} diff --git a/README.en.md b/README.en.md index 2eedd98..9316ba3 100644 --- a/README.en.md +++ b/README.en.md @@ -11,6 +11,7 @@ The debug bar enables the display of relevant debug information in the shop fron - [Changelog](#changelog) - [Contributing](#contributing) - [License](#license)´ +- [Further licences and terms of use](#further-licences-and-terms-of-use)´ ## Installation @@ -62,4 +63,33 @@ Copyright (c) D3 Data Development (Inh. Thomas Dartsch) This software is distributed under the GNU GENERAL PUBLIC LICENSE version 3. ``` -For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code. \ No newline at end of file +For full copyright and licensing information, please see the [LICENSE](LICENSE.md) file distributed with this source code. + +## Further licences and terms of use + +### Smarty collector +([https://github.com/Junker/php-debugbar-smarty/blob/master/LICENSE](https://github.com/Junker/php-debugbar-smarty/blob/master/LICENSE) - status 2022-07-31) + +``` +The MIT License (MIT) + +Copyright (c) 2016 Dmitry Kosenkov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` \ No newline at end of file diff --git a/README.md b/README.md index 891e5c0..f7321af 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Die Debug Bar ermöglicht die Darstellung relevanter Debuginformationen im Shopf - [Changelog](#changelog) - [Beitragen](#beitragen) - [Lizenz](#lizenz) +- [Weitere Lizenzen und Nutzungsbedingungen](#weitere-lizenzen-und-nutzungsbedingungen) ## Installation @@ -62,4 +63,33 @@ Copyright (c) D3 Data Development (Inh. Thomas Dartsch) Diese Software wird unter der GNU GENERAL PUBLIC LICENSE Version 3 vertrieben. ``` -Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde. \ No newline at end of file +Die vollständigen Copyright- und Lizenzinformationen entnehmen Sie bitte der [LICENSE](LICENSE.md)-Datei, die mit diesem Quellcode verteilt wurde. + +## weitere Lizenzen und Nutzungsbedingungen + +### Smarty-Collector +([https://github.com/Junker/php-debugbar-smarty/blob/master/LICENSE](https://github.com/Junker/php-debugbar-smarty/blob/master/LICENSE) - Stand 31.07.2022) + +``` +The MIT License (MIT) + +Copyright (c) 2016 Dmitry Kosenkov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +``` \ No newline at end of file