Copied!
CloneableFinalInstantiable
Methods
public static caselessRemove(array $keys, array $data) : array
 

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

  • param array<string|int> $keys
public static copyToStream(Psr\Http\Message\StreamInterface $source, Psr\Http\Message\StreamInterface $dest, int $maxLen = -1) : void
 

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

The copy stops if the destination write returns 0, for example a BufferStream at its high water mark or a full DroppingStream. For a guaranteed full copy use a normal writable stream such as a file or php://temp stream.

  • param \StreamInterface $source Stream to read from
  • param \StreamInterface $dest Stream to write to
  • param int $maxLen Maximum number of bytes to read. Pass -1 to read the entire stream.
  • throws \RuntimeException on error.
public static 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.

  • param \StreamInterface $stream Stream to read
  • param int $maxLen Maximum number of bytes to read. Pass -1 to read the entire stream.
  • throws \RuntimeException on error.
public static 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.

  • param \StreamInterface $stream Stream to calculate the hash for
  • param string $algo Hash algorithm (e.g. md5, crc32, etc)
  • param bool $rawOutput Whether or not to use raw output
  • throws \RuntimeException on error.
public static 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. Values must be strings or non-empty arrays of strings.
  • remove_headers: (array) Remove the given headers. Values may be strings or integers.
  • body: (mixed) Sets the given body. Present non-null values are converted with self::streamFor(), including scalar values, resources, streams, iterators, callable arrays, closures, invokable objects, and objects with __toString(). String inputs remain literal bodies.
  • uri: (UriInterface) Set the URI.
  • query: (string) Set the query string value of the URI.
  • version: (string) Set the protocol version.
  • param \RequestInterface $request Request to clone and modify.
  • param array $changes Changes to apply.
public static readLine(Psr\Http\Message\StreamInterface $stream, ?int $maxLength = NULL) : string
 

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

  • param \StreamInterface $stream Stream to read from
  • param int|null $maxLength Maximum buffer length
public static redactUserInfo(Psr\Http\Message\UriInterface $uri) : Psr\Http\Message\UriInterface
 

Redact the password in the user info part of a URI.

public static streamFor( $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 array, closure, or invokable object is passed and no earlier resource or object rule applies, a read-only stream object will be created that invokes the given callable. The callable is invoked with the suggested number of bytes to read. The callable can return fewer or more bytes than requested, but MUST return false or null when there is no more data to return. Any additional bytes will be buffered and used in subsequent reads. String inputs are always treated as string bodies, even when they name callable functions.
  • param resource|string|int|float|bool|\StreamInterface|callable|\Iterator|null $resource Entity body data
  • param array{size?: int, metadata?: array} $options Additional options
  • throws \InvalidArgumentException if the $resource arg is not valid.
public static tryFopen(string $filename, string $mode)
 

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.

  • param string $filename File to open
  • param string $mode Mode used to open the file
  • return resource
  • throws \RuntimeException if the file cannot be opened
public static tryGetContents( $stream) : string
 

Safely gets the contents of a given stream.

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

  • param resource $stream
  • throws \RuntimeException if the stream cannot be read
public static uriFor( $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.

  • param string|\UriInterface $uri
  • throws \InvalidArgumentException
Methods
private static warnOnInvalidModifyRequestChange(string $key, string $expected, $value) : void
 
  • param mixed $value
private static warnOnInvalidModifyRequestChanges(array $changes) : void
 
  • param array<array-key, mixed> $changes
private static writeAll(Psr\Http\Message\StreamInterface $dest, string $buf) : bool
 

Writes the full buffer to the destination, retrying short writes.

Returns false when the destination write returns 0 or less.

Methods
public static caselessRemove(array $keys, array $data) : array
 

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

  • param array<string|int> $keys
public static copyToStream(Psr\Http\Message\StreamInterface $source, Psr\Http\Message\StreamInterface $dest, int $maxLen = -1) : void
 

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

The copy stops if the destination write returns 0, for example a BufferStream at its high water mark or a full DroppingStream. For a guaranteed full copy use a normal writable stream such as a file or php://temp stream.

  • param \StreamInterface $source Stream to read from
  • param \StreamInterface $dest Stream to write to
  • param int $maxLen Maximum number of bytes to read. Pass -1 to read the entire stream.
  • throws \RuntimeException on error.
public static 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.

  • param \StreamInterface $stream Stream to read
  • param int $maxLen Maximum number of bytes to read. Pass -1 to read the entire stream.
  • throws \RuntimeException on error.
public static 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.

  • param \StreamInterface $stream Stream to calculate the hash for
  • param string $algo Hash algorithm (e.g. md5, crc32, etc)
  • param bool $rawOutput Whether or not to use raw output
  • throws \RuntimeException on error.
public static 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. Values must be strings or non-empty arrays of strings.
  • remove_headers: (array) Remove the given headers. Values may be strings or integers.
  • body: (mixed) Sets the given body. Present non-null values are converted with self::streamFor(), including scalar values, resources, streams, iterators, callable arrays, closures, invokable objects, and objects with __toString(). String inputs remain literal bodies.
  • uri: (UriInterface) Set the URI.
  • query: (string) Set the query string value of the URI.
  • version: (string) Set the protocol version.
  • param \RequestInterface $request Request to clone and modify.
  • param array $changes Changes to apply.
public static readLine(Psr\Http\Message\StreamInterface $stream, ?int $maxLength = NULL) : string
 

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

  • param \StreamInterface $stream Stream to read from
  • param int|null $maxLength Maximum buffer length
public static redactUserInfo(Psr\Http\Message\UriInterface $uri) : Psr\Http\Message\UriInterface
 

Redact the password in the user info part of a URI.

public static streamFor( $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 array, closure, or invokable object is passed and no earlier resource or object rule applies, a read-only stream object will be created that invokes the given callable. The callable is invoked with the suggested number of bytes to read. The callable can return fewer or more bytes than requested, but MUST return false or null when there is no more data to return. Any additional bytes will be buffered and used in subsequent reads. String inputs are always treated as string bodies, even when they name callable functions.
  • param resource|string|int|float|bool|\StreamInterface|callable|\Iterator|null $resource Entity body data
  • param array{size?: int, metadata?: array} $options Additional options
  • throws \InvalidArgumentException if the $resource arg is not valid.
public static tryFopen(string $filename, string $mode)
 

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.

  • param string $filename File to open
  • param string $mode Mode used to open the file
  • return resource
  • throws \RuntimeException if the file cannot be opened
public static tryGetContents( $stream) : string
 

Safely gets the contents of a given stream.

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

  • param resource $stream
  • throws \RuntimeException if the stream cannot be read
public static uriFor( $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.

  • param string|\UriInterface $uri
  • throws \InvalidArgumentException
private static warnOnInvalidModifyRequestChange(string $key, string $expected, $value) : void
 
  • param mixed $value
private static warnOnInvalidModifyRequestChanges(array $changes) : void
 
  • param array<array-key, mixed> $changes
private static writeAll(Psr\Http\Message\StreamInterface $dest, string $buf) : bool
 

Writes the full buffer to the destination, retrying short writes.

Returns false when the destination write returns 0 or less.

© 2026 Bruce Wells
Search Namespaces \ Classes
Configuration