Skip to content

Commit b7371ea

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 #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 #31398 (comment), removing here workaround in SecurityBundle. TODO: - [x] Update CHANGELOG & UPGRADE files - [x] Add tests WDYT? Commits ------- b79532a Add ErrorController to preview and render errors
2 parents 7a9c5da + b79532a commit b7371ea

File tree

38 files changed

+308
-130
lines changed

38 files changed

+308
-130
lines changed

UPGRADE-4.4.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,25 @@ TwigBridge
217217
TwigBundle
218218
----------
219219

220-
* Deprecated default value `twig.controller.exception::showAction` of the `twig.exception_controller` configuration option,
221-
set it to `null` instead. This will also change the default error response format according to https://tools.ietf.org/html/rfc7807
222-
for `json`, `xml`, `atom` and `txt` formats:
220+
* Deprecated `twig.exception_controller` configuration option, set it to "null" and use `framework.error_controller` instead:
221+
222+
Before:
223+
```yaml
224+
twig:
225+
exception_controller: 'App\Controller\MyExceptionController'
226+
```
227+
228+
After:
229+
```yaml
230+
twig:
231+
exception_controller: null
232+
233+
framework:
234+
error_controller: 'App\Controller\MyExceptionController'
235+
```
236+
237+
The new default exception controller will also change the error response content according to
238+
https://tools.ietf.org/html/rfc7807 for `json`, `xml`, `atom` and `txt` formats:
223239

224240
Before:
225241
```json
@@ -240,7 +256,8 @@ TwigBundle
240256
}
241257
```
242258

243-
* Deprecated the `ExceptionController` and all built-in error templates, use the error renderer mechanism of the `ErrorRenderer` component
259+
* Deprecated the `ExceptionController` and `PreviewErrorController` controllers, use `ErrorController` from the HttpKernel component instead
260+
* Deprecated all built-in error templates, use the error renderer mechanism of the `ErrorRenderer` component
244261
* Deprecated loading custom error templates in non-html formats. Custom HTML error pages based on Twig keep working as before:
245262

246263
Before (`templates/bundles/TwigBundle/Exception/error.jsonld.twig`):

UPGRADE-5.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ TwigBundle
538538
* The default value (`false`) of the `twig.strict_variables` configuration option has been changed to `%kernel.debug%`.
539539
* The `transchoice` tag and filter have been removed, use the `trans` ones instead with a `%count%` parameter.
540540
* Removed support for legacy templates directories `src/Resources/views/` and `src/Resources/<BundleName>/views/`, use `templates/` and `templates/bundles/<BundleName>/` instead.
541-
* The default value (`twig.controller.exception::showAction`) of the `twig.exception_controller` configuration option has been changed to `null`.
542-
* Removed `ExceptionController` class and all built-in error templates
541+
* The `twig.exception_controller` configuration option has been removed, use `framework.error_controller` instead.
542+
* Removed `ExceptionController`, `PreviewErrorController` classes and all built-in error templates
543543

544544
TwigBridge
545545
----------

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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

src/Symfony/Bundle/FrameworkBundle/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')) {

src/Symfony/Bundle/FrameworkBundle/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">
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>

src/Symfony/Bundle/FrameworkBundle/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">

src/Symfony/Bundle/FrameworkBundle/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>

src/Symfony/Bundle/FrameworkBundle/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
}

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