diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a86bac9fb..9e06c9f3c 100644 --- a/DependencyInjection/Configuration.php +++ b/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/Tests/DependencyInjection/Fixtures/php/exceptions.php b/Tests/DependencyInjection/Fixtures/php/exceptions.php index 5d0dde0e0..96b128f97 100644 --- a/Tests/DependencyInjection/Fixtures/php/exceptions.php +++ b/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/Tests/DependencyInjection/Fixtures/xml/exceptions.xml b/Tests/DependencyInjection/Fixtures/xml/exceptions.xml index cc73b8de3..49878fc11 100644 --- a/Tests/DependencyInjection/Fixtures/xml/exceptions.xml +++ b/Tests/DependencyInjection/Fixtures/xml/exceptions.xml @@ -8,6 +8,9 @@ + + + diff --git a/Tests/DependencyInjection/Fixtures/yml/exceptions.yml b/Tests/DependencyInjection/Fixtures/yml/exceptions.yml index 82fab4e04..3958c4c5f 100644 --- a/Tests/DependencyInjection/Fixtures/yml/exceptions.yml +++ b/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/Tests/DependencyInjection/FrameworkExtensionTest.php b/Tests/DependencyInjection/FrameworkExtensionTest.php index 3fb337b47..abbe2d9a3 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -552,6 +552,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)); }