8000 Add BC layer · symfony/symfony@22d2fd1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22d2fd1

Browse files
committed
Add BC layer
1 parent 89fd991 commit 22d2fd1

File tree

4 files changed

+94
-3
lines changed

4 files changed

+94
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,25 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode)
11991199
->arrayNode('exceptions')
12001200
->info('Exception handling configuration')
12011201
->useAttributeAsKey('class')
1202+
->beforeNormalization()
1203+
// Handle legacy XML configuration
1204+
->ifArray()
1205+
->then(function (array $v): array {
1206+
if (!\array_key_exists('exception', $v)) {
1207+
return $v;
1208+
}
1209+
1210+
$v = $v['exception'];
1211+
unset($v['exception']);
1212+
1213+
foreach ($v as &$exception) {
1214+
$exception['class'] = $exception['name'];
1215+
unset($exception['name']);
1216+
}
1217+
1218+
return $v;
1219+
})
1220+
->end()
12021221
->prototype('array')
12031222
->children()
12041223
->scalarNode('log_level')

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<xsd:element name="cache" type="cache" minOccurs="0" maxOccurs="1" />
3030
<xsd:element name="workflow" type="workflow" minOccurs="0" maxOccurs="unbounded" />
3131
<xsd:element name="php-errors" type="php-errors" minOccurs="0" maxOccurs="1" />
32-
<xsd:element name="exception" type="exception" minOccurs="0" maxOccurs="unbounded" />
32+
<xsd:element name="exceptions" type="exceptions" minOccurs="0" maxOccurs="1" />
33+
<xsd:element name="exception" type="new-exception" minOccurs="0" maxOccurs="unbounded" />
3334
<xsd:element name="lock" type="lock" minOccurs="0" maxOccurs="1" />
3435
<xsd:element name="messenger" type="messenger" minOccurs="0" maxOccurs="1" />
3536
<xsd:element name="http-client" type="http_client" minOccurs="0" maxOccurs="1" />
@@ -359,12 +360,33 @@
359360
<xsd:attribute name="enabled" type="xsd:boolean" />
360361
</xsd:complexType>
361362

362-
<xsd:complexType name="exception">
363-
<xsd:attribute name="class" type="xsd:string" use="required" />
363+
<xsd:complexType name="exceptions">
364+
<xsd:sequence>
365+
<xsd:element name="exception" type="old-exception" minOccurs="0" maxOccurs="unbounded" />
366+
</xsd:sequence>
367+
</xsd:complexType>
368+
369+
<xsd:complexType name="exception" abstract="true">
364370
<xsd:attribute name="log-level" type="xsd:string" />
365371
<xsd:attribute name="status-code" type="xsd:integer" />
366372
</xsd:complexType>
367373

374+
<xsd:complexType name="old-exception">
375+
<xsd:complexContent>
376+
<xsd:extension base="exception">
377+
<xsd:attribute name="name" type="xsd:string" use="required" />
378+
</xsd:extension>
379+
</xsd:complexContent>
380+
</xsd:complexType>
381+
382+
<xsd:complexType name="new-exception">
383+
<xsd:complexContent>
384+
<xsd:extension base="exception">
385+
<xsd:attribute name="class" type="xsd:string" use="required" />
386+
</xsd:extension>
387+
</xsd:complexContent>
388+
</xsd:complexType>
389+
368390
<xsd:complexType name="marking_store">
369391
<xsd:sequence>
370392
<xsd:element name="argument" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:exceptions>
10+
<framework:exception name="Symfony\Component\HttpKernel\Exception\BadRequestHttpException" log-level="info" status-code="422" />
11+
<framework:exception name="Symfony\Component\HttpKernel\Exception\NotFoundHttpException" log-level="info" status-code="0" />
12+
<framework:exception name="Symfony\Component\HttpKernel\Exception\ConflictHttpException" log-level="info" status-code="0" />
13+
<framework:exception name="Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException" log-level="null" status-code="500" />
14+
</framework:exceptions>
15+
</framework:config>
16+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/XmlFrameworkExtensionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,38 @@ public function testMessengerMiddlewareFactoryErroneousFormat()
3232
{
3333
$this->markTestSkipped('XML configuration will not allow erroneous format.');
3434
}
35+
36+
public function testLegacyExceptionsConfig()
37+
{
38+
$container = $this->createContainerFromFile('exceptions_legacy');
39+
40+
$configuration = $container->getDefinition('exception_listener')->getArgument(3);
41+
42+
$this->assertSame([
43+
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class,
44+
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
45+
\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class,
46+
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class,
47+
], array_keys($configuration));
48+
49+
$this->assertEqualsCanonicalizing([
50+
'log_level' => 'info',
51+
'status_code' => 422,
52+
], $configuration[\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class]);
53+
54+
$this->assertEqualsCanonicalizing([
55+
'log_level' => 'info',
56+
'status_code' => null,
57+
], $configuration[\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class]);
58+
59+
$this->assertEqualsCanonicalizing([
60+
'log_level' => 'info',
61+
'status_code' => null,
62+
], $configuration[\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class]);
63+
64+
$this->assertEqualsCanonicalizing([
65+
'log_level' => null,
66+
'status_code' => 500,
67+
], $configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
68+
}
3569
}

0 commit comments

Comments
 (0)
0