Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc281ec6

Browse files
committed
Add SapiErrorRendererSelector for context-based error rendering
1 parent1a8b82e commitc281ec6

File tree

9 files changed

+92
-5
lines changed

9 files changed

+92
-5
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/error_renderer.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
useSymfony\Component\ErrorHandler\ErrorRenderer\CliErrorRenderer;
15+
useSymfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
1416
useSymfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
17+
useSymfony\Component\ErrorHandler\ErrorRenderer\SapiErrorRendererSelector;
1518

1619
returnstaticfunction (ContainerConfigurator$container) {
1720
$container->services()
@@ -32,7 +35,18 @@
3235
service('logger')->nullOnInvalid(),
3336
])
3437

38+
->set('error_handler.error_renderer.cli', CliErrorRenderer::class)
39+
40+
->set('error_handler.error_renderer.default', ErrorRendererInterface::class)
41+
->factory([SapiErrorRendererSelector::class,'select'])
42+
->args([
43+
service('error_renderer.cli'),
44+
service('error_renderer.html'),
45+
])
46+
3547
->alias('error_renderer.html','error_handler.error_renderer.html')
36-
->alias('error_renderer','error_renderer.html')
48+
->alias('error_renderer.cli','error_handler.error_renderer.cli')
49+
->alias('error_renderer.default','error_handler.error_renderer.default')
50+
->alias('error_renderer','error_renderer.default')
3751
;
3852
};

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
inline_service()
215215
->factory([SerializerErrorRenderer::class,'getPreferredFormat'])
216216
->args([service('request_stack')]),
217-
service('error_renderer.html'),
217+
service('error_renderer.default'),
218218
inline_service()
219219
->factory([HtmlErrorRenderer::class,'isDebug'])
220220
->args([service('request_stack'),param('kernel.debug')]),

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ApiAttributesTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public static function mapRequestPayloadProvider(): iterable
337337
'format' =>'dummy',
338338
'parameters' => [],
339339
'content' =>'Hello',
340-
'expectedResponse' =>'415UnsupportedMedia Type',
340+
'expectedResponse' =>'Unsupportedformat',
341341
'expectedStatusCode' =>415,
342342
];
343343

@@ -578,7 +578,7 @@ public static function mapRequestPayloadProvider(): iterable
578578
'format' =>'dummy',
579579
'parameters' => [],
580580
'content' =>'Hello',
581-
'expectedResponse' =>'415UnsupportedMedia Type',
581+
'expectedResponse' =>'Unsupportedformat',
582582
'expectedStatusCode' =>415,
583583
];
584584

@@ -824,7 +824,7 @@ public static function mapRequestPayloadProvider(): iterable
824824
'format' =>'dummy',
825825
'parameters' => [],
826826
'content' =>'Hello',
827-
'expectedResponse' =>'415UnsupportedMedia Type',
827+
'expectedResponse' =>'Unsupportedformat',
828828
'expectedStatusCode' =>415,
829829
];
830830

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bundle\FrameworkBundle\Tests\Functional;
13+
14+
class ErrorHandlerWebTestCaseextends AbstractWebTestCase
15+
{
16+
publicfunctiontestNonHtmlErrorResponseOnCliContext()
17+
{
18+
$client =self::createClient(['test_case' =>'ErrorHandler','root_config' =>'config.yml','debug' =>false]);
19+
$client->request('GET','/_error/500.html');
20+
21+
self::assertResponseStatusCodeSame(500,$client->getResponse()->getStatusCode());
22+
self::assertStringNotContainsString('<!DOCTYPE html>',$client->getResponse()->getContent());
23+
self::assertStringContainsString('This is a sample exception.',$client->getResponse()->getContent());
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
useSymfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
14+
return [
15+
newFrameworkBundle(),
16+
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
imports:
2+
-{ resource: ../config/default.yml }
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_errors:
2+
resource:"@FrameworkBundle/Resources/config/routing/errors.xml"
3+
prefix:/_error

‎src/Symfony/Component/ErrorHandler/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add`error:dump` command
8+
* Add`SapiErrorRendererSelector` to select the proper error renderer based on the current`PHP_SAPI`
89

910
7.1
1011
---
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\ErrorHandler\ErrorRenderer;
13+
14+
/**
15+
* @author Yonel Ceruto <open@yceruto.dev>
16+
*
17+
* @internal
18+
*/
19+
finalclass SapiErrorRendererSelector
20+
{
21+
publicstaticfunctionselect(ErrorRendererInterface$cliErrorRenderer,ErrorRendererInterface$htmlErrorRenderer):ErrorRendererInterface
22+
{
23+
return\in_array(\PHP_SAPI, ['cli','phpdbg','embed'],true) ?$cliErrorRenderer :$htmlErrorRenderer;
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp