# Class HttpSoft\Response\HtmlResponse
Class, that implements Psr\Http\Message\ResponseInterface and HttpSoft\Response\ResponseStatusCodeInterface.
Implementation of Psr\Http\Message\ResponseInterface
for easy creation an instance from HTML code.
use HttpSoft\Response\HtmlResponse;
$response = new HtmlResponse('<p>HTML</p>');
$response->getStatusCode(); // 200
$response->getReasonPhrase(); // 'OK'
$response->getBody()->getContents(); // '<p>HTML</p>'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['text/html; charset=UTF-8']]
$response->getProtocolVersion(); // '1.1'
$response = new HtmlResponse('<p>HTML</p>', 404, ['Content-Type' => 'text/plain; charset=UTF-8'], '2');
$response->getStatusCode(); // 404
$response->getReasonPhrase(); // 'Not Found'
$response->getBody()->getContents(); // '<p>HTML</p>'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['text/plain; charset=UTF-8']]
$response->getProtocolVersion(); // '2'
$newResponse = $response->withHeader('Content-Language', 'en');
$newResponse->getHeaderLine('content-language'); // 'en'
$response->getHeaders(); // ['Content-Type' => ['text/plain; charset=UTF-8'], 'Content-Language' => ['en']]
$newResponse = $response->withStatus(HtmlResponse::STATUS_INTERNAL_SERVER_ERROR);
$newResponse->getStatusCode(); // 500
$newResponse->getReasonPhrase(); // 'Internal Server Error'
$newResponse = $response->withStatus(599, 'Custom Phrase');
$newResponse->getStatusCode(); // 599
$newResponse->getReasonPhrase(); // 'Custom Phrase'
# Public methods
See the original detailed description of the methods in the Psr\Http\Message\ResponseInterface.
/**
* @param string $html
* @param int $code
* @param array $headers
* @param string $protocol
* @param string $reasonPhrase
*/
public function __construct(
string $html,
int $code = self::STATUS_OK,
array $headers = [],
string $protocol = '1.1',
string $reasonPhrase = ''
);
If the Content-Type
header is not specified, it will be set value to 'text/html; charset=UTF-8'
by default.
All other methods with descriptions are in the used traits: