800428cdb1f900dd6dfffabb35d23934ace4c540
[yaffs-website] / src / Response / RedirectResponse.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
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
8  */
9
10 namespace Zend\Diactoros\Response;
11
12 use InvalidArgumentException;
13 use Psr\Http\Message\UriInterface;
14 use Zend\Diactoros\Response;
15
16 use function get_class;
17 use function gettype;
18 use function is_object;
19 use function is_string;
20 use function sprintf;
21
22 /**
23  * Produce a redirect response.
24  */
25 class RedirectResponse extends Response
26 {
27     /**
28      * Create a redirect response.
29      *
30      * Produces a redirect response with a Location header and the given status
31      * (302 by default).
32      *
33      * Note: this method overwrites the `location` $headers value.
34      *
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.
38      */
39     public function __construct($uri, $status = 302, array $headers = [])
40     {
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"',
44                 __CLASS__,
45                 (is_object($uri) ? get_class($uri) : gettype($uri))
46             ));
47         }
48
49         $headers['location'] = [(string) $uri];
50         parent::__construct('php://temp', $status, $headers);
51     }
52 }