diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index a86ec0561d3bc..c70a07635843a 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -1194,35 +1194,31 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode)
$logLevels = (new \ReflectionClass(LogLevel::class))->getConstants();
$rootNode
+ ->fixXmlConfig('exception')
->children()
->arrayNode('exceptions')
->info('Exception handling configuration')
+ ->useAttributeAsKey('class')
->beforeNormalization()
+ // Handle legacy XML configuration
->ifArray()
->then(function (array $v): array {
if (!\array_key_exists('exception', $v)) {
return $v;
}
- // Fix XML normalization
- $data = isset($v['exception'][0]) ? $v['exception'] : [$v['exception']];
- $exceptions = [];
- foreach ($data as $exception) {
- $config = [];
- if (\array_key_exists('log-level', $exception)) {
- $config['log_level'] = $exception['log-level'];
- }
- if (\array_key_exists('status-code', $exception)) {
- $config['status_code'] = $exception['status-code'];
- }
- $exceptions[$exception['name']] = $config;
+ $v = $v['exception'];
+ unset($v['exception']);
+
+ foreach ($v as &$exception) {
+ $exception['class'] = $exception['name'];
+ unset($exception['name']);
}
- return $exceptions;
+ return $v;
})
->end()
->prototype('array')
- ->fixXmlConfig('exception')
->children()
->scalarNode('log_level')
->info('The level of log message. Null to let Symfony decide.')
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
index d5f369cb1e815..d4be9fb6f2b7f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
@@ -30,6 +30,7 @@
+
@@ -361,14 +362,29 @@
-
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 49878fc118b50..35c787867a93a 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions.xml
@@ -6,11 +6,25 @@
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions_legacy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions_legacy.xml
new file mode 100644
index 0000000000000..49878fc118b50
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/exceptions_legacy.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index abbe2d9a3e4c1..f212a6db89ffa 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -547,24 +547,34 @@ public function testExceptionsConfig()
{
$container = $this->createContainerFromFile('exceptions');
+ $configuration = $container->getDefinition('exception_listener')->getArgument(3);
+
$this->assertSame([
- \Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class => [
- '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));
+ \Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\ConflictHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class,
+ ], array_keys($configuration));
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => 422,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => null,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => null,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => null,
+ 'status_code' => 500,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
}
public function testRouter()
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php
index ebc37d93bed84..131bb07f0c657 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php
@@ -32,4 +32,38 @@ public function testMessengerMiddlewareFactoryErroneousFormat()
{
$this->markTestSkipped('XML configuration will not allow erroneous format.');
}
+
+ public function testLegacyExceptionsConfig()
+ {
+ $container = $this->createContainerFromFile('exceptions_legacy');
+
+ $configuration = $container->getDefinition('exception_listener')->getArgument(3);
+
+ $this->assertSame([
+ \Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\ConflictHttpException::class,
+ \Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class,
+ ], array_keys($configuration));
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => 422,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => null,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => 'info',
+ 'status_code' => null,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class]);
+
+ $this->assertEqualsCanonicalizing([
+ 'log_level' => null,
+ 'status_code' => 500,
+ ], $configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
+ }
}