# Class HttpSoft\Response\TextResponse

Class, that implements Psr\Http\Message\ResponseInterface and HttpSoft\Response\ResponseStatusCodeInterface.

Implementation of Psr\Http\Message\ResponseInterface for easy creation an instance from text plain.

Source code on GitHub.

use HttpSoft\Response\TextResponse;

$response = new TextResponse('Text');
$response->getStatusCode(); // 200
$response->getReasonPhrase(); // 'OK'
$response->getBody()->getContents(); // 'Text'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['text/plain; charset=UTF-8']]
$response->getProtocolVersion(); // '1.1'

$response = new TextResponse('Text', 404, ['Content-Type' => 'text/html; charset=UTF-8'], '2');
$response->getStatusCode(); // 404
$response->getReasonPhrase(); // 'Not Found'
$response->getBody()->getContents(); // 'Text'
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Content-Type' => ['text/html; charset=UTF-8']]
$response->getProtocolVersion(); // '2'

$newResponse = $response->withHeader('Content-Language', 'ru');
$newResponse->getHeaderLine('content-language'); // 'ru'
$response->getHeaders(); // ['Content-Type' => ['text/html; charset=UTF-8'], 'Content-Language' => ['ru']]

$newResponse = $response->withStatus(TextResponse::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 $text
 * @param int $code
 * @param array $headers
 * @param string $protocol
 * @param string $reasonPhrase
 */
public function __construct(
    string $text,
    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/plain; charset=UTF-8' by default.

All other methods with descriptions are in the used traits: