# Class HttpSoft\Response\RedirectResponse

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

Implementation of Psr\Http\Message\ResponseInterface for easy creation an instance with redirection.

Source code on GitHub.

use HttpSoft\Response\RedirectResponse;

// 302 redirect:

$response = new RedirectResponse('https://example.com/path/to/action');
// equivalently to:
$response = new RedirectResponse('https://example.com/path/to/action', RedirectResponse::STATUS_FOUND);

$response->getStatusCode(); // 302
$response->getReasonPhrase(); // 'Found'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Location' => ['https://example.com/path/to/action']]
$response->getProtocolVersion(); // '1.1'

// 301 redirect:

$response = new RedirectResponse('/path/to/action', 301, [], '2');
// equivalently to:
$response = new RedirectResponse('/path/to/action', RedirectResponse::STATUS_MOVED_PERMANENTLY, [], '2');

$response->getStatusCode(); // 301
$response->getReasonPhrase(); // 'Moved Permanently'
$response->getBody()->getContents(); // ''
$response->getBody()->getMetadata('uri') // 'php://temp'
$response->getHeaders(); // ['Location' => ['/path/to/action']]
$response->getProtocolVersion(); // '2'

# Public methods

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

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

All other methods with descriptions are in the used traits: