8
0
DebugBar/Application/Models/Collectors/SmartyCollector.php

116 Zeilen
2.7 KiB
PHP

2022-07-31 21:58:12 +02:00
<?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 OxidEsales\Eshop\Core\Registry;
2022-07-31 21:58:12 +02:00
use Smarty;
class SmartyCollector extends DataCollector implements Renderable
{
/** @var Smarty */
2022-08-03 09:17:43 +02:00
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;
}
2022-07-31 21:58:12 +02:00
/**
* @param Smarty $smarty
*/
2022-08-03 09:17:43 +02:00
public function __construct(Smarty $smarty)
{
$this->smarty = $smarty;
}
2022-07-31 21:58:12 +02:00
/**
* @return array
*/
2022-08-03 09:17:43 +02:00
public function collect(): array
2022-07-31 21:58:12 +02:00
{
$data = ['current view template' => Registry::getConfig()->getTopActiveView()->getTemplateName()];
2022-07-31 21:58:12 +02:00
$vars = $this->smarty->get_template_vars();
2022-08-03 09:17:43 +02:00
foreach ($vars as $idx => $var) {
if ($this->isHtmlVarDumperUsed()) {
$data[$idx] = $this->getVarDumper()->renderVar($var);
} else {
$data[$idx] = $this->getDataFormatter()->formatVar($var);
}
}
2022-07-31 21:58:12 +02:00
2022-08-03 09:17:43 +02:00
return ['vars' => $data, 'count' => count($data)];
}
2022-07-31 21:58:12 +02:00
/**
* @return string
*/
2022-08-03 09:17:43 +02:00
public function getName(): string
2022-07-31 21:58:12 +02:00
{
2022-08-03 09:17:43 +02:00
return 'smarty';
}
2022-07-31 21:58:12 +02:00
/**
* @return array
*/
2022-08-03 09:17:43 +02:00
public function getWidgets(): array
2022-07-31 21:58:12 +02:00
{
2022-08-03 09:17:43 +02:00
$widget = $this->isHtmlVarDumperUsed()
? "PhpDebugBar.Widgets.HtmlVariableListWidget"
: "PhpDebugBar.Widgets.VariableListWidget";
return [
"smarty" => [
2022-08-04 16:03:32 +02:00
"icon" => "file-text",
2022-08-03 09:17:43 +02:00
"widget" => $widget,
"map" => "smarty.vars",
"default" => "{}",
],
2022-08-04 16:03:32 +02:00
"smarty:badge" => [
2022-08-03 09:17:43 +02:00
"map" => "smarty.count",
"default" => 0,
],
];
}
2022-07-31 21:58:12 +02:00
}