# Class HttpSoft\Response\EmptyResponse

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

Implementation of Psr\Http\Message\ResponseInterface for easy creation an instance of a response with an empty body.

Source code on GitHub.

use HttpSoft\Response\EmptyResponse;

$response = new EmptyResponse();
$response->getStatusCode(); // 204
$response->getReasonPhrase(); // 'No Content'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // []
$response->getProtocolVersion(); // '1.1'

$response = new EmptyResponse(201, ['Link' => '<https://example.com>; rel="preconnect"'], '2');
$response->getStatusCode(); // 201
$response->getReasonPhrase(); // 'Created'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Link' => ['<https://example.com>; rel="preconnect"']]
$response->getProtocolVersion(); // '2'

$response = new EmptyResponse(EmptyResponse::STATUS_ACCEPTED);
$response->getStatusCode(); // 202
$response->getReasonPhrase(); // 'Accepted'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // []
$response->getProtocolVersion(); // '1.1'

$newResponse = $response->withStatus(EmptyResponse::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'

// When trying to writing content, the `\InvalidArgumentException` exception will be thrown:
$response->getBody()->write('Content'); // throws InvalidArgumentException

# Public methods

See the original detailed description of the methods in the Psr\Http\Message\ResponseInterface.

/**
 * @param int $code
 * @param array $headers
 * @param string $protocol
 * @param string $reasonPhrase
 */
public function __construct(
    int $code = self::STATUS_NO_CONTENT,
    array $headers = [],
    string $protocol = '1.1',
    string $reasonPhrase = ''
);

All other methods with descriptions are in the used traits: