cdn77 / Tracy-Blue-Screen-Bundle

@@ -4,14 +4,14 @@
Loading
4 4
5 5
namespace Cdn77\TracyBlueScreenBundle\BlueScreen;
6 6
7 -
use Symfony\Component\HttpFoundation\Request;
7 +
use Symfony\Component\HttpFoundation\Response;
8 8
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
9 9
use Throwable;
10 10
use Tracy\BlueScreen;
11 11
12 -
use function header;
13 -
use function headers_sent;
14 -
use function strpos;
12 +
use function assert;
13 +
use function ob_get_clean;
14 +
use function ob_start;
15 15
16 16
final class ControllerBlueScreenExceptionListener
17 17
{
@@ -25,27 +25,20 @@
Loading
25 25
26 26
    public function onKernelException(ExceptionEvent $event) : void
27 27
    {
28 -
        $this->forceExceptionControllerHtml($event->getRequest());
29 -
        $this->renderBlueScreen($event->getThrowable());
30 -
    }
28 +
        $blueScreenResponse = $this->renderBlueScreen($event->getThrowable());
31 29
32 -
    private function forceExceptionControllerHtml(Request $request) : void
33 -
    {
34 -
        $request->setRequestFormat('html');
35 -
        $request->attributes->set('_format', 'html');
30 +
        $event->setResponse($blueScreenResponse);
36 31
    }
37 32
38 -
    private function renderBlueScreen(Throwable $exception) : void
33 +
    private function renderBlueScreen(Throwable $exception) : Response
39 34
    {
40 -
        if (! headers_sent()) {
41 -
            $protocol = $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1';
42 -
            $code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false
43 -
                ? 503
44 -
                : 500;
45 -
            header($protocol . ' ' . $code, true, $code);
46 -
            header('Content-Type: text/html; charset=UTF-8');
47 -
        }
35 +
        ob_start();
48 36
49 37
        $this->blueScreen->render($exception);
38 +
39 +
        $contents = ob_get_clean();
40 +
        assert($contents !== false);
41 +
42 +
        return new Response($contents, Response::HTTP_NOT_FOUND);
50 43
    }
51 44
}
Files Coverage
src 95.45%
Project Totals (5 files) 95.45%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading