\GuzzleHttp\Psr7Utils

Summary

Methods
Properties
Constants
caselessRemove()
copyToStream()
copyToString()
hash()
modifyRequest()
readLine()
streamFor()
tryFopen()
uriFor()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

caselessRemove()

caselessRemove(iterable<string>  $keys, array  $data) : array

Remove the items given by the keys, case insensitively from the data.

Parameters

iterable $keys
array $data

Returns

array —

copyToStream()

copyToStream(\Psr\Http\Message\StreamInterface  $source, \Psr\Http\Message\StreamInterface  $dest, int  $maxLen = -1) : mixed

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

int $maxLen

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

Throws

\RuntimeException

on error.

Returns

mixed —

copyToString()

copyToString(\Psr\Http\Message\StreamInterface  $stream, int  $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

int $maxLen

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

Throws

\RuntimeException

on error.

Returns

string —

hash()

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

Calculate a hash of a stream.

This method reads the entire stream to calculate a rolling hash, based on PHP's hash_init functions.

Parameters

\Psr\Http\Message\StreamInterface $stream

Stream to calculate the hash for

string $algo

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

bool $rawOutput

Whether or not to use raw output

Throws

\RuntimeException

on error.

Returns

string —

Returns the hash of the stream

modifyRequest()

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

Clone and modify a request with the given changes.

This method is useful for reducing the number of clones needed to mutate a message.

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 —

readLine()

readLine(\Psr\Http\Message\StreamInterface  $stream, int|null  $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

int|null $maxLength

Maximum buffer length

Returns

string —

streamFor()

streamFor(resource|string|int|float|bool|\Psr\Http\Message\StreamInterface|callable|\Iterator|null  $resource = '', array  $options = []) : \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.

This method accepts the following $resource types:

  • Psr\Http\Message\StreamInterface: Returns the value as-is.
  • string: Creates a stream object that uses the given string as the contents.
  • resource: Creates a stream object that wraps the given PHP stream resource.
  • Iterator: If the provided value implements Iterator, then a read-only stream object will be created that wraps the given iterable. Each time the stream is read from, data from the iterator will fill a buffer and will be continuously called until the buffer is equal to the requested read size. Subsequent read calls will first read from the buffer and then call next on the underlying iterator until it is exhausted.
  • object with __toString(): If the object has the __toString() method, the object will be cast to a string and then a stream will be returned that uses the string value.
  • NULL: When null is passed, an empty stream object is returned.
  • callable When a callable is passed, a read-only stream object will be created that invokes the given callable. The callable is invoked with the number of suggested bytes to read. The callable can return any number of bytes, but MUST return false when there is no more data to return. The stream object that wraps the callable will invoke the callable until the number of requested bytes are available. Any additional bytes will be buffered and used in subsequent reads.

Parameters

resource|string|int|float|bool|\Psr\Http\Message\StreamInterface|callable|\Iterator|null $resource

Entity body data

array $options

Additional options

Throws

\InvalidArgumentException

if the $resource arg is not valid.

Returns

\Psr\Http\Message\StreamInterface —

tryFopen()

tryFopen(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 —

uriFor()

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

Returns a UriInterface for the given value.

This function accepts a string or 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 —