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;
17 * Produce a redirect response.
19 class RedirectResponse extends Response
22 * Create a redirect response.
24 * Produces a redirect response with a Location header and the given status
27 * Note: this method overwrites the `location` $headers value.
29 * @param string|UriInterface $uri URI for the Location header.
30 * @param int $status Integer status code for the redirect; 302 by default.
31 * @param array $headers Array of headers to use at initialization.
33 public function __construct($uri, $status = 302, array $headers = [])
35 if (! is_string($uri) && ! $uri instanceof UriInterface) {
36 throw new InvalidArgumentException(sprintf(
37 'Uri provided to %s MUST be a string or Psr\Http\Message\UriInterface instance; received "%s"',
39 (is_object($uri) ? get_class($uri) : gettype($uri))
43 $headers['location'] = [(string) $uri];
44 parent::__construct('php://temp', $status, $headers);