- Now working properly with TextResponse, and anything else which is not Text, Json or HTML
This commit is contained in:
		
							parent
							
								
									912e456bde
								
							
						
					
					
						commit
						08a8683d59
					
				@ -35,7 +35,7 @@ class Dump {
 | 
				
			|||||||
        $data = $this->getDumpContent();
 | 
					        $data = $this->getDumpContent();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        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;'>
 | 
					<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>
 | 
					<div style='color:#9f9f9f;font-size:10px;' title='{$this->trace['file']}'>[ file: {$this->trace['file']}:{$this->trace['line']} ]</div>
 | 
				
			||||||
$data
 | 
					$data
 | 
				
			||||||
</pre>
 | 
					</pre>
 | 
				
			||||||
 | 
				
			|||||||
@ -7,10 +7,7 @@ namespace Dump {
 | 
				
			|||||||
        Psr\Http\Server\RequestHandlerInterface,
 | 
					        Psr\Http\Server\RequestHandlerInterface,
 | 
				
			||||||
        Psr\Http\Message\ResponseInterface;
 | 
					        Psr\Http\Message\ResponseInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use Laminas\Diactoros\Response,
 | 
					    use Laminas\Diactoros\{ Response, Stream, Response\JsonResponse, Response\HtmlResponse, Response\TextResponse };
 | 
				
			||||||
        Laminas\Diactoros\Stream,
 | 
					 | 
				
			||||||
        Laminas\Diactoros\Response\JsonResponse,
 | 
					 | 
				
			||||||
        Laminas\Diactoros\Response\HtmlResponse;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    use function stream_copy_to_stream;
 | 
					    use function stream_copy_to_stream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -42,14 +39,25 @@ namespace Dump {
 | 
				
			|||||||
            };
 | 
					            };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            switch (true) {
 | 
					            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:
 | 
					                case $response instanceof JsonResponse:
 | 
				
			||||||
                    foreach(static::$dump_stack as $item) {
 | 
					                    foreach(static::$dump_stack as $item) {
 | 
				
			||||||
                        $dump[] = $item->renderArray();
 | 
					                        $dump[] = $item->renderArray();
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $stream->write(json_encode(array_merge([ "_dump" => $dump ?? [] ], json_decode($response->getBody()->getContents() ?? "{}", true)), JsonResponse::DEFAULT_JSON_FLAGS));
 | 
					                    $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:
 | 
					                case $response instanceof Response:
 | 
				
			||||||
                    $body = $response->getBody();
 | 
					                    $body = $response->getBody();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -58,7 +66,7 @@ namespace Dump {
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $stream->append_resource($body->detach());
 | 
					                    $stream->append_resource($body->detach());
 | 
				
			||||||
                break;
 | 
					                    break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $response->withBody($stream);
 | 
					            return $response->withBody($stream);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user