Skip to content
Permalink
Browse files

Improve SHOW_HOOK

  • Loading branch information...
gillesbourgeat authored and roadster31 committed Apr 19, 2019
1 parent 3414719 commit e24656be71eb104c4cff5f463dbe60892828c182
Showing with 106 additions and 108 deletions.
  1. +3 −3 composer.json
  2. +75 −75 composer.lock
  3. +28 −30 local/modules/TheliaSmarty/Template/Plugins/Hook.php
@@ -61,14 +61,14 @@
"spipu/html2pdf": "^5.0",
"symfony/polyfill-php73": "^1.0",
"symfony/lock": "^3.4|^4.0",
"thelia/propel": "dev-thelia-2.4"
"thelia/propel": "dev-thelia-2.4",
"symfony/var-dumper": "^2.0|^3.0|^4.0"
},
"require-dev": {
"fzaninotto/faker": "1.5.*",
"thelia/hooktest-module": "~1.1",
"thelia/hooktest-template": "~1.1",
"phpunit/phpunit": "^5.0",
"symfony/var-dumper": "^2.0|^3.0|^4.0"
"phpunit/phpunit": "^5.0"
},
"minimum-stability": "stable",
"config": {

Some generated files are not rendered by default. Learn more.

@@ -109,7 +109,11 @@ public function processHookFunction($params, &$smarty)
$content = trim($event->dump());
if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
$content = self::showHook($hookName, $params) . $content;
$content = self::showHook(
$hookName,
$params,
$smarty->getTemplateVars()
) . $content;
}
$this->hookResults[$hookName] = $content;
@@ -156,37 +160,31 @@ protected function getSmartyPluginModule()
return $this->smartyPluginModule;
}
protected function showHook($hookName, $params)
protected function showHook($hookName, $params, $templateVars)
{
$content = '<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">' . $hookName;
foreach ($params as $name => $value) {
if ($name !== 'location' && $name !== "name") {
$type = '';
if (is_object($value)) {
$value = get_class($value);
$type = 'object';
} elseif (is_array($value)) {
$value = implode(',', $value);
$type = 'array';
} elseif (is_int($value)) {
$type = 'float';
} elseif (is_int($value)) {
$type = 'int';
} elseif (is_string($value)) {
$value = (strlen($value) > 30) ? substr($value, 0, 30) . '...' : $value;
$type = 'string';
}
if ($type !== '') {
$type = '<span style="background-color: #FF7D00; color: #fff">' . $type . '</span> ';
}
$content .= '<span style="background-color: #008000; color: #fff; margin-left: 6px;">' . $name . ' = ' . $type . $value . '</span>';
}
if (!\class_exists('\Symfony\Component\VarDumper\VarDumper')) {
throw new \Exception('For use SHOW_HOOK, you can install dependency symfony/var-dumper');
}
return $content . '</div>';
ob_start();
\Symfony\Component\VarDumper\VarDumper::dump([
'hook name' => $hookName,
'hook parameters' => $params,
'hook external variables' => $templateVars
]);
$content = ob_get_clean();
return <<<HTML
<div style="background-color: #C82D26; color: #fff; border-color: #000000; border: solid;">
{$hookName}
<a onclick="this.parentNode.querySelector('.hook-details').style.display = 'block'">Show details</a>
<div class="hook-details" style="display: none; cursor: pointer;">
{$content}
</div>
</div>
HTML;
}
/**
@@ -226,7 +224,7 @@ public function processHookBlock($params, $content, $smarty, &$repeat)
if (!$repeat) {
if ($this->debug && $smarty->getRequest()->get('SHOW_HOOK')) {
$content = self::showHook($hookName, $params) . $content;
$content = self::showHook($hookName, $params, $smarty->getTemplateVars()) . $content;
}
return $content;

0 comments on commit e24656b

Please sign in to comment.
You can’t perform that action at this time.