diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index a86bac9fb95e9..9e06c9f3c73e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -1227,15 +1227,19 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode) ->scalarNode('log_level') ->info('The level of log message. Null to let Symfony decide.') ->validate() - ->ifTrue(function ($v) use ($logLevels) { return !\in_array($v, $logLevels); }) + ->ifTrue(function ($v) use ($logLevels) { return null !== $v && !\in_array($v, $logLevels, true); }) ->thenInvalid(sprintf('The log level is not valid. Pick one among "%s".', implode('", "', $logLevels))) ->end() ->defaultNull() ->end() ->scalarNode('status_code') - ->info('The status code of the response. Null to let Symfony decide.') + ->info('The status code of the response. Null or 0 to let Symfony decide.') + ->beforeNormalization() + ->ifTrue(function ($v) { return 0 === $v; }) + ->then(function ($v) { return null; }) + ->end() ->validate() - ->ifTrue(function ($v) { return $v < 100 || $v > 599; }) + ->ifTrue(function ($v) { return null !== $v && ($v < 100 || $v > 599); }) ->thenInvalid('The status code is not valid. Pick a value between 100 and 599.') ->end() ->defaultNull() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/exceptions.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/exceptions.php index 5d0dde0e0ac64..96b128f97b010 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/exceptions.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/exceptions.php @@ -1,6 +1,9 @@ loadFromExtension('framework', [ 'exceptions' => [ @@ -8,5 +11,17 @@ 'log_level' => 'info', 'status_code' => 422, ], + NotFoundHttpException::class => [ + 'log_level' => 'info', + 'status_code' => null, + ], + ConflictHttpException::class => [ + 'log_level' => 'info', + 'status_code' => 0, + ], + ServiceUnavailableHttpException::class => [ + 'log_level' => null, + 'status_code' => 500, + ], ], ]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml index cc73b8de3ced6..49878fc118b50 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml @@ -8,6 +8,9 @@ + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/exceptions.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/exceptions.yml index 82fab4e04a9f9..3958c4c5fd3fb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/exceptions.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/exceptions.yml @@ -3,3 +3,12 @@ framework: Symfony\Component\HttpKernel\Exception\BadRequestHttpException: log_level: info status_code: 422 + Symfony\Component\HttpKernel\Exception\NotFoundHttpException: + log_level: info + status_code: null + Symfony\Component\HttpKernel\Exception\ConflictHttpException: + log_level: info + status_code: 0 + Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException: + log_level: null + status_code: 500 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 36d0f441ccf8c..82687f503b484 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -550,6 +550,18 @@ public function testExceptionsConfig() 'log_level' => 'info', 'status_code' => 422, ], + \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class => [ + 'log_level' => 'info', + 'status_code' => null, + ], + \Symfony\Component\HttpKernel\Exception\ConflictHttpException::class => [ + 'log_level' => 'info', + 'status_code' => null, + ], + \Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class => [ + 'log_level' => null, + 'status_code' => 500, + ], ], $container->getDefinition('exception_listener')->getArgument(3)); } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php index 9dc3871c25df7..b6fd0a357d6fe 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php @@ -33,8 +33,14 @@ class ErrorListener implements EventSubscriberInterface protected $controller; protected $logger; protected $debug; + /** + * @var array|null}> + */ protected $exceptionsMapping; + /** + * @param array|null}> $exceptionsMapping + */ public function __construct($controller, LoggerInterface $logger = null, bool $debug = false, array $exceptionsMapping = []) { $this->controller = $controller;