@@ -21,55 +21,11 @@ Installation
21
21
Usage
22
22
-----
23
23
24
- The ErrorRenderer component provides several handlers and renderers to convert
25
- PHP errors and exceptions into other formats easier to debug when working with
26
- HTTP applications.
24
+ The ErrorRenderer component provides several renderers to convert PHP errors and
25
+ exceptions into other formats such as JSON and HTML easier to debug when working
26
+ with HTTP applications::
27
27
28
- .. TODO: how are these handlers enabled in the app? (Previously: Debug::enable())
29
-
30
- Handling PHP Errors and Exceptions
31
- ----------------------------------
32
-
33
- Enabling the Error Handler
34
- ~~~~~~~~~~~~~~~~~~~~~~~~~~
35
-
36
- The :class: `Symfony\\ Component\\ ErrorRenderer\\ ErrorHandler ` class catches PHP
37
- errors and converts them to exceptions (of class :phpclass: `ErrorException ` or
38
- :class: `Symfony\\ Component\\ ErrorRenderer\\ Exception\\ FatalErrorException ` for
39
- PHP fatal errors)::
40
-
41
- use Symfony\Component\ErrorRenderer\ErrorHandler;
42
-
43
- ErrorHandler::register();
44
-
45
- This error handler is enabled by default in the production environment when the
46
- application uses the FrameworkBundle because it generates better error logs.
47
-
48
- Enabling the Exception Handler
49
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
-
51
- The :class: `Symfony\\ Component\\ ErrorRenderer\\ ExceptionHandler ` class catches
52
- uncaught PHP exceptions and converts them to a nice PHP response. It is useful
53
- in :ref: `debug mode <debug-mode >` to replace the default PHP/XDebug output with
54
- something prettier and more useful::
55
-
56
- use Symfony\Component\ErrorRenderer\ExceptionHandler;
57
-
58
- ExceptionHandler::register();
59
-
60
- .. note ::
61
-
62
- If the :doc: `HttpFoundation component </components/http_foundation >` is
63
- available, the handler uses a Symfony Response object; if not, it falls
64
- back to a regular PHP response.
65
-
66
- Rendering PHP Errors and Exceptions
67
- -----------------------------------
68
-
69
- Another feature provided by this component are the "error renderers", which
70
- converts PHP errors and exceptions into other formats such as JSON and HTML::
71
-
72
- use Symfony\Component\ErrorRenderer\ErrorRenderer\ErrorRenderer;
28
+ use Symfony\Component\ErrorRenderer\ErrorRenderer;
73
29
use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer;
74
30
use Symfony\Component\ErrorRenderer\ErrorRenderer\JsonErrorRenderer;
75
31
@@ -78,15 +34,15 @@ converts PHP errors and exceptions into other formats such as JSON and HTML::
78
34
new JsonErrorRenderer(),
79
35
// ...
80
36
];
81
- $errorFormatter = new ErrorFormatter ($renderers);
37
+ $errorRenderer = new ErrorRenderer ($renderers);
82
38
83
39
/** @var Symfony\Component\ErrorRenderer\Exception\FlattenException */
84
40
$exception = ...;
85
41
/** @var Symfony\Component\HttpFoundation\Request */
86
42
$request = ...;
87
43
88
44
return new Response(
89
- $errorFormatter ->render($exception, $request->getRequestFormat ()),
45
+ $errorRenderer ->render($exception, $request->getPreferredFormat ()),
90
46
$exception->getStatusCode(),
91
47
$exception->getHeaders()
92
48
);
@@ -123,14 +79,14 @@ class anywhere in your project::
123
79
{
124
80
private $debug;
125
81
126
- public static function getFormat(): string
82
+ public function __construct(bool $debug = true)
127
83
{
128
- return 'jsonld' ;
84
+ $this->debug = $debug ;
129
85
}
130
86
131
- public function __construct(bool $debug = true)
87
+ public static function getFormat(): string
132
88
{
133
- $this->debug = $debug ;
89
+ return 'jsonld' ;
134
90
}
135
91
136
92
public function render(FlattenException $exception): string
@@ -161,7 +117,7 @@ class anywhere in your project::
161
117
162
118
To enable the new error renderer in the application,
163
119
:ref: `register it as a service <service-container-creating-service >` and
164
- :doc: `tag it </service_container/tags >` with the ``error_catcher .renderer ``
120
+ :doc: `tag it </service_container/tags >` with the ``error_renderer .renderer ``
165
121
tag.
166
122
167
123
.. configuration-block ::
172
128
services :
173
129
App\ErrorRenderer\JsonLdErrorRenderer :
174
130
arguments : ['%kernel.debug%']
175
- tags : ['error_catcher .renderer']
131
+ tags : ['error_renderer .renderer']
176
132
177
133
.. code-block :: xml
178
134
186
142
<services >
187
143
<service id =" App\ErrorRenderer\JsonLdErrorRenderer" >
188
144
<argument >true</argument >
189
- <tag name =" error_catcher .renderer" />
145
+ <tag name =" error_renderer .renderer" />
190
146
</service >
191
147
</services >
192
148
</container >
198
154
199
155
$container->register(JsonLdErrorRenderer::class)
200
156
->setArguments([true]);
201
- ->addTag('error_catcher .renderer');
157
+ ->addTag('error_renderer .renderer');
202
158
203
159
.. _`RFC 7807` : https://tools.ietf.org/html/rfc7807
204
160
.. _`JSON-LD format` : https://en.wikipedia.org/wiki/JSON-LD
0 commit comments