\GuzzleHttpPsr7

Traits

MessageTrait Trait implementing functionality common to requests and responses.
StreamDecoratorTrait Stream decorator trait

Classes

AppendStream Reads from multiple streams, one after the other.
BufferStream Provides a buffer stream that can be written to to fill a buffer, and read from to remove bytes from the buffer.
CachingStream Stream decorator that can cache previously read bytes from a sequentially read stream.
DroppingStream Stream decorator that begins dropping data once the size of the underlying stream becomes too full.
FnStream Compose stream implementations based on a hash of functions.
InflateStream Uses PHP's zlib.inflate filter to inflate deflate or gzipped content.
LazyOpenStream Lazily reads or writes to a file that is opened only after an IO operation take place on the stream.
LimitStream Decorator used to return only a subset of a stream
MultipartStream Stream that when read returns bytes for a streaming multipart or multipart/form-data stream.
NoSeekStream Stream decorator that prevents a stream from being seeked
PumpStream Provides a read only stream that pumps data from a PHP callable.
Request PSR-7 request implementation.
Response PSR-7 response implementation.
Rfc7230
ServerRequest Server-side HTTP request
Stream PHP stream implementation.
StreamWrapper Converts Guzzle streams into PHP stream resources.
UploadedFile
Uri PSR-7 URI implementation.
UriNormalizer Provides methods to normalize and compare URIs.
UriResolver Resolves a URI reference in the context of a base URI and the opposite way.

Functions

build_query()

build_query(array  $params, integer|false  $encoding = PHP_QUERY_RFC3986) : string

Build a query string from an array of key value pairs.

This function can use the return value of parse_query() to build a query string. This function does not modify the provided keys when an array is encountered (like http_build_query would).

Parameters

array $params

Query string parameters.

integer|false $encoding

Set to false to not encode, PHP_QUERY_RFC3986 to encode using RFC3986, or PHP_QUERY_RFC1738 to encode using RFC1738.

Returns

string

copy_to_stream()

copy_to_stream(\Psr\Http\Message\StreamInterface  $source, \Psr\Http\Message\StreamInterface  $dest, integer  $maxLen = -1) 

Copy the contents of a stream into another stream until the given number of bytes have been read.

Parameters

\Psr\Http\Message\StreamInterface $source

Stream to read from

\Psr\Http\Message\StreamInterface $dest

Stream to write to

integer $maxLen

Maximum number of bytes to read. Pass -1 to read the entire stream.

Throws

\RuntimeException

on error.

copy_to_string()

copy_to_string(\Psr\Http\Message\StreamInterface  $stream, integer  $maxLen = -1) : string

Copy the contents of a stream into a string until the given number of bytes have been read.

Parameters

\Psr\Http\Message\StreamInterface $stream

Stream to read

integer $maxLen

Maximum number of bytes to read. Pass -1 to read the entire stream.

Throws

\RuntimeException

on error.

Returns

string

get_message_body_summary()

get_message_body_summary(\Psr\Http\Message\MessageInterface  $message, integer  $truncateAt = 120) : null|string

Get a short summary of the message body

Will return null if the response is not printable.

Parameters

\Psr\Http\Message\MessageInterface $message

The message to get the body summary

integer $truncateAt

The maximum allowed size of the summary

Returns

null|string

hash()

hash(\Psr\Http\Message\StreamInterface  $stream, string  $algo, boolean  $rawOutput = false) : string

Calculate a hash of a Stream

Parameters

\Psr\Http\Message\StreamInterface $stream

Stream to calculate the hash for

string $algo

Hash algorithm (e.g. md5, crc32, etc)

boolean $rawOutput

Whether or not to use raw output

Throws

\RuntimeException

on error.

Returns

string —

Returns the hash of the stream

mimetype_from_extension()

mimetype_from_extension(  $extension) : string|null

Maps a file extensions to a mimetype.

Parameters

$extension

string The file extension.

Returns

string|null

mimetype_from_filename()

mimetype_from_filename(  $filename) : null|string

Determines the mimetype of a file by looking at its extension.

Parameters

$filename

Returns

null|string

modify_request()

modify_request(\Psr\Http\Message\RequestInterface  $request, array  $changes) : \Psr\Http\Message\RequestInterface

Clone and modify a request with the given changes.

The changes can be one of:

  • method: (string) Changes the HTTP method.
  • set_headers: (array) Sets the given headers.
  • remove_headers: (array) Remove the given headers.
  • body: (mixed) Sets the given body.
  • uri: (UriInterface) Set the URI.
  • query: (string) Set the query string value of the URI.
  • version: (string) Set the protocol version.

Parameters

\Psr\Http\Message\RequestInterface $request

Request to clone and modify.

array $changes

Changes to apply.

Returns

\Psr\Http\Message\RequestInterface

normalize_header()

normalize_header(string|array  $header) : array

Converts an array of header values that may contain comma separated headers into an array of headers with no comma separated values.

Parameters

string|array $header

Header to normalize.

Returns

array —

Returns the normalized header field values.

parse_header()

parse_header(string|array  $header) : array

Parse an array of header values containing ";" separated data into an array of associative arrays representing the header key value pair data of the header. When a parameter does not contain a value, but just contains a key, this function will inject a key with a '' string value.

Parameters

string|array $header

Header to parse into components.

Returns

array —

Returns the parsed header values.

parse_query()

parse_query(string  $str, integer|boolean  $urlEncoding = true) : array

Parse a query string into an associative array.

If multiple values are found for the same key, the value of that key value pair will become an array. This function does not parse nested PHP style arrays into an associative array (e.g., foo[a]=1&foo[b]=2 will be parsed into ['foo[a]' => '1', 'foo[b]' => '2']).

Parameters

string $str

Query string to parse

integer|boolean $urlEncoding

How the query string is encoded

Returns

array

parse_request()

parse_request(string  $message) : \GuzzleHttp\Psr7\Request

Parses a request message string into a request object.

Parameters

string $message

Request message string.

Returns

\GuzzleHttp\Psr7\Request

parse_response()

parse_response(string  $message) : \GuzzleHttp\Psr7\Response

Parses a response message string into a response object.

Parameters

string $message

Response message string.

Returns

\GuzzleHttp\Psr7\Response

readline()

readline(\Psr\Http\Message\StreamInterface  $stream, integer  $maxLength = null) : string

Read a line from the stream up to the maximum allowed buffer length

Parameters

\Psr\Http\Message\StreamInterface $stream

Stream to read from

integer $maxLength

Maximum buffer length

Returns

string

rewind_body()

rewind_body(\Psr\Http\Message\MessageInterface  $message) 

Attempts to rewind a message body and throws an exception on failure.

The body of the message will only be rewound if a call to tell() returns a value other than 0.

Parameters

\Psr\Http\Message\MessageInterface $message

Message to rewind

Throws

\RuntimeException

str()

str(\Psr\Http\Message\MessageInterface  $message) : string

Returns the string representation of an HTTP message.

Parameters

\Psr\Http\Message\MessageInterface $message

Message to convert to a string.

Returns

string

stream_for()

stream_for(resource|string|null|integer|float|boolean|\Psr\Http\Message\StreamInterface|callable|\Iterator  $resource = '', array  $options = array()) : \Psr\Http\Message\StreamInterface

Create a new stream based on the input type.

Options is an associative array that can contain the following keys:

  • metadata: Array of custom metadata.
  • size: Size of the stream.

Parameters

resource|string|null|integer|float|boolean|\Psr\Http\Message\StreamInterface|callable|\Iterator $resource

Entity body data

array $options

Additional options

Throws

\InvalidArgumentException

if the $resource arg is not valid.

Returns

\Psr\Http\Message\StreamInterface

try_fopen()

try_fopen(string  $filename, string  $mode) : resource

Safely opens a PHP stream resource using a filename.

When fopen fails, PHP normally raises a warning. This function adds an error handler that checks for errors and throws an exception instead.

Parameters

string $filename

File to open

string $mode

Mode used to open the file

Throws

\RuntimeException

if the file cannot be opened

Returns

resource

uri_for()

uri_for(string|\Psr\Http\Message\UriInterface  $uri) : \Psr\Http\Message\UriInterface

Returns a UriInterface for the given value.

This function accepts a string or \GuzzleHttp\Psr7\Psr\Http\Message\UriInterface and returns a UriInterface for the given value. If the value is already a UriInterface, it is returned as-is.

Parameters

string|\Psr\Http\Message\UriInterface $uri

Throws

\InvalidArgumentException

Returns

\Psr\Http\Message\UriInterface