3 * Zend Framework (http://framework.zend.com/)
5 * @see http://github.com/zendframework/zend-diactoros for the canonical source repository
6 * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
10 namespace Zend\Diactoros\Response;
12 use InvalidArgumentException;
13 use Psr\Http\Message\UriInterface;
14 use Zend\Diactoros\Response;
16 use function get_class;
18 use function is_object;
19 use function is_string;
23 * Produce a redirect response.
25 class RedirectResponse extends Response
28 * Create a redirect response.
30 * Produces a redirect response with a Location header and the given status
33 * Note: this method overwrites the `location` $headers value.
35 * @param string|UriInterface $uri URI for the Location header.
36 * @param int $status Integer status code for the redirect; 302 by default.
37 * @param array $headers Array of headers to use at initialization.
39 public function __construct($uri, $status = 302, array $headers = [])
41 if (! is_string($uri) && ! $uri instanceof UriInterface) {
42 throw new InvalidArgumentException(sprintf(
43 'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
45 (is_object($uri) ? get_class($uri) : gettype($uri))
49 $headers['location'] = [(string) $uri];
50 parent::__construct('php://temp', $status, $headers);