Final Class Yiisoft\ErrorHandler\RendererProvider\ContentTypeRendererProvider
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
Provides a renderer based on the "Accept" header of the request.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| get() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $container | \ |
|
| $renderers | ?array | |
public function __construct(
private readonly ContainerInterface $container,
?array $renderers = null,
) {
$this->renderers = $renderers ?? [
'application/json' => JsonRenderer::class,
'application/xml' => XmlRenderer::class,
'text/xml' => XmlRenderer::class,
'text/plain' => PlainTextRenderer::class,
'text/html' => HtmlRenderer::class,
'*/*' => HtmlRenderer::class,
];
}
| public ?\ | ||
| $request | \ |
|
public function get(ServerRequestInterface $request): ?ThrowableRendererInterface
{
$rendererClass = $this->selectRendererClass($request);
if ($rendererClass === null) {
return null;
}
/** @var ThrowableRendererInterface */
return $this->container->get($rendererClass);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.