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
8 namespace Zend\Diactoros
;
10 use Psr\Http\Message\RequestInterface
;
11 use Psr\Http\Message\StreamInterface
;
12 use Psr\Http\Message\UriInterface
;
15 * HTTP Request encapsulation
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.
21 class Request
implements RequestInterface
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.
32 public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = [])
34 $this->initialize($uri, $method, $body, $headers);
40 public function getHeaders()
42 $headers = $this->headers
;
43 if (! $this->hasHeader('host')
44 && $this->uri
->getHost()
46 $headers['Host'] = [$this->getHostFromUri()];
55 public function getHeader($header)
57 if (! $this->hasHeader($header)) {
58 if (strtolower($header) === 'host'
59 && $this->uri
->getHost()
61 return [$this->getHostFromUri()];
67 $header = $this->headerNames
[strtolower($header)];
69 return $this->headers
[$header];