0 follower

Final Class Yiisoft\ErrorHandler\ErrorData

InheritanceYiisoft\ErrorHandler\ErrorData
ImplementsStringable

ErrorData stores content and headers that are suitable for adding to response.

Public Methods

Hide inherited 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

Hide inherited methods

__construct() public method

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 = [],
) {
}

            
__toString() public method

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;
}

            
addToResponse() public method

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;
}