Mercurial > hg > cmmr2012-drupal-site
comparison vendor/zendframework/zend-diactoros/src/Request.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children | 5311817fb629 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
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; | |
11 | |
12 use Psr\Http\Message\RequestInterface; | |
13 use Psr\Http\Message\StreamInterface; | |
14 use Psr\Http\Message\UriInterface; | |
15 | |
16 /** | |
17 * HTTP Request encapsulation | |
18 * | |
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. | |
22 */ | |
23 class Request implements RequestInterface | |
24 { | |
25 use RequestTrait; | |
26 | |
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. | |
33 */ | |
34 public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = []) | |
35 { | |
36 $this->initialize($uri, $method, $body, $headers); | |
37 } | |
38 | |
39 /** | |
40 * {@inheritdoc} | |
41 */ | |
42 public function getHeaders() | |
43 { | |
44 $headers = $this->headers; | |
45 if (! $this->hasHeader('host') | |
46 && $this->uri->getHost() | |
47 ) { | |
48 $headers['Host'] = [$this->getHostFromUri()]; | |
49 } | |
50 | |
51 return $headers; | |
52 } | |
53 | |
54 /** | |
55 * {@inheritdoc} | |
56 */ | |
57 public function getHeader($header) | |
58 { | |
59 if (! $this->hasHeader($header)) { | |
60 if (strtolower($header) === 'host' | |
61 && $this->uri->getHost() | |
62 ) { | |
63 return [$this->getHostFromUri()]; | |
64 } | |
65 | |
66 return []; | |
67 } | |
68 | |
69 $header = $this->headerNames[strtolower($header)]; | |
70 | |
71 return $this->headers[$header]; | |
72 } | |
73 } |