Final Class Yiisoft\ErrorHandler\ErrorData
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Stringable |
ErrorData stores content and headers that are suitable for adding to response.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| __toString() | Returns a content to use as response body. | Yiisoft\ |
| addToResponse() | Returns a response with error data. | Yiisoft\ |
Method Details
| public mixed __construct ( string $content, array | ||
| $content | string |
The content to use as response body. |
| $headers | array |
The headers to add to the response. |
public function __construct(
private readonly string $content,
private readonly array $headers = [],
) {}
Returns a content to use as response body.
| public string __toString ( ) | ||
| return | string |
The content to use as response body. |
|---|---|---|
public function __toString(): string
{
return $this->content;
}
Returns a response with error data.
| public \ | ||
| $response | \ |
The response for setting error data. |
| return | \ |
The response with error data. |
|---|---|---|
public function addToResponse(ResponseInterface $response): ResponseInterface
{
foreach ($this->headers as $name => $value) {
$response = $response->withHeader($name, $value);
}
$response
->getBody()
->write($this->content);
return $response;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.