add smarty collector

This commit is contained in:
Daniel Seifert 2022-07-31 21:58:12 +02:00
parent eee07e22e3
commit b1dbe6854d
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
4 changed files with 200 additions and 5 deletions

View File

@ -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());
}
}

View File

@ -0,0 +1,114 @@
<?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 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
)
);
}
}

View File

@ -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.
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.
```

View File

@ -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.
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.
```