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;
12 use Psr\Http\Message\RequestInterface;
13 use Psr\Http\Message\StreamInterface;
14 use Psr\Http\Message\UriInterface;
17 * HTTP Request encapsulation
19 * Requests are considered immutable; all methods that might change state are
20 * implemented such that they retain the internal state of the current
21 * message and return a new instance that contains the changed state.
23 class Request implements RequestInterface
28 * @param null|string|UriInterface $uri URI for the request, if any.
29 * @param null|string $method HTTP method for the request, if any.
30 * @param string|resource|StreamInterface $body Message body, if any.
31 * @param array $headers Headers for the message, if any.
32 * @throws \InvalidArgumentException for any invalid value.
34 public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = [])
36 $this->initialize($uri, $method, $body, $headers);
42 public function getHeaders()
44 $headers = $this->headers;
45 if (! $this->hasHeader('host')
46 && $this->uri->getHost()
48 $headers['Host'] = [$this->getHostFromUri()];
57 public function getHeader($header)
59 if (! $this->hasHeader($header)) {
60 if (strtolower($header) === 'host'
61 && $this->uri->getHost()
63 return [$this->getHostFromUri()];
69 $header = $this->headerNames[strtolower($header)];
71 return $this->headers[$header];