Skip to content

Commit a4467bd

Browse files
committed
feature #33271 Added new ErrorController + Preview and enabling there the error renderer mechanism (yceruto)
This PR was merged into the 4.4 branch. Discussion ---------- Added new ErrorController + Preview and enabling there the error renderer mechanism | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes (deps=high failure is normal) | Fixed tickets | - | License | MIT | Doc PR | TODO After deprecating the `ExceptionController` in TwigBundle (refs symfony/symfony#31398) the `twig.exception_controller` config key becomes useless as feature provided by TwigBundle, while the preview controller is taking more relevance for the error renderer mechanish. **Proposal** * Deprecate the `twig.exception_controller` config key in favor of `framework.error_controller` with default `ErrorController` that activates the error renderer mechanism through the current `ExceptionListener`, meaning also that `DebugHandlersListener::onKernelException` method becomes useless too. * Deprecate the `PreviewErrorController` from TwigBundle in favor of similar in FrameworkBundle. So you no longer need to install TwigBundle to create a custom error controller or check the preview output of an error renderer (included `TwigHtmlErrorRenderer`). Btw this would fix symfony/symfony#31398 (comment), removing here workaround in SecurityBundle. TODO: - [x] Update CHANGELOG & UPGRADE files - [x] Add tests WDYT? Commits ------- b79532ab0e Add ErrorController to preview and render errors
2 parents 4aeb086 + c34f3f2 commit a4467bd

File tree

11 files changed

+37
-7
lines changed

11 files changed

+37
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ CHANGELOG
1414
* Deprecated `routing.loader.service`, use `routing.loader.container` instead.
1515
* Not tagging service route loaders with `routing.route_loader` has been deprecated.
1616
* Overriding the methods `KernelTestCase::tearDown()` and `WebTestCase::tearDown()` without the `void` return-type is deprecated.
17-
17+
* Added new `error_controller` configuration to handle system exceptions
18+
1819
4.3.0
1920
-----
2021

DependencyInjection/Configuration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use Symfony\Component\Mailer\Mailer;
2929
use Symfony\Component\Messenger\MessageBusInterface;
3030
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
31-
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
3231
use Symfony\Component\Serializer\Serializer;
3332
use Symfony\Component\Translation\Translator;
3433
use Symfony\Component\Validator\Validation;
@@ -84,6 +83,9 @@ public function getConfigTreeBuilder()
8483
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
8584
->prototype('scalar')->end()
8685
->end()
86+
->scalarNode('error_controller')
87+
->defaultValue('error_controller')
88+
->end()
8789
->end()
8890
;
8991

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public function load(array $configs, ContainerBuilder $container)
212212
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
213213
$container->setParameter('kernel.trusted_hosts', $config['trusted_hosts']);
214214
$container->setParameter('kernel.default_locale', $config['default_locale']);
215+
$container->setParameter('kernel.error_controller', $config['error_controller']);
215216

216217
if (!$container->hasParameter('debug.file_link_format')) {
217218
if (!$container->hasParameter('templating.helper.code.file_link_format')) {

Resources/config/debug_prod.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
<argument>%kernel.debug%</argument>
2222
<argument type="service" id="debug.file_link_formatter" />
2323
<argument>%kernel.debug%</argument>
24-
<argument>%kernel.charset%</argument>
25-
<argument type="service" id="error_renderer" on-invalid="null" />
2624
</service>
2725

2826
<service id="debug.file_link_formatter" class="Symfony\Component\HttpKernel\Debug\FileLinkFormatter">

Resources/config/routing/errors.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="_preview_error" path="/{code}.{_format}">
8+
<default key="_controller">error_controller::preview</default>
9+
<default key="_format">html</default>
10+
<requirement key="code">\d+</requirement>
11+
</route>
12+
</routes>

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<xsd:attribute name="secret" type="xsd:string" />
4242
<xsd:attribute name="default-locale" type="xsd:string" />
4343
<xsd:attribute name="test" type="xsd:boolean" />
44+
<xsd:attribute name="error-controller" type="xsd:string" />
4445
</xsd:complexType>
4546

4647
<xsd:complexType name="form">

Resources/config/web.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,19 @@
8888
<service id="disallow_search_engine_index_response_listener" class="Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener">
8989
<tag name="kernel.event_subscriber" />
9090
</service>
91+
92+
<service id="error_controller" class="Symfony\Component\HttpKernel\Controller\ErrorController" public="true">
93+
<argument type="service" id="http_kernel" />
94+
<argument>%kernel.error_controller%</argument>
95+
<argument type="service" id="error_renderer" />
96+
</service>
97+
98+
<service id="exception_listener" class="Symfony\Component\HttpKernel\EventListener\ExceptionListener">
99+
<tag name="kernel.event_subscriber" />
100+
<tag name="monolog.logger" channel="request" />
101+
<argument>%kernel.error_controller%</argument>
102+
<argument type="service" id="logger" on-invalid="null" />
103+
<argument>%kernel.debug%</argument>
104+
</service>
91105
</services>
92106
</container>

Tests/Command/CacheClearCommand/Fixture/TestAppKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3838

3939
public function setAnnotatedClassCache(array $annotatedClasses)
4040
{
41-
$annotatedClasses = array_diff($annotatedClasses, ['Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController', 'Symfony\Bundle\TwigBundle\Controller\ExceptionController']);
41+
$annotatedClasses = array_diff($annotatedClasses, ['Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController', 'Symfony\Bundle\TwigBundle\Controller\ExceptionController', 'Symfony\Bundle\TwigBundle\Controller\PreviewErrorController']);
4242

4343
parent::setAnnotatedClassCache($annotatedClasses);
4444
}

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
373373
'transports' => [],
374374
'enabled' => !class_exists(FullStack::class) && class_exists(Mailer::class),
375375
],
376+
'error_controller' => 'error_controller',
376377
];
377378
}
378379
}

Tests/Functional/app/BundlePaths/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ framework:
88

99
twig:
1010
strict_variables: '%kernel.debug%'
11-
exception_controller: ~
11+
exception_controller: null # to be removed in 5.0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy