11
11
12
12
namespace Symfony \Bundle \WebProfilerBundle \Controller ;
13
13
14
- use Symfony \Component \Debug \ ExceptionHandler ;
14
+ use Symfony \Component \ErrorHandler \ ErrorRenderer \ HtmlErrorRenderer ;
15
15
use Symfony \Component \HttpFoundation \Response ;
16
16
use Symfony \Component \HttpKernel \Debug \FileLinkFormatter ;
17
17
use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
@@ -30,14 +30,18 @@ class ExceptionController
30
30
protected $ twig ;
31
31
protected $ debug ;
32
32
protected $ profiler ;
33
+ private $ charset ;
33
34
private $ fileLinkFormat ;
35
+ private $ errorRenderer ;
34
36
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 )
36
38
{
37
39
$ this ->profiler = $ profiler ;
38
40
$ this ->twig = $ twig ;
39
41
$ this ->debug = $ debug ;
42
+ $ this ->charset = $ charset ;
40
43
$ this ->fileLinkFormat = $ fileLinkFormat ;
44
+ $ this ->errorRenderer = $ errorRenderer ;
41
45
}
42
46
43
47
/**
@@ -61,9 +65,11 @@ public function showAction($token)
61
65
$ template = $ this ->getTemplate ();
62
66
63
67
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
+ }
65
71
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 ' ]);
67
73
}
68
74
69
75
$ code = $ exception ->getStatusCode ();
@@ -97,13 +103,14 @@ public function cssAction($token)
97
103
98
104
$ this ->profiler ->disable ();
99
105
100
- $ exception = $ this ->profiler ->loadProfile ($ token )->getCollector ('exception ' )->getException ();
101
106
$ template = $ this ->getTemplate ();
102
107
103
108
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
+ }
105
112
106
- return new Response ($ handler -> getStylesheet ($ exception ), 200 , ['Content-Type ' => 'text/css ' ]);
113
+ return new Response ($ this -> errorRenderer -> getStylesheet (), 200 , ['Content-Type ' => 'text/css ' ]);
107
114
}
108
115
109
116
return new Response ($ this ->twig ->render ('@WebProfiler/Collector/exception.css.twig ' ), 200 , ['Content-Type ' => 'text/css ' ]);
0 commit comments