|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types = 1); |
| 4 | + |
| 5 | +namespace AvtoDev\DevTools\Exceptions; |
| 6 | + |
| 7 | +use Throwable; |
| 8 | +use Symfony\Component\HttpFoundation\Request; |
| 9 | +use Symfony\Component\HttpFoundation\Response; |
| 10 | + |
| 11 | +class VarDumperException extends \Exception |
| 12 | +{ |
| 13 | + /** |
| 14 | + * VarDumperException constructor. |
| 15 | + * |
| 16 | + * @param string $message |
| 17 | + * @param int $code |
| 18 | + * @param Throwable|null $previous |
| 19 | + */ |
| 20 | + public function __construct(string $message, |
| 21 | + int $code = Response::HTTP_INTERNAL_SERVER_ERROR, |
| 22 | + Throwable $previous = null) |
| 23 | + { |
| 24 | + parent::__construct($message, $code, $previous); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Report the exception. |
| 29 | + * |
| 30 | + * Since "illuminate/framework" v5.5. |
| 31 | + * |
| 32 | + * @link https://laravel.com/docs/5.5/errors#renderable-exceptions |
| 33 | + * |
| 34 | + * @return void |
| 35 | + */ |
| 36 | + public function report() |
| 37 | + { |
| 38 | + // Do nothing |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Render the exception into an HTTP response. |
| 43 | + * |
| 44 | + * Since "illuminate/framework" v5.5. |
| 45 | + * |
| 46 | + * @link https://laravel.com/docs/5.5/errors#renderable-exceptions |
| 47 | + * |
| 48 | + * @param Request|null $request |
| 49 | + * |
| 50 | + * @return Response |
| 51 | + */ |
| 52 | + public function render(Request $request = null): Response |
| 53 | + { |
| 54 | + return new Response(static::generateView($this->getMessage()), $this->getCode()); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Generate HTML representation of some content. |
| 59 | + * |
| 60 | + * @param string $content |
| 61 | + * |
| 62 | + * @return string |
| 63 | + */ |
| 64 | + protected static function generateView($content):string |
| 65 | + { |
| 66 | + return <<<EOT |
| 67 | +<html> |
| 68 | + <head></head> |
| 69 | + <body> |
| 70 | + $content |
| 71 | + </body> |
| 72 | +</html> |
| 73 | +EOT; |
| 74 | + } |
| 75 | +} |
0 commit comments