Skip to content

Commit d48e00e

Browse files
committed
readme
1 parent 35e673e commit d48e00e

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ For more information about creating your own renders and examples of rendering e
122122

123123
### Using a factory to create a response
124124

125-
`Yiisoft\ErrorHandler\Factory\ThrowableResponseFactory` renders `Throwable` object and produces a response according to the content type provided by the client.
125+
`Yiisoft\ErrorHandler\ThrowableResponseFactory` renders `Throwable` object and produces a response according to the content type provided by the client.
126126

127127
```php
128-
use Yiisoft\ErrorHandler\Factory\ThrowableResponseFactory;
128+
use Yiisoft\ErrorHandler\RendererProvider;
129+
use Yiisoft\ErrorHandler\ThrowableResponseFactory;
129130

130131
/**
131132
* @var \Throwable $throwable
@@ -135,27 +136,27 @@ use Yiisoft\ErrorHandler\Factory\ThrowableResponseFactory;
135136
* @var \Yiisoft\ErrorHandler\ErrorHandler $errorHandler
136137
*/
137138

138-
$throwableResponseFactory = new ThrowableResponseFactory($responseFactory, $errorHandler, $container);
139+
$throwableResponseFactory = new ThrowableResponseFactory(
140+
$responseFactory,
141+
$errorHandler,
142+
new RendererProvider\CompositeRendererProvider(
143+
new RendererProvider\HeadRendererProvider(),
144+
new RendererProvider\ContentTypeRendererProvider($container),
145+
),
146+
);
139147

140148
// Creating an instance of the `Psr\Http\Message\ResponseInterface` with error information.
141149
$response = $throwableResponseFactory->create($throwable, $request);
142150
```
143151

144-
`Yiisoft\ErrorHandler\Factory\ThrowableResponseFactory` chooses how to render an exception based on accept HTTP header.
145-
If it's `text/html` or any unknown content type, it will use the error or exception HTML template to display errors.
146-
For other mime types, the error handler will choose different renderer that is registered within the error catcher.
147-
By default, JSON, XML and plain text are supported. You can change this behavior as follows:
152+
`Yiisoft\ErrorHandler\ThrowableResponseFactory` chooses how to render an exception by renderer provider. Providers
153+
available out of the box:
148154

149-
```php
150-
// Returns a new instance without renderers by the specified content types.
151-
$throwableResponseFactory = $throwableResponseFactory->withoutRenderers('application/xml', 'text/xml');
152-
153-
// Returns a new instance with the specified content type and renderer class.
154-
$throwableResponseFactory = $throwableResponseFactory->withRenderer('my/format', new MyRenderer());
155-
156-
// Returns a new instance with the specified force content type to respond with regardless of request.
157-
$throwableResponseFactory = $throwableResponseFactory->forceContentType('application/json');
158-
```
155+
- `HeadRendererProvider` - renders error into HTTP headers. It is used for HEAD requests.
156+
- `ContentTypeRendererProvider` - renders error based on accept HTTP header. By default, JSON, XML and plain text are
157+
supported.
158+
- `ClosureRendererProvider` - allows you to create your own renderer provider using closures.
159+
- `CompositeRendererProvider` - allows you to combine several renderer providers.
159160

160161
### Using a middleware for catching unhandled errors
161162

0 commit comments

Comments
 (0)