- Added details tag in HTML output for better visual and accessibility

This commit is contained in:
Dave Mc Nicoll 2025-09-17 18:44:52 +00:00
parent 9526cb8e2e
commit 49148e87d4

View File

@ -33,15 +33,17 @@ class Dump {
} }
public function renderHtml() { public function renderHtml() {
$data = $this->getDumpContent(); $data = implode('', array_map(fn($e) => "<details style='padding-left:5px' open><summary></summary><p style='margin-top: -1.1rem;margin-left: 15px;'>$e</p></details>", $this->getDumpContent(true)));
$this->trace['file'] ??= "?"; $this->trace['file'] ??= "?";
$this->trace['line'] ??= "?"; $this->trace['line'] ??= "?";
return <<<HTML return <<<HTML
<pre style='-webkit-overflow-scrolling: touch;background-color: #f5f5f5;color: #4a4a4a;font-size: 12px;line-height:18px;overflow-x: auto;padding: 0.5rem 1.5rem;word-wrap: normal;white-space: pre;margin:0.33rem 0;position: relative;z-index:9999999999;'> <pre style='-webkit-overflow-scrolling: touch;background-color: #f5f5f5;color: #4a4a4a;font-size: 12px;line-height:18px;overflow-x: auto;padding: 0.5rem 1.5rem;word-wrap: normal;white-space: pre-line;margin:0.33rem 0;position: relative;z-index:9999999999;'>
<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ] <small>timestamp: {$this->trace['time']}</small></div> <details open>
$data <summary><span style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ] <small>timestamp: {$this->trace['time']}</small></span> </summary>
<p>$data</p>
</details>
</pre> </pre>
HTML; HTML;
} }
@ -57,9 +59,18 @@ HTML;
return str_repeat('-', strlen($header)) . PHP_EOL . $header . PHP_EOL . str_repeat('-', strlen($header)) . PHP_EOL . $data . PHP_EOL; return str_repeat('-', strlen($header)) . PHP_EOL . $header . PHP_EOL . str_repeat('-', strlen($header)) . PHP_EOL . $data . PHP_EOL;
} }
protected function getDumpContent() { protected function getDumpContent(bool $split = false) : string|array {
if ($split) {
return array_map(fn($e) => $this->renderDump([ $e ]), $this->content ?: [ null ]);
}
return $this->renderDump($this->content !== [] ? $this->content : [null]);
}
protected function renderDump(mixed $any) : string
{
ob_start(); ob_start();
var_dump(...($this->content !== [] ? $this->content : [null])); var_dump(...$any);
return ob_get_clean(); return ob_get_clean();
} }