2015-08-27 12:03:05 -07:00
< ? php
/**
* Zend Framework ( http :// framework . zend . com / )
*
* @ see http :// github . com / zendframework / zend - diactoros for the canonical source repository
2017-04-13 15:53:35 +01:00
* @ copyright Copyright ( c ) 2015 - 2016 Zend Technologies USA Inc . ( http :// www . zend . com )
2015-08-27 12:03:05 -07:00
* @ 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 ;
2017-04-13 15:53:35 +01:00
use Psr\Http\Message\UriInterface ;
2015-08-27 12:03:05 -07:00
/**
* 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
{
2017-04-13 15:53:35 +01:00
use RequestTrait ;
2015-08-27 12:03:05 -07:00
/**
2017-04-13 15:53:35 +01:00
* @ param null | string | UriInterface $uri URI for the request , if any .
2015-08-27 12:03:05 -07:00
* @ 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' )
2017-04-13 15:53:35 +01:00
&& $this -> uri -> getHost ()
2015-08-27 12:03:05 -07:00
) {
$headers [ 'Host' ] = [ $this -> getHostFromUri ()];
}
return $headers ;
}
/**
* { @ inheritdoc }
*/
public function getHeader ( $header )
{
if ( ! $this -> hasHeader ( $header )) {
if ( strtolower ( $header ) === 'host'
2017-04-13 15:53:35 +01:00
&& $this -> uri -> getHost ()
2015-08-27 12:03:05 -07:00
) {
return [ $this -> getHostFromUri ()];
}
return [];
}
$header = $this -> headerNames [ strtolower ( $header )];
2017-04-13 15:53:35 +01:00
return $this -> headers [ $header ];
2015-08-27 12:03:05 -07:00
}
}