Skip to content

Commit f97f94e

Browse files
committed
Added WebProfilerBundle integration
1 parent 0dc5780 commit f97f94e

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\WebProfilerBundle\Controller;
1313

14-
use Symfony\Component\Debug\ExceptionHandler;
14+
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
1515
use Symfony\Component\HttpFoundation\Response;
1616
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
1717
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -30,14 +30,18 @@ class ExceptionController
3030
protected $twig;
3131
protected $debug;
3232
protected $profiler;
33+
private $charset;
3334
private $fileLinkFormat;
35+
private $errorRenderer;
3436

35-
public function __construct(Profiler $profiler = null, Environment $twig, bool $debug, FileLinkFormatter $fileLinkFormat = null)
37+
public function __construct(Profiler $profiler = null, Environment $twig, bool $debug, FileLinkFormatter $fileLinkFormat = null, string $charset = null, HtmlErrorRenderer $errorRenderer = null)
3638
{
3739
$this->profiler = $profiler;
3840
$this->twig = $twig;
3941
$this->debug = $debug;
42+
$this->charset = $charset;
4043
$this->fileLinkFormat = $fileLinkFormat;
44+
$this->errorRenderer = $errorRenderer;
4145
}
4246

4347
/**
@@ -61,9 +65,11 @@ public function showAction($token)
6165
$template = $this->getTemplate();
6266

6367
if (!$this->twig->getLoader()->exists($template)) {
64-
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
68+
if (null === $this->errorRenderer) {
69+
$this->errorRenderer = new HtmlErrorRenderer($this->debug, $this->charset, $this->fileLinkFormat);
70+
}
6571

66-
return new Response($handler->getContent($exception), 200, ['Content-Type' => 'text/html']);
72+
return new Response($this->errorRenderer->getBody($exception), 200, ['Content-Type' => 'text/html']);
6773
}
6874

6975
$code = $exception->getStatusCode();
@@ -97,13 +103,14 @@ public function cssAction($token)
97103

98104
$this->profiler->disable();
99105

100-
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
101106
$template = $this->getTemplate();
102107

103108
if (!$this->templateExists($template)) {
104-
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat);
109+
if (null === $this->errorRenderer) {
110+
$this->errorRenderer = new HtmlErrorRenderer($this->debug, $this->charset, $this->fileLinkFormat);
111+
}
105112

106-
return new Response($handler->getStylesheet($exception), 200, ['Content-Type' => 'text/css']);
113+
return new Response($this->errorRenderer->getStylesheet(), 200, ['Content-Type' => 'text/css']);
107114
}
108115

109116
return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, ['Content-Type' => 'text/css']);

src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<argument type="service" id="twig" />
2828
<argument>%kernel.debug%</argument>
2929
<argument type="service" id="debug.file_link_formatter" />
30+
<argument>%kernel.charset%</argument>
31+
<argument type="service" id="error_handler.renderer.html" on-invalid="null" />
3032
</service>
3133

3234
<service id="web_profiler.csp.handler" class="Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler">

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/WebProfilerExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Definition;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
2021
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
2122
use Symfony\Component\EventDispatcher\EventDispatcher;
2223

@@ -53,6 +54,7 @@ protected function setUp()
5354
$this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock();
5455

5556
$this->container = new ContainerBuilder();
57+
$this->container->register('error_handler.renderer.html', HtmlErrorRenderer::class);
5658
$this->container->register('event_dispatcher', EventDispatcher::class)->setPublic(true);
5759
$this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))->setPublic(true);
5860
$this->container->register('twig', 'Twig\Environment')->setPublic(true);

0 commit comments

Comments
 (0)