@@ -21,55 +21,11 @@ Installation
2121Usage
2222-----
2323
24- The ErrorRenderer component provides severalhandlers 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 formatssuch as JSON and HTML easier to debug when working
26+ with HTTP applications::
2727
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;
7329 use Symfony\Component\ErrorRenderer\ErrorRenderer\HtmlErrorRenderer;
7430 use Symfony\Component\ErrorRenderer\ErrorRenderer\JsonErrorRenderer;
7531
@@ -78,15 +34,15 @@ converts PHP errors and exceptions into other formats such as JSON and HTML::
7834 new JsonErrorRenderer(),
7935 // ...
8036 ];
81- $errorFormatter = newErrorFormatter ($renderers);
37+ $errorRenderer = newErrorRenderer ($renderers);
8238
8339 /** @var Symfony\Component\ErrorRenderer\Exception\FlattenException */
8440 $exception = ...;
8541 /** @var Symfony\Component\HttpFoundation\Request */
8642 $request = ...;
8743
8844 return new Response(
89- $errorFormatter ->render($exception, $request->getRequestFormat ()),
45+ $errorRenderer ->render($exception, $request->getPreferredFormat ()),
9046 $exception->getStatusCode(),
9147 $exception->getHeaders()
9248 );
@@ -123,14 +79,14 @@ class anywhere in your project::
12379 {
12480 private $debug;
12581
126- publicstatic functiongetFormat(): string
82+ public function__construct(bool $debug = true)
12783 {
128- return 'jsonld' ;
84+ $this->debug = $debug ;
12985 }
13086
131- public function__construct(bool $debug = true)
87+ publicstatic functiongetFormat(): string
13288 {
133- $this->debug = $debug ;
89+ return 'jsonld' ;
13490 }
13591
13692 public function render(FlattenException $exception): string
@@ -161,7 +117,7 @@ class anywhere in your project::
161117
162118To enable the new error renderer in the application,
163119: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 ``
165121tag.
166122
167123..configuration-block ::
172128services :
173129App\ErrorRenderer\JsonLdErrorRenderer :
174130arguments :['%kernel.debug%']
175- tags :['error_catcher .renderer']
131+ tags :['error_renderer .renderer']
176132
177133 ..code-block ::xml
178134
186142 <services >
187143 <service id =" App\ErrorRenderer\JsonLdErrorRenderer" >
188144 <argument >true</argument >
189- <tag name =" error_catcher .renderer" />
145+ <tag name =" error_renderer .renderer" />
190146 </service >
191147 </services >
192148 </container >
198154
199155 $container->register(JsonLdErrorRenderer::class)
200156 ->setArguments([true]);
201- ->addTag('error_catcher .renderer');
157+ ->addTag('error_renderer .renderer');
202158
203159 .. _`RFC 7807` :https://tools.ietf.org/html/rfc7807
204160.. _`JSON-LD format` :https://en.wikipedia.org/wiki/JSON-LD