bce824992f8a46989c66ee705250ae78754a2f7f
[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 /**
17  * Produce a redirect response.
18  */
19 class RedirectResponse extends Response
20 {
21     /**
22      * Create a redirect response.
23      *
24      * Produces a redirect response with a Location header and the given status
25      * (302 by default).
26      *
27      * Note: this method overwrites the `location` $headers value.
28      *
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.
32      */
33     public function __construct($uri, $status = 302, array $headers = [])
34     {
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"',
38                 __CLASS__,
39                 (is_object($uri) ? get_class($uri) : gettype($uri))
40             ));
41         }
42
43         $headers['location'] = [(string) $uri];
44         parent::__construct('php://temp', $status, $headers);
45     }
46 }