Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef5da7bb7e | ||
|
|
ff4ade51fb | ||
|
|
b9416c580b | ||
|
|
49148e87d4 |
No files matched your search
+17
-6
@@ -33,15 +33,17 @@ class Dump {
|
||||
}
|
||||
|
||||
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['line'] ??= "?";
|
||||
|
||||
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;'>
|
||||
<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>
|
||||
$data
|
||||
<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-wrap;margin:0.33rem 0;position: relative;z-index:9999999999;'>
|
||||
<details open><!--
|
||||
--><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>
|
||||
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;
|
||||
}
|
||||
|
||||
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();
|
||||
var_dump(...($this->content !== [] ? $this->content : [null]));
|
||||
var_dump(...$any);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Dump {
|
||||
|
||||
use Psr\Http\Server\MiddlewareInterface,
|
||||
Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Server\RequestHandlerInterface,
|
||||
@@ -28,6 +27,13 @@ namespace Dump {
|
||||
{
|
||||
$response = $handler->handle($request);
|
||||
|
||||
$stream = $this->createStream($response);
|
||||
|
||||
return $response->withBody($stream);
|
||||
}
|
||||
|
||||
public function createStream(ResponseInterface $response) : Stream
|
||||
{
|
||||
$stream = new class("php://memory", "rw") extends Stream {
|
||||
public function append_resource($resource) {
|
||||
stream_copy_to_stream($resource, $this->resource);
|
||||
@@ -52,7 +58,7 @@ namespace Dump {
|
||||
}
|
||||
|
||||
if (isset($dump)) {
|
||||
$json = json_encode(array_merge(["_dump" => $dump ], json_decode($body->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS);
|
||||
$json = json_encode(array_merge(["_dump" => $dump ], (array) json_decode($body->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS);
|
||||
|
||||
$stream->write(! is_string($json) ? json_encode($json, JsonResponse::DEFAULT_JSON_FLAGS) : $json);
|
||||
}
|
||||
@@ -76,7 +82,7 @@ namespace Dump {
|
||||
break;
|
||||
}
|
||||
|
||||
return $response->withBody($stream);
|
||||
return $stream;
|
||||
}
|
||||
|
||||
public static function dump(...$what)
|
||||
|
||||
Reference in new issue
Block a user