Skip to content

[WebProfilerBundle] Decoupling TwigBundle and using the new ErrorRenderer mechanism #32695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Validator
WebProfilerBundle
-----------------

* Deprecated the `ExceptionController::templateExists()` method
* Deprecated the `ExceptionController` class in favor of `ExceptionErrorController`
* Deprecated the `TemplateManager::templateExists()` method

WebServerBundle
Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ Yaml
* The parser is now stricter and will throw a `ParseException` when a
mapping is found inside a multi-line string.

WebProfilerBundle
-----------------

* Removed the `ExceptionController` class, use `ExceptionErrorController` instead.

WebServerBundle
---------------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Added button to clear the ajax request tab
* Deprecated the `ExceptionController::templateExists()` method
* Deprecated the `TemplateManager::templateExists()` method
* Deprecated the `ExceptionController` in favor of `ExceptionErrorController`

4.3.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
use Twig\Error\LoaderError;
use Twig\Loader\ExistsLoaderInterface;

@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ExceptionController::class, ExceptionErrorController::class), E_USER_DEPRECATED);

/**
* ExceptionController.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since Symfony 4.4, use the ExceptionErrorController instead.
*/
class ExceptionController
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\WebProfilerBundle\Controller;

use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Profiler\Profiler;

/**
* Renders the exception panel.
*
* @author Yonel Ceruto <yonelceruto@gmail.com>
*/
class ExceptionErrorController
{
private $htmlErrorRenderer;
private $profiler;

public function __construct(HtmlErrorRenderer $htmlErrorRenderer, ?Profiler $profiler)
{
$this->htmlErrorRenderer = $htmlErrorRenderer;
$this->profiler = $profiler;
}

/**
* Renders the exception panel stacktrace for the given token.
*/
public function body(string $token): Response
{
if (null === $this->profiler) {
throw new NotFoundHttpException('The profiler must be enabled.');
}

$exception = $this->profiler->loadProfile($token)
->getCollector('exception')
->getException()
;

return new Response($this->htmlErrorRenderer->getBody($exception));
}

/**
* Renders the exception panel stylesheet.
*/
public function stylesheet(): Response
{
return new Response($this->htmlErrorRenderer->getStylesheet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
<argument type="service" id="debug.file_link_formatter" />
<argument type="service" id="error_renderer.renderer.html" on-invalid="null" />
<argument type="service" id="error_renderer.renderer.html" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why removing on-invalid="null" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a hard dependency on the bundle since 4.4, is there any chance it's invalid?

<deprecated>The "%service_id%" service is deprecated since Symfony 4.4, use the "web_profiler.controller.exception_error" service instead.</deprecated>
</service>

<service id="web_profiler.controller.exception_error" class="Symfony\Bundle\WebProfilerBundle\Controller\ExceptionErrorController" public="true">
<argument type="service" id="error_renderer.renderer.html" />
<argument type="service" id="profiler" on-invalid="null" />
</service>

<service id="web_profiler.csp.handler" class="Symfony\Bundle\WebProfilerBundle\Csp\ContentSecurityPolicyHandler">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
</route>

<route id="_profiler_exception" path="/{token}/exception">
<default key="_controller">web_profiler.controller.exception::showAction</default>
<default key="_controller">web_profiler.controller.exception_error::body</default>
</route>

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

</routes>
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{ include('@Twig/exception.css.twig') }}

.container {
max-width: auto;
margin: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% if collector.hasexception %}
<style>
{{ render(path('_profiler_exception_css', { token: token })) }}
{{ include('@WebProfiler/Collector/exception.css.twig') }}
</style>
{% endif %}
{{ parent() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
<span class="label status-error">exception</span>
{% endif %}
<a class="toggle-button">
<span class="icon icon-close">{{ include('@Twig/images/icon-minus-square.svg') }}</span>
<span class="icon icon-open">{{ include('@Twig/images/icon-plus-square.svg') }}</span>
<span class="icon icon-close">{{ include('@WebProfiler/images/icon-minus-square.svg') }}</span>
<span class="icon icon-open">{{ include('@WebProfiler/images/icon-plus-square.svg') }}</span>
</a>
</th>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="{{ _charset }}" />
<meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>Symfony Profiler</title>
<title>{% block title %}Symfony Profiler{% endblock %}</title>
<link rel="icon" type="image/x-icon" sizes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R8+HBUgFWSnQI2EAFnqlpcaGxsJIFkMN8L9AnPnzmX6jRs3SACeAi0vL888JwYPgTEJpauhnADo6/LSgQMHCHD37l2Cp15//XXq7eslgKb+Fi1exM9lZmbaCDclIcpQQhATE4OVsrOzuamg+cyePZuzG64Hrlu3jp9ZuWolCdy+fZueeOIJpkdHR1sLHqgM0Yh0bTRz1m7fvp2KiopYkYKCApo8ebLZIwzlFeXSOXEnsLPe2Ij+p5DbYYdOdOtDQ0rNjFya5sTcsGGDcTDZoXTcNoVBMoxWyzDS2yXmOyeUtGSskmDjx4/nRgPAfBDmMpZtUIbRcsi2GsfSD2QYyd2OcdmyZSSwdu1apuXk5GB16v4bak0yX0imyIUEgwNovFTglhMZGcm0srIy43zAVUxuTLbW4xn17Fci23wly9dngUummrTaixcvMpOtW7fiiBwQpqKYU9efHuxDJE5hC9wvL9TW1RLg+PHjPGTQ8wsLC4WpDC5Y5UR4k5qKMSLT6lqeAiX0nuAaMmSI9sMPP9CZM2foyJEj9O677wpTVIuTjidNp0HibvttoH9E5OMqbWKkSaNSlojldoLF7TEP+nUEmKI62y1kOBINbVaNarcI0PuGGUlHyfYvLHg7/jhFSFYqZh0P8KHSptd5ksOPU3tvqAEUot/hFmOIYJLp87wGe9Dwm95eg5xa/R8G6d8U5EcFhwAAAABJRU5ErkJggg==">

{% block head %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends '@Twig/layout.html.twig' %}
{% extends '@WebProfiler/Profiler/base.html.twig' %}

{% block title 'Redirection Intercepted' %}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function setUp()
$this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock();

$this->container = new ContainerBuilder();
$this->container->register('error_renderer.renderer.html', HtmlErrorRenderer::class);
$this->container->register('error_renderer.renderer.html', HtmlErrorRenderer::class)->setPublic(true);
$this->container->register('event_dispatcher', EventDispatcher::class)->setPublic(true);
$this->container->register('router', $this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))->setPublic(true);
$this->container->register('twig', 'Twig\Environment')->setPublic(true);
Expand Down Expand Up @@ -92,10 +92,11 @@ public function testDefaultConfig($debug)

$extension = new WebProfilerExtension();
$extension->load([[]], $this->container);
$this->container->removeDefinition('web_profiler.controller.exception');

$this->assertFalse($this->container->has('web_profiler.debug_toolbar'));

$this->assertSaneContainer($this->getCompiledContainer());
self::assertSaneContainer($this->getCompiledContainer());
}

/**
Expand All @@ -105,10 +106,11 @@ public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listene
{
$extension = new WebProfilerExtension();
$extension->load([['toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects]], $this->container);
$this->container->removeDefinition('web_profiler.controller.exception');

$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));

$this->assertSaneContainer($this->getCompiledContainer(), '', ['web_profiler.csp.handler']);
self::assertSaneContainer($this->getCompiledContainer(), '', ['web_profiler.csp.handler']);

if ($listenerInjected) {
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebProfilerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"php": "^7.1.3",
"symfony/config": "^4.2|^5.0",
"symfony/error-renderer": "^4.4|^5.0",
"symfony/http-kernel": "^4.4",
"symfony/routing": "^3.4|^4.0|^5.0",
"symfony/twig-bundle": "^4.2|^5.0",
Expand Down