Skip to content

Commit 92019f4

Browse files
committed
bug #2178 Throw exception for false combination of twig exception controller and exception_listener configuration (alexander-schranz)
This PR was squashed before being merged into the 2.x branch (closes #2178). Discussion ---------- Throw exception for false combination of twig exception controller and exception_listener configuration By default in symfony 4.4 the older exception controller is used so the error handler component is not used. If the exceptionListener is disabled the newer ErrorController need to be used else the mapping configuraiton and listeners don't work. This would fix #2167 (comment) where on `prefer-lowest` and disabled `exception_listener` the error handler is not called and so the exception not correctly serialized Commits ------- e54a336 Throw exception for false combination of twig exception controller and exception_listener configuration
2 parents 4535d1a + e54a336 commit 92019f4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

DependencyInjection/Compiler/TwigExceptionPass.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ final class TwigExceptionPass implements CompilerPassInterface
2424
{
2525
public function process(ContainerBuilder $container)
2626
{
27+
if ($container->hasDefinition('fos_rest.exception.codes_map') // is config exception.enabled true
28+
&& $container->hasParameter('twig.exception_listener.controller') // is twig-bundle 4.4 installed
29+
&& $container->getParameter('twig.exception_listener.controller') // is twig-bundle deprecated controller set
30+
&& !$container->hasDefinition('fos_rest.exception_listener') // is deprecated exception_listener disabled
31+
) {
32+
throw new \InvalidArgumentException('You can not disable the "fos_rest.exception.exception_listener" and still have the "twig.exception_controller" enabled.');
33+
}
34+
2735
// when no custom exception controller has been set
2836
if ($container->hasDefinition('fos_rest.error_listener') &&
2937
null === $container->getDefinition('fos_rest.error_listener')->getArgument(0)

Tests/Functional/app/RequestBodyParamConverterTwigBundle/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ framework:
1111
fos_rest:
1212
body_converter:
1313
enabled: true
14-
exception:
15-
exception_listener: false
1614
routing_loader: false
1715

1816
sensio_framework_extra:

0 commit comments

Comments
 (0)