annotate vendor/zendframework/zend-diactoros/src/Request.php @ 19:fa3358dc1485 tip

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