- Dump middleware
This commit is contained in:
commit
6d1d15421d
4 files changed
+167
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Dump;
|
||||
|
||||
class Dump {
|
||||
/**
|
||||
* Latest stack trace found from the debugger
|
||||
* @var
|
||||
*/
|
||||
protected $trace = null;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $content = null;
|
||||
|
||||
public function __construct(...$content) {
|
||||
$this->trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2] ?? [
|
||||
"line" => -1,
|
||||
"file" => "unknown",
|
||||
];
|
||||
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function renderArray() {
|
||||
return [
|
||||
'content' => $this->content,
|
||||
'file' => $this->trace['file'],
|
||||
'line' => $this->trace['line'],
|
||||
];
|
||||
}
|
||||
|
||||
public function renderHtml() {
|
||||
$data = $this->getDumpContent();
|
||||
|
||||
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;'>
|
||||
<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ]</div>
|
||||
$data
|
||||
</pre>
|
||||
HTML;
|
||||
}
|
||||
|
||||
protected function getDumpContent() {
|
||||
ob_start();
|
||||
var_dump(...($this->content !== [] ? $this->content : [null]));
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user