friendship ended with social-app. php is my new best friend
at main 2.2 kB view raw
1<?php 2 3namespace React\Http\Message; 4 5use Psr\Http\Message\RequestInterface; 6use Psr\Http\Message\StreamInterface; 7use Psr\Http\Message\UriInterface; 8use React\Http\Io\AbstractRequest; 9use React\Http\Io\BufferedBody; 10use React\Http\Io\ReadableBodyStream; 11use React\Stream\ReadableStreamInterface; 12 13/** 14 * Respresents an outgoing HTTP request message. 15 * 16 * This class implements the 17 * [PSR-7 `RequestInterface`](https://www.php-fig.org/psr/psr-7/#32-psrhttpmessagerequestinterface) 18 * which extends the 19 * [PSR-7 `MessageInterface`](https://www.php-fig.org/psr/psr-7/#31-psrhttpmessagemessageinterface). 20 * 21 * This is mostly used internally to represent each outgoing HTTP request 22 * message for the HTTP client implementation. Likewise, you can also use this 23 * class with other HTTP client implementations and for tests. 24 * 25 * > Internally, this implementation builds on top of a base class which is 26 * considered an implementation detail that may change in the future. 27 * 28 * @see RequestInterface 29 */ 30final class Request extends AbstractRequest implements RequestInterface 31{ 32 /** 33 * @param string $method HTTP method for the request. 34 * @param string|UriInterface $url URL for the request. 35 * @param array<string,string|string[]> $headers Headers for the message. 36 * @param string|ReadableStreamInterface|StreamInterface $body Message body. 37 * @param string $version HTTP protocol version. 38 * @throws \InvalidArgumentException for an invalid URL or body 39 */ 40 public function __construct( 41 $method, 42 $url, 43 array $headers = array(), 44 $body = '', 45 $version = '1.1' 46 ) { 47 if (\is_string($body)) { 48 $body = new BufferedBody($body); 49 } elseif ($body instanceof ReadableStreamInterface && !$body instanceof StreamInterface) { 50 $body = new ReadableBodyStream($body); 51 } elseif (!$body instanceof StreamInterface) { 52 throw new \InvalidArgumentException('Invalid request body given'); 53 } 54 55 parent::__construct($method, $url, $headers, $body, $version); 56 } 57}