-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[ErrorRenderer] Refactor and delegate serializing responsibility to the Serializer component #34288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -18,7 +18,6 @@ Console | |||
Debug | ||||
----- | ||||
|
||||
* Deprecated the `Debug` class, use the one from the `ErrorRenderer` component instead | ||||
* Deprecated the `FlattenException` class, use the one from the `ErrorRenderer` component instead | ||||
* Deprecated the component in favor of the `ErrorHandler` component | ||||
|
||||
|
@@ -307,45 +306,35 @@ TwigBundle | |||
* Deprecated all built-in error templates, use the error renderer mechanism of the `ErrorRenderer` component | ||||
* Deprecated loading custom error templates in non-html formats. Custom HTML error pages based on Twig keep working as before: | ||||
|
||||
Before (`templates/bundles/TwigBundle/Exception/error.jsonld.twig`): | ||||
Before (`templates/bundles/TwigBundle/Exception/error.json.twig`): | ||||
```twig | ||||
{ | ||||
"@id": "https://example.com", | ||||
"@type": "error", | ||||
"@context": { | ||||
"title": "{{ status_text }}", | ||||
"code": {{ status_code }}, | ||||
"message": "{{ exception.message }}" | ||||
} | ||||
"type": "https://example.com/error", | ||||
"title": "{{ status_text }}", | ||||
"status": {{ status_code }} | ||||
} | ||||
``` | ||||
|
||||
After (`App\ErrorRenderer\JsonLdErrorRenderer`): | ||||
After (`App\Serializer\ProblemJsonNormalizer`): | ||||
```php | ||||
class JsonLdErrorRenderer implements ErrorRendererInterface | ||||
class ProblemJsonNormalizer implements NormalizerInterface | ||||
{ | ||||
public static function getFormat(): string | ||||
public function normalize($exception, $format = null, array $context = []) | ||||
{ | ||||
return 'jsonld'; | ||||
return [ | ||||
'type' => 'https://example.com/error', | ||||
'title' => $exception->getStatusText(), | ||||
'status' => $exception->getStatusCode(), | ||||
]; | ||||
} | ||||
|
||||
public function render(FlattenException $exception): string | ||||
public function supportsNormalization($data, $format = null) | ||||
{ | ||||
return json_encode([ | ||||
'@id' => 'https://example.com', | ||||
'@type' => 'error', | ||||
'@context' => [ | ||||
'title' => $exception->getTitle(), | ||||
'code' => $exception->getStatusCode(), | ||||
'message' => $exception->getMessage(), | ||||
], | ||||
]); | ||||
return 'json' === $format && $data instanceof FlattenException; | ||||
} | ||||
} | ||||
``` | ||||
|
||||
Configure your rendering service tagging it with `error_renderer.renderer`. | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed from: symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php Line 35 in d5ba535
|
||||
|
||||
Validator | ||||
--------- | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,6 @@ Console | |
Debug | ||
----- | ||
|
||
* Removed the `Debug` class, use the one from the `ErrorRenderer` component instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
* Removed the `FlattenException` class, use the one from the `ErrorRenderer` component instead | ||
* Removed the component in favor of the `ErrorHandler` component | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Configures the Twig-based HTML error renderer. | ||
* | ||
* @author Yonel Ceruto <yonelceruto@gmail.com> | ||
*/ | ||
final class ErrorRendererPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$container->getDefinition('error_renderer')->setArgument(0, new Reference('twig.error_renderer.html')); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[duplicated] the whole component is deprecated (mentioned two lines bellow)