aacc2dd31d5a4bd4c295d04c13890b6a36b68c44
[yaffs-website] / vendor / zendframework / zend-diactoros / src / Request.php
1 <?php
2 /**
3  * @see       https://github.com/zendframework/zend-diactoros for the canonical source repository
4  * @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
5  * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
6  */
7
8 namespace Zend\Diactoros;
9
10 use Psr\Http\Message\RequestInterface;
11 use Psr\Http\Message\StreamInterface;
12 use Psr\Http\Message\UriInterface;
13
14 /**
15  * HTTP Request encapsulation
16  *
17  * Requests are considered immutable; all methods that might change state are
18  * implemented such that they retain the internal state of the current
19  * message and return a new instance that contains the changed state.
20  */
21 class Request implements RequestInterface
22 {
23     use RequestTrait;
24
25     /**
26      * @param null|string|UriInterface $uri URI for the request, if any.
27      * @param null|string $method HTTP method for the request, if any.
28      * @param string|resource|StreamInterface $body Message body, if any.
29      * @param array $headers Headers for the message, if any.
30      * @throws \InvalidArgumentException for any invalid value.
31      */
32     public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = [])
33     {
34         $this->initialize($uri, $method, $body, $headers);
35     }
36
37     /**
38      * {@inheritdoc}
39      */
40     public function getHeaders()
41     {
42         $headers = $this->headers;
43         if (! $this->hasHeader('host')
44             && $this->uri->getHost()
45         ) {
46             $headers['Host'] = [$this->getHostFromUri()];
47         }
48
49         return $headers;
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     public function getHeader($header)
56     {
57         if (! $this->hasHeader($header)) {
58             if (strtolower($header) === 'host'
59                 && $this->uri->getHost()
60             ) {
61                 return [$this->getHostFromUri()];
62             }
63
64             return [];
65         }
66
67         $header = $this->headerNames[strtolower($header)];
68
69         return $this->headers[$header];
70     }
71 }