Skip to content

Commit ad61578

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Mailer] Include all transports' debug messages in RoundRobin transport exception [FrameworkBundle] fix: fix help message Use relative timestamps [Cache] Fix dealing with ext-redis' multi/exec returning a bool [Messenger][Amqp] Added missing rpc_timeout option [Serializer] Prevent GetSetMethodNormalizer from creating invalid magic method call [HttpFoundation] Fix dumping array cookies [WebProfilerBundle] Fix dump header not being displayed TraceableHttpClient: increase decorator's priority Use static methods inside data providers [FrameworkBundle] Allow configuring `framework.exceptions` with a config builder bug #48313 [Mime] Fix MessagePart serialization [ErrorHandler][DebugClassLoader] Fix some new return types support Fix getting the name of closures on PHP 8.1.11+ [Translator] Fix typo "internal" / "interval" fix dumping top-level tagged values
2 parents 698b236 + c65b5fd commit ad61578

File tree

11 files changed

+132
-46
lines changed

11 files changed

+132
-46
lines changed

Command/ConfigDumpReferenceCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function configure()
6767
6868
For dumping a specific option, add its path as second argument (only available for the yaml format):
6969
70-
<info>php %command.full_name% framework profiler.matcher</info>
70+
<info>php %command.full_name% framework http_client.default_options</info>
7171

7272
EOF
7373
)

Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private function getCallableData(mixed $callable): array
361361
}
362362
$data['name'] = $r->name;
363363

364-
if ($class = $r->getClosureScopeClass()) {
364+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
365365
$data['class'] = $class->name;
366366
if (!$r->getClosureThis()) {
367367
$data['static'] = true;

Console/Descriptor/MarkdownDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected function describeCallable(mixed $callable, array $options = [])
377377
}
378378
$string .= "\n".sprintf('- Name: `%s`', $r->name);
379379

380-
if ($class = $r->getClosureScopeClass()) {
380+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
381381
$string .= "\n".sprintf('- Class: `%s`', $class->name);
382382
if (!$r->getClosureThis()) {
383383
$string .= "\n- Static: yes";

Console/Descriptor/TextDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ private function formatCallable(mixed $callable): string
614614
if (str_contains($r->name, '{closure}')) {
615615
return 'Closure()';
616616
}
617-
if ($class = $r->getClosureScopeClass()) {
617+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
618618
return sprintf('%s::%s()', $class->name, $r->name);
619619
}
620620

Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ private function getCallableDocument(mixed $callable): \DOMDocument
548548
}
549549
$callableXML->setAttribute('name', $r->name);
550550

551-
if ($class = $r->getClosureScopeClass()) {
551+
if ($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) {
552552
$callableXML->setAttribute('class', $class->name);
553553
if (!$r->getClosureThis()) {
554554
$callableXML->setAttribute('static', 'true');

DependencyInjection/Configuration.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,35 +1165,31 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode)
11651165
$logLevels = (new \ReflectionClass(LogLevel::class))->getConstants();
11661166

11671167
$rootNode
1168+
->fixXmlConfig('exception')
11681169
->children()
11691170
->arrayNode('exceptions')
11701171
->info('Exception handling configuration')
1172+
->useAttributeAsKey('class')
11711173
->beforeNormalization()
1174+
// Handle legacy XML configuration
11721175
->ifArray()
11731176
->then(function (array $v): array {
11741177
if (!\array_key_exists('exception', $v)) {
11751178
return $v;
11761179
}
11771180

1178-
// Fix XML normalization
1179-
$data = isset($v['exception'][0]) ? $v['exception'] : [$v['exception']];
1180-
$exceptions = [];
1181-
foreach ($data as $exception) {
1182-
$config = [];
1183-
if (\array_key_exists('log-level', $exception)) {
1184-
$config['log_level'] = $exception['log-level'];
1185-
}
1186-
if (\array_key_exists('status-code', $exception)) {
1187-
$config['status_code'] = $exception['status-code'];
1188-
}
1189-
$exceptions[$exception['name']] = $config;
1181+
$v = $v['exception'];
1182+
unset($v['exception']);
1183+
1184+
foreach ($v as &$exception) {
1185+
$exception['class'] = $exception['name'];
1186+
unset($exception['name']);
11901187
}
11911188

1192-
return $exceptions;
1189+
return $v;
11931190
})
11941191
->end()
11951192
->prototype('array')
1196-
->fixXmlConfig('exception')
11971193
->children()
11981194
->scalarNode('log_level')
11991195
->info('The level of log message. Null to let Symfony decide.')

Resources/config/schema/symfony-1.0.xsd

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<xsd:element name="workflow" type="workflow" minOccurs="0" maxOccurs="unbounded" />
3131
<xsd:element name="php-errors" type="php-errors" minOccurs="0" maxOccurs="1" />
3232
<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" />
@@ -360,14 +361,29 @@
360361

361362
<xsd:complexType name="exceptions">
362363
<xsd:sequence>
363-
<xsd:element name="exception" type="exception" minOccurs="0" maxOccurs="unbounded" />
364+
<xsd:element name="exception" type="old-exception" minOccurs="0" maxOccurs="unbounded" />
364365
</xsd:sequence>
365366
</xsd:complexType>
366367

367-
<xsd:complexType name="exception">
368-
<xsd:attribute name="name" type="xsd:string" use="required" />
368+
<xsd:complexType name="exception" abstract="true">
369369
<xsd:attribute name="log-level" type="xsd:string" />
370-
<xsd:attribute name="status-code" type="xsd:int" />
370+
<xsd:attribute name="status-code" type="xsd:integer" />
371+
</xsd:complexType>
372+
373+
<xsd:complexType name="old-exception">
374+
<xsd:complexContent>
375+
<xsd:extension base="exception">
376+
<xsd:attribute name="name" type="xsd:string" use="required" />
377+
</xsd:extension>
378+
</xsd:complexContent>
379+
</xsd:complexType>
380+
381+
<xsd:complexType name="new-exception">
382+
<xsd:complexContent>
383+
<xsd:extension base="exception">
384+
<xsd:attribute name="class" type="xsd:string" use="required" />
385+
</xsd:extension>
386+
</xsd:complexContent>
371387
</xsd:complexType>
372388

373389
<xsd:complexType name="marking_store">

Tests/DependencyInjection/Fixtures/xml/exceptions.xml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@
66
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
77

88
<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>
9+
<framework:exception
10+
class="Symfony\Component\HttpKernel\Exception\BadRequestHttpException"
11+
log-level="info"
12+
status-code="422"
13+
/>
14+
15+
<framework:exception
16+
class="Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
17+
log-level="info"
18+
/>
19+
20+
<framework:exception
21+
class="Symfony\Component\HttpKernel\Exception\ConflictHttpException"
22+
log-level="info"
23+
/>
24+
25+
<framework:exception
26+
class="Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException"
27+
status-code="500"
28+
/>
1529
</framework:config>
1630
</container>
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>

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -542,24 +542,34 @@ public function testExceptionsConfig()
542542
{
543543
$container = $this->createContainerFromFile('exceptions');
544544

545+
$configuration = $container->getDefinition('exception_listener')->getArgument(3);
546+
545547
$this->assertSame([
546-
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class => [
547-
'log_level' => 'info',
548-
'status_code' => 422,
549-
],
550-
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class => [
551-
'log_level' => 'info',
552-
'status_code' => null,
553-
],
554-
\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class => [
555-
'log_level' => 'info',
556-
'status_code' => null,
557-
],
558-
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class => [
559-
'log_level' => null,
560-
'status_code' => 500,
561-
],
562-
], $container->getDefinition('exception_listener')->getArgument(3));
548+
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class,
549+
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
550+
\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class,
551+
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class,
552+
], array_keys($configuration));
553+
554+
$this->assertEqualsCanonicalizing([
555+
'log_level' => 'info',
556+
'status_code' => 422,
557+
], $configuration[\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class]);
558+
559+
$this->assertEqualsCanonicalizing([
560+
'log_level' => 'info',
561+
'status_code' => null,
562+
], $configuration[\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class]);
563+
564+
$this->assertEqualsCanonicalizing([
565+
'log_level' => 'info',
566+
'status_code' => null,
567+
], $configuration[\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class]);
568+
569+
$this->assertEqualsCanonicalizing([
570+
'log_level' => null,
571+
'status_code' => 500,
572+
], $configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
563573
}
564574

565575
public function testRouter()

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)