public function createRequest(string $method,
                                  $uri,
                                  array $headers = [],
                                  $body = null,
                                  $protocolVersion = '1.1'): RequestInterface
    {
        $request = new Request($method, $this->createUri($uri));

        // Headers ?
        if (!empty($headers)) {
            $request = $request->withHeaders($headers);
        }

        // Body ?
        if (!is_null($body)) {
            if ($body instanceof StreamInterface) {
                $request = $request->withBody($body);
            }

            if (is_resource($body)) {
                $request = $request->withBody($this->createStreamFromResource($body));
            }

            if (is_string($body)) {
                $request = $request->withBody($this->createStream($body));
            }
        }

        // Protocol version ?
        if ($protocolVersion != $request->getProtocolVersion()) {
            $request = $request->withProtocolVersion($protocolVersion);
        }

        return $request;
    }
public function createRequest(string $method,
                                  $uri,
                                  array $headers = [],
                                  $body = null,
                                  $protocolVersion = '1.1'): RequestInterface
    {
        $request = new Request($method, $this->createUri($uri));

        // Headers ?
        if (!empty($headers)) {
            $request = $request->withHeaders($headers);
        }

        // Body ?
        if (!is_null($body)) {
            if ($body instanceof StreamInterface) {
                $request = $request->withBody($body);
            }

            if (is_resource($body)) {
                $request = $request->withBody($this->createStreamFromResource($body));
            }

            if (is_string($body)) {
                $request = $request->withBody($this->createStream($body));
            }
        }

        // Protocol version ?
        if ($protocolVersion != $request->getProtocolVersion()) {
            $request = $request->withProtocolVersion($protocolVersion);
        }

        return $request;
    }
public function createRequest ( string $ method , $ uri , array $ headers = [ ] , $ body = null , $ protocolVersion = '1.1' ) : RequestInterface { $ request = new Request ( $ method , $ this -> createUri ( $ uri ) ) ; // Headers ? if ( ! empty ( $ headers ) ) { $ request = $ request -> withHeaders ( $ headers ) ; } // Body ? if ( ! is_null ( $ body ) ) { if ( $ body instanceof StreamInterface ) { $ request = $ request -> withBody ( $ body ) ; } if ( is_resource ( $ body ) ) { $ request = $ request -> withBody ( $ this -> createStreamFromResource ( $ body ) ) ; } if ( is_string ( $ body ) ) { $ request = $ request -> withBody ( $ this -> createStream ( $ body ) ) ; } } // Protocol version ? if ( $ protocolVersion != $ request -> getProtocolVersion ( ) ) { $ request = $ request -> withProtocolVersion ( $ protocolVersion ) ; } return $ request ; }
Create a new request.

@param string                               $method The HTTP method associated with the request.
@param UriInterface|string                  $uri    The URI associated with the request.
@param array                                $headers
@param resource|string|StreamInterface|null $body
@param string                               $protocolVersion

@return \Psr\Http\Message\RequestInterface
Create a new request .