annotate vendor/zendframework/zend-diactoros/src/Request.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children c2387f117808
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@0 14 /**
Chris@0 15 * HTTP Request encapsulation
Chris@0 16 *
Chris@0 17 * Requests are considered immutable; all methods that might change state are
Chris@0 18 * implemented such that they retain the internal state of the current
Chris@0 19 * message and return a new instance that contains the changed state.
Chris@0 20 */
Chris@0 21 class Request implements RequestInterface
Chris@0 22 {
Chris@0 23 use RequestTrait;
Chris@0 24
Chris@0 25 /**
Chris@0 26 * @param null|string|UriInterface $uri URI for the request, if any.
Chris@0 27 * @param null|string $method HTTP method for the request, if any.
Chris@0 28 * @param string|resource|StreamInterface $body Message body, if any.
Chris@0 29 * @param array $headers Headers for the message, if any.
Chris@0 30 * @throws \InvalidArgumentException for any invalid value.
Chris@0 31 */
Chris@0 32 public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = [])
Chris@0 33 {
Chris@0 34 $this->initialize($uri, $method, $body, $headers);
Chris@0 35 }
Chris@0 36
Chris@0 37 /**
Chris@0 38 * {@inheritdoc}
Chris@0 39 */
Chris@0 40 public function getHeaders()
Chris@0 41 {
Chris@0 42 $headers = $this->headers;
Chris@0 43 if (! $this->hasHeader('host')
Chris@0 44 && $this->uri->getHost()
Chris@0 45 ) {
Chris@0 46 $headers['Host'] = [$this->getHostFromUri()];
Chris@0 47 }
Chris@0 48
Chris@0 49 return $headers;
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * {@inheritdoc}
Chris@0 54 */
Chris@0 55 public function getHeader($header)
Chris@0 56 {
Chris@0 57 if (! $this->hasHeader($header)) {
Chris@0 58 if (strtolower($header) === 'host'
Chris@0 59 && $this->uri->getHost()
Chris@0 60 ) {
Chris@0 61 return [$this->getHostFromUri()];
Chris@0 62 }
Chris@0 63
Chris@0 64 return [];
Chris@0 65 }
Chris@0 66
Chris@0 67 $header = $this->headerNames[strtolower($header)];
Chris@0 68
Chris@0 69 return $this->headers[$header];
Chris@0 70 }
Chris@0 71 }