- Now working properly with TextResponse, and anything else which is not Text, Json or HTML

This commit is contained in:
Dave Mc Nicoll 2021-10-19 12:44:13 +00:00
parent 912e456bde
commit 08a8683d59
2 changed files with 15 additions and 7 deletions

View File

@ -35,7 +35,7 @@ class Dump {
$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;'>
<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:9000000000;'>
<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ]</div>
$data
</pre>

View File

@ -7,10 +7,7 @@ namespace Dump {
Psr\Http\Server\RequestHandlerInterface,
Psr\Http\Message\ResponseInterface;
use Laminas\Diactoros\Response,
Laminas\Diactoros\Stream,
Laminas\Diactoros\Response\JsonResponse,
Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\{ Response, Stream, Response\JsonResponse, Response\HtmlResponse, Response\TextResponse };
use function stream_copy_to_stream;
@ -42,14 +39,25 @@ namespace Dump {
};
switch (true) {
case $response instanceof TextResponse:
$body = $response->getBody();
foreach(static::$dump_stack as $item) {
$stream->write($item->renderText());
}
$stream->append_resource($body->detach());
break;
case $response instanceof JsonResponse:
foreach(static::$dump_stack as $item) {
$dump[] = $item->renderArray();
}
$stream->write(json_encode(array_merge([ "_dump" => $dump ?? [] ], json_decode($response->getBody()->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS));
break;
break;
default:
case $response instanceof Response:
$body = $response->getBody();
@ -58,7 +66,7 @@ namespace Dump {
}
$stream->append_resource($body->detach());
break;
break;
}
return $response->withBody($stream);