Mercurial > hg > isophonics-drupal-site
diff vendor/zendframework/zend-diactoros/src/Request.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 7a779792577d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/zendframework/zend-diactoros/src/Request.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,73 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @see http://github.com/zendframework/zend-diactoros for the canonical source repository + * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License + */ + +namespace Zend\Diactoros; + +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UriInterface; + +/** + * HTTP Request encapsulation + * + * Requests are considered immutable; all methods that might change state are + * implemented such that they retain the internal state of the current + * message and return a new instance that contains the changed state. + */ +class Request implements RequestInterface +{ + use RequestTrait; + + /** + * @param null|string|UriInterface $uri URI for the request, if any. + * @param null|string $method HTTP method for the request, if any. + * @param string|resource|StreamInterface $body Message body, if any. + * @param array $headers Headers for the message, if any. + * @throws \InvalidArgumentException for any invalid value. + */ + public function __construct($uri = null, $method = null, $body = 'php://temp', array $headers = []) + { + $this->initialize($uri, $method, $body, $headers); + } + + /** + * {@inheritdoc} + */ + public function getHeaders() + { + $headers = $this->headers; + if (! $this->hasHeader('host') + && $this->uri->getHost() + ) { + $headers['Host'] = [$this->getHostFromUri()]; + } + + return $headers; + } + + /** + * {@inheritdoc} + */ + public function getHeader($header) + { + if (! $this->hasHeader($header)) { + if (strtolower($header) === 'host' + && $this->uri->getHost() + ) { + return [$this->getHostFromUri()]; + } + + return []; + } + + $header = $this->headerNames[strtolower($header)]; + + return $this->headers[$header]; + } +}