src/RequestTrait.php
private function initialize($uri = null, $method = null, $body = 'php://memory', array $headers = [])
    {
        if (! $uri instanceof UriInterface && ! is_string($uri) && null !== $uri) {
            throw new InvalidArgumentException(
                'Invalid URI provided; must be null, a string, or a Psr\Http\Message\UriInterface instance'
            );
        }

        $this->validateMethod($method);

        if (! is_string($body) && ! is_resource($body) && ! $body instanceof StreamInterface) {
            throw new InvalidArgumentException(
                'Body must be a string stream resource identifier, '
                . 'an actual stream resource, '
                . 'or a Psr\Http\Message\StreamInterface implementation'
            );
        }

        if (is_string($uri)) {
            $uri = new Uri($uri);
        }

        $this->method = $method;
        $this->uri    = $uri;
        $this->stream = ($body instanceof StreamInterface) ? $body : new Stream($body, 'r');

        list($this->headerNames, $headers) = $this->filterHeaders($headers);
        $this->assertHeaders($headers);
        $this->headers = $headers;
    }
private function initialize($uri = null, $method = null, $body = 'php://memory', array $headers = [])
    {
        if (! $uri instanceof UriInterface && ! is_string($uri) && null !== $uri) {
            throw new InvalidArgumentException(
                'Invalid URI provided; must be null, a string, or a Psr\Http\Message\UriInterface instance'
            );
        }

        $this->validateMethod($method);

        if (! is_string($body) && ! is_resource($body) && ! $body instanceof StreamInterface) {
            throw new InvalidArgumentException(
                'Body must be a string stream resource identifier, '
                . 'an actual stream resource, '
                . 'or a Psr\Http\Message\StreamInterface implementation'
            );
        }

        if (is_string($uri)) {
            $uri = new Uri($uri);
        }

        $this->method = $method;
        $this->uri    = $uri;
        $this->stream = ($body instanceof StreamInterface) ? $body : new Stream($body, 'r');

        list($this->headerNames, $headers) = $this->filterHeaders($headers);
        $this->assertHeaders($headers);
        $this->headers = $headers;
    }
private function initialize ( $ uri = null , $ method = null , $ body = 'php://memory' , array $ headers = [ ] ) { if ( ! $ uri instanceof UriInterface && ! is_string ( $ uri ) && null !== $ uri ) { throw new InvalidArgumentException ( 'Invalid URI provided; must be null, a string, or a Psr\Http\Message\UriInterface instance' ) ; } $ this -> validateMethod ( $ method ) ; if ( ! is_string ( $ body ) && ! is_resource ( $ body ) && ! $ body instanceof StreamInterface ) { throw new InvalidArgumentException ( 'Body must be a string stream resource identifier, ' . 'an actual stream resource, ' . 'or a Psr\Http\Message\StreamInterface implementation' ) ; } if ( is_string ( $ uri ) ) { $ uri = new Uri ( $ uri ) ; } $ this -> method = $ method ; $ this -> uri = $ uri ; $ this -> stream = ( $ body instanceof StreamInterface ) ? $ body : new Stream ( $ body , 'r' ) ; list ( $ this -> headerNames , $ headers ) = $ this -> filterHeaders ( $ headers ) ; $ this -> assertHeaders ( $ headers ) ; $ this -> headers = $ headers ; }
Initialize request state.

Used by constructors.

@param null|string $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.
Initialize request state .