Skip to content

Commit f492ba5

Browse files
committed
feature #32695 [WebProfilerBundle] Decoupling TwigBundle and using the new ErrorRenderer mechanism (yceruto)
This PR was merged into the 4.4 branch. Discussion ---------- [WebProfilerBundle] Decoupling TwigBundle and using the new ErrorRenderer mechanism | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #31398 (comment) | License | MIT | Doc PR | - Commits ------- 846d3e0 Decoupling TwigBundle and using the new ErrorRenderer mechanism
2 parents fad4104 + 846d3e0 commit f492ba5

File tree

16 files changed

+92
-13
lines changed

16 files changed

+92
-13
lines changed

UPGRADE-4.4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Validator
237237
WebProfilerBundle
238238
-----------------
239239

240-
* Deprecated the `ExceptionController::templateExists()` method
240+
* Deprecated the `ExceptionController` class in favor of `ExceptionErrorController`
241241
* Deprecated the `TemplateManager::templateExists()` method
242242

243243
WebServerBundle

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ Yaml
579579
* The parser is now stricter and will throw a `ParseException` when a
580580
mapping is found inside a multi-line string.
581581

582+
WebProfilerBundle
583+
-----------------
584+
585+
* Removed the `ExceptionController` class, use `ExceptionErrorController` instead.
586+
582587
WebServerBundle
583588
---------------
584589

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Added button to clear the ajax request tab
88
* Deprecated the `ExceptionController::templateExists()` method
99
* Deprecated the `TemplateManager::templateExists()` method
10+
* Deprecated the `ExceptionController` in favor of `ExceptionErrorController`
1011

1112
4.3.0
1213
-----

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
use Twig\Error\LoaderError;
2121
use Twig\Loader\ExistsLoaderInterface;
2222

23+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ExceptionController::class, ExceptionErrorController::class), E_USER_DEPRECATED);
24+
2325
/**
2426
* ExceptionController.
2527
*
2628
* @author Fabien Potencier <fabien@symfony.com>
29+
*
30+
* @deprecated since Symfony 4.4, use the ExceptionErrorController instead.
2731
*/
2832
class ExceptionController
2933
{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\WebProfilerBundle\Controller;
13+
14+
use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17+
use Symfony\Component\HttpKernel\Profiler\Profiler;
18+
19+
/**
20+
* Renders the exception panel.
21+
*
22+
* @author Yonel Ceruto <yonelceruto@gmail.com>
23+
*/
24+
class ExceptionErrorController
25+
{
26+
private $htmlErrorRenderer;
27+
private $profiler;
28+
29+
public function __construct(HtmlErrorRenderer $htmlErrorRenderer, ?Profiler $profiler)
30+
{
31+
$this->htmlErrorRenderer = $htmlErrorRenderer;
32+
$this->profiler = $profiler;
33+
}
34+
35+
/**
36+
* Renders the exception panel stacktrace for the given token.
37+
*/
38+
public function body(string $token): Response
39+
{
40+
if (null === $this->profiler) {
41+
throw new NotFoundHttpException('The profiler must be enabled.');
42+
}
43+
44+
$exception = $this->profiler->loadProfile($token)
45+
->getCollector('exception')
46+
->getException()
47+
;
48+
49+
return new Response($this->htmlErrorRenderer->getBody($exception));
50+
}
51+
52+
/**
53+
* Renders the exception panel stylesheet.
54+
*/
55+
public function stylesheet(): Response
56+
{
57+
return new Response($this->htmlErrorRenderer->getStylesheet());
58+
}
59+
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
<argument type="service" id="twig" />
2828
<argument>%kernel.debug%</argument>
2929
<argument type="service" id="debug.file_link_formatter" />
30-
<argument type="service" id="error_renderer.renderer.html" on-invalid="null" />
30+
<argument type="service" id="error_renderer.renderer.html" />
31+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.4, use the "web_profiler.controller.exception_error" service instead.</deprecated>
32+
</service>
33+
34+
<service id="web_profiler.controller.exception_error" class="Symfony\Bundle\WebProfilerBundle\Controller\ExceptionErrorController" public="true">
35+
<argument type="service" id="error_renderer.renderer.html" />
36+
<argument type="service" id="profiler" on-invalid="null" />
3137
</service>
3238

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
</route>
3838

3939
<route id="_profiler_exception" path="/{token}/exception">
40-
<default key="_controller">web_profiler.controller.exception::showAction</default>
40+
<default key="_controller">web_profiler.controller.exception_error::body</default>
4141
</route>
4242

4343
<route id="_profiler_exception_css" path="/{token}/exception.css">
44-
<default key="_controller">web_profiler.controller.exception::cssAction</default>
44+
<default key="_controller">web_profiler.controller.exception_error::stylesheet</default>
4545
</route>
4646

4747
</routes>

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.css.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{{ include('@Twig/exception.css.twig') }}
2-
31
.container {
42
max-width: auto;
53
margin: 0;

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{% if collector.hasexception %}
55
<style>
66
{{ render(path('_profiler_exception_css', { token: token })) }}
7+
{{ include('@WebProfiler/Collector/exception.css.twig') }}
78
</style>
89
{% endif %}
910
{{ parent() }}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/messenger.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
<span class="label status-error">exception</span>
120120
{% endif %}
121121
<a class="toggle-button">
122-
<span class="icon icon-close">{{ include('@Twig/images/icon-minus-square.svg') }}</span>
123-
<span class="icon icon-open">{{ include('@Twig/images/icon-plus-square.svg') }}</span>
122+
<span class="icon icon-close">{{ include('@WebProfiler/images/icon-minus-square.svg') }}</span>
123+
<span class="icon icon-open">{{ include('@WebProfiler/images/icon-plus-square.svg') }}</span>
124124
</a>
125125
</th>
126126
</tr>

0 commit comments

Comments
 (0)