1
1
.. index ::
2
2
single: Error
3
3
single: Exception
4
- single: Components; ErrorCatcher
4
+ single: Components; ErrorRenderer
5
5
6
- The ErrorCatcher Component
7
- ==========================
6
+ The ErrorRenderer Component
7
+ ===========================
8
8
9
- The ErrorCatcher component converts PHP errors and exceptions into other
9
+ The ErrorRenderer component converts PHP errors and exceptions into other
10
10
formats such as JSON and HTML and renders them.
11
11
12
12
Installation
13
13
------------
14
14
15
15
.. code-block :: terminal
16
16
17
- $ composer require symfony/error-catcher
17
+ $ composer require symfony/error-renderer
18
18
19
19
.. include :: /components/require_autoload.rst.inc
20
20
21
21
Usage
22
22
-----
23
23
24
- The ErrorCatcher component provides several handlers and renderers to convert
24
+ The ErrorRenderer component provides several handlers and renderers to convert
25
25
PHP errors and exceptions into other formats easier to debug when working with
26
26
HTTP applications.
27
27
@@ -33,12 +33,12 @@ Handling PHP Errors and Exceptions
33
33
Enabling the Error Handler
34
34
~~~~~~~~~~~~~~~~~~~~~~~~~~
35
35
36
- The :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorHandler ` class catches PHP
36
+ The :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorHandler ` class catches PHP
37
37
errors and converts them to exceptions (of class :phpclass: `ErrorException ` or
38
- :class: `Symfony\\ Component\\ ErrorCatcher \\ Exception\\ FatalErrorException ` for
38
+ :class: `Symfony\\ Component\\ ErrorRenderer \\ Exception\\ FatalErrorException ` for
39
39
PHP fatal errors)::
40
40
41
- use Symfony\Component\ErrorCatcher \ErrorHandler;
41
+ use Symfony\Component\ErrorRenderer \ErrorHandler;
42
42
43
43
ErrorHandler::register();
44
44
@@ -48,12 +48,12 @@ application uses the FrameworkBundle because it generates better error logs.
48
48
Enabling the Exception Handler
49
49
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
50
51
- The :class: `Symfony\\ Component\\ ErrorCatcher \\ ExceptionHandler ` class catches
51
+ The :class: `Symfony\\ Component\\ ErrorRenderer \\ ExceptionHandler ` class catches
52
52
uncaught PHP exceptions and converts them to a nice PHP response. It is useful
53
53
in :ref: `debug mode <debug-mode >` to replace the default PHP/XDebug output with
54
54
something prettier and more useful::
55
55
56
- use Symfony\Component\ErrorCatcher \ExceptionHandler;
56
+ use Symfony\Component\ErrorRenderer \ExceptionHandler;
57
57
58
58
ExceptionHandler::register();
59
59
@@ -69,9 +69,9 @@ Rendering PHP Errors and Exceptions
69
69
Another feature provided by this component are the "error renderers", which
70
70
converts PHP errors and exceptions into other formats such as JSON and HTML::
71
71
72
- use Symfony\Component\ErrorCatcher \ErrorRenderer\ErrorRenderer;
73
- use Symfony\Component\ErrorCatcher \ErrorRenderer\HtmlErrorRenderer;
74
- use Symfony\Component\ErrorCatcher \ErrorRenderer\JsonErrorRenderer;
72
+ use Symfony\Component\ErrorRenderer \ErrorRenderer\ErrorRenderer;
73
+ use Symfony\Component\ErrorRenderer \ErrorRenderer\HtmlErrorRenderer;
74
+ use Symfony\Component\ErrorRenderer \ErrorRenderer\JsonErrorRenderer;
75
75
76
76
$renderers = [
77
77
new HtmlErrorRenderer(),
@@ -80,7 +80,7 @@ converts PHP errors and exceptions into other formats such as JSON and HTML::
80
80
];
81
81
$errorFormatter = new ErrorFormatter($renderers);
82
82
83
- /** @var Symfony\Component\ErrorCatcher \Exception\FlattenException */
83
+ /** @var Symfony\Component\ErrorRenderer \Exception\FlattenException */
84
84
$exception = ...;
85
85
/** @var Symfony\Component\HttpFoundation\Request */
86
86
$request = ...;
@@ -96,28 +96,28 @@ Built-in Error Renderers
96
96
97
97
This component provides error renderers for the most common needs:
98
98
99
- * :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorRenderer\\ HtmlErrorRenderer `
99
+ * :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorRenderer\\ HtmlErrorRenderer `
100
100
renders errors in HTML format;
101
- * :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorRenderer\\ JsonErrorRenderer `
101
+ * :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorRenderer\\ JsonErrorRenderer `
102
102
renders errors in JSON format and it's compliant with the `RFC 7807 `_ standard;
103
- * :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorRenderer\\ XmlErrorRenderer `
103
+ * :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorRenderer\\ XmlErrorRenderer `
104
104
renders errors in XML and Atom formats. It's compliant with the `RFC 7807 `_
105
105
standard;
106
- * :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorRenderer\\ TxtErrorRenderer `
106
+ * :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorRenderer\\ TxtErrorRenderer `
107
107
renders errors in plain text format.
108
108
109
109
Adding a Custom Error Renderer
110
110
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
111
112
112
Error renderers are PHP classes that implement the
113
- :class: `Symfony\\ Component\\ ErrorCatcher \\ ErrorRenderer\\ ErrorRendererInterface `.
113
+ :class: `Symfony\\ Component\\ ErrorRenderer \\ ErrorRenderer\\ ErrorRendererInterface `.
114
114
For example, if you need to render errors in `JSON-LD format `_, create this
115
115
class anywhere in your project::
116
116
117
- namespace App\ErrorCatcher ;
117
+ namespace App\ErrorRenderer ;
118
118
119
- use Symfony\Component\ErrorCatcher \ErrorRenderer\ErrorRendererInterface;
120
- use Symfony\Component\ErrorCatcher \Exception\FlattenException;
119
+ use Symfony\Component\ErrorRenderer \ErrorRenderer\ErrorRendererInterface;
120
+ use Symfony\Component\ErrorRenderer \Exception\FlattenException;
121
121
122
122
class JsonLdErrorRenderer implements ErrorRendererInterface
123
123
{
170
170
171
171
# config/services.yaml
172
172
services :
173
- App\ErrorCatcher \JsonLdErrorRenderer :
173
+ App\ErrorRenderer \JsonLdErrorRenderer :
174
174
arguments : ['%kernel.debug%']
175
175
tags : ['error_catcher.renderer']
176
176
184
184
https://symfony.com/schema/dic/services/services-1.0.xsd" >
185
185
186
186
<services >
187
- <service id =" App\ErrorCatcher \JsonLdErrorRenderer" >
187
+ <service id =" App\ErrorRenderer \JsonLdErrorRenderer" >
188
188
<argument >true</argument >
189
189
<tag name =" error_catcher.renderer" />
190
190
</service >
194
194
.. code-block :: php
195
195
196
196
// config/services.php
197
- use App\ErrorCatcher \JsonLdErrorRenderer;
197
+ use App\ErrorRenderer \JsonLdErrorRenderer;
198
198
199
199
$container->register(JsonLdErrorRenderer::class)
200
200
->setArguments([true]);
0 commit comments