Skip to content

Commit 70198b6

Browse files
Merge branch '6.0' into 6.1
* 6.0: [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 a64bda2 + ad61578 commit 70198b6

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
@@ -1185,35 +1185,31 @@ private function addExceptionsSection(ArrayNodeDefinition $rootNode)
11851185
$logLevels = (new \ReflectionClass(LogLevel::class))->getConstants();
11861186

11871187
$rootNode
1188+
->fixXmlConfig('exception')
11881189
->children()
11891190
->arrayNode('exceptions')
11901191
->info('Exception handling configuration')
1192+
->useAttributeAsKey('class')
11911193
->beforeNormalization()
1194+
// Handle legacy XML configuration
11921195
->ifArray()
11931196
->then(function (array $v): array {
11941197
if (!\array_key_exists('exception', $v)) {
11951198
return $v;
11961199
}
11971200

1198-
// Fix XML normalization
1199-
$data = isset($v['exception'][0]) ? $v['exception'] : [$v['exception']];
1200-
$exceptions = [];
1201-
foreach ($data as $exception) {
1202-
$config = [];
1203-
if (\array_key_exists('log-level', $exception)) {
1204-
$config['log_level'] = $exception['log-level'];
1205-
}
1206-
if (\array_key_exists('status-code', $exception)) {
1207-
$config['status_code'] = $exception['status-code'];
1208-
}
1209-
$exceptions[$exception['name']] = $config;
1201+
$v = $v['exception'];
1202+
unset($v['exception']);
1203+
1204+
foreach ($v as &$exception) {
1205+
$exception['class'] = $exception['name'];
1206+
unset($exception['name']);
12101207
}
12111208

1212-
return $exceptions;
1209+
return $v;
12131210
})
12141211
->end()
12151212
->prototype('array')
1216-
->fixXmlConfig('exception')
12171213
->children()
12181214
->scalarNode('log_level')
12191215
->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="semaphore" type="semaphore" minOccurs="0" maxOccurs="1" />
3536
<xsd:element name="messenger" type="messenger" minOccurs="0" maxOccurs="1" />
@@ -364,14 +365,29 @@
364365

365366
<xsd:complexType name="exceptions">
366367
<xsd:sequence>
367-
<xsd:element name="exception" type="exception" minOccurs="0" maxOccurs="unbounded" />
368+
<xsd:element name="exception" type="old-exception" minOccurs="0" maxOccurs="unbounded" />
368369
</xsd:sequence>
369370
</xsd:complexType>
370371

371-
<xsd:complexType name="exception">
372-
<xsd:attribute name="name" type="xsd:string" use="required" />
372+
<xsd:complexType name="exception" abstract="true">
373373
<xsd:attribute name="log-level" type="xsd:string" />
374-
<xsd:attribute name="status-code" type="xsd:int" />
374+
<xsd:attribute name="status-code" type="xsd:integer" />
375+
</xsd:complexType>
376+
377+
<xsd:complexType name="old-exception">
378+
<xsd:complexContent>
379+
<xsd:extension base="exception">
380+
<xsd:attribute name="name" type="xsd:string" use="required" />
381+
</xsd:extension>
382+
</xsd:complexContent>
383+
</xsd:complexType>
384+
385+
<xsd:complexType name="new-exception">
386+
<xsd:complexContent>
387+
<xsd:extension base="exception">
388+
<xsd:attribute name="class" type="xsd:string" use="required" />
389+
</xsd:extension>
390+
</xsd:complexContent>
375391
</xsd:complexType>
376392

377393
<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 http-method-override="false">
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 http-method-override="false">
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
@@ -576,24 +576,34 @@ public function testExceptionsConfig()
576576
{
577577
$container = $this->createContainerFromFile('exceptions');
578578

579+
$configuration = $container->getDefinition('exception_listener')->getArgument(3);
580+
579581
$this->assertSame([
580-
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class => [
581-
'log_level' => 'info',
582-
'status_code' => 422,
583-
],
584-
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class => [
585-
'log_level' => 'info',
586-
'status_code' => null,
587-
],
588-
\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class => [
589-
'log_level' => 'info',
590-
'status_code' => null,
591-
],
592-
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class => [
593-
'log_level' => null,
594-
'status_code' => 500,
595-
],
596-
], $container->getDefinition('exception_listener')->getArgument(3));
582+
\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class,
583+
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
584+
\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class,
585+
\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class,
586+
], array_keys($configuration));
587+
588+
$this->assertEqualsCanonicalizing([
589+
'log_level' => 'info',
590+
'status_code' => 422,
591+
], $configuration[\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class]);
592+
593+
$this->assertEqualsCanonicalizing([
594+
'log_level' => 'info',
595+
'status_code' => null,
596+
], $configuration[\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class]);
597+
598+
$this->assertEqualsCanonicalizing([
599+
'log_level' => 'info',
600+
'status_code' => null,
601+
], $configuration[\Symfony\Component\HttpKernel\Exception\ConflictHttpException::class]);
602+
603+
$this->assertEqualsCanonicalizing([
604+
'log_level' => null,
605+
'status_code' => 500,
606+
], $configuration[\Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException::class]);
597607
}
598608

599609
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)