Final Class Yiisoft\ErrorHandler\ErrorData
| Inheritance | Yiisoft\ErrorHandler\ErrorData |
|---|---|
| Implements | Stringable |
ErrorData stores content and headers that are suitable for adding to response.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ErrorHandler\ErrorData | |
| __toString() | Returns a content to use as response body. | Yiisoft\ErrorHandler\ErrorData |
| addToResponse() | Returns a response with error data. | Yiisoft\ErrorHandler\ErrorData |
Method Details
| public mixed __construct ( string $content, array<string, string|string[]> $headers = [] ) | ||
| $content | string |
The content to use as response body. |
| $headers | array<string, string|string[]> |
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 \Psr\Http\Message\ResponseInterface addToResponse ( \Psr\Http\Message\ResponseInterface $response ) | ||
| $response | \Psr\Http\Message\ResponseInterface |
The response for setting error data. |
| return | \Psr\Http\Message\ResponseInterface |
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;
}
Signup or Login in order to comment.