composer package updates
[openemr.git] / vendor / zendframework / zend-diactoros / src / Request.php
blob422862ec697906358c092f4ef9d5a66d61723893
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 */
8 namespace Zend\Diactoros;
10 use Psr\Http\Message\RequestInterface;
11 use Psr\Http\Message\StreamInterface;
12 use Psr\Http\Message\UriInterface;
14 use function strtolower;
16 /**
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
25 use RequestTrait;
27 /**
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);
39 /**
40 * {@inheritdoc}
42 public function getHeaders()
44 $headers = $this->headers;
45 if (! $this->hasHeader('host')
46 && $this->uri->getHost()
47 ) {
48 $headers['Host'] = [$this->getHostFromUri()];
51 return $headers;
54 /**
55 * {@inheritdoc}
57 public function getHeader($header)
59 if (! $this->hasHeader($header)) {
60 if (strtolower($header) === 'host'
61 && $this->uri->getHost()
62 ) {
63 return [$this->getHostFromUri()];
66 return [];
69 $header = $this->headerNames[strtolower($header)];
71 return $this->headers[$header];