Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
GuzzleHttp\Psr7\Utils Class Reference

Static Public Member Functions

static caselessRemove (array $keys, array $data)
 
static copyToStream (StreamInterface $source, StreamInterface $dest, int $maxLen=-1)
 Copy the contents of a stream into another stream until the given number of bytes have been read.
 
static copyToString (StreamInterface $stream, int $maxLen=-1)
 Copy the contents of a stream into a string until the given number of bytes have been read.
 
static hash (StreamInterface $stream, string $algo, bool $rawOutput=false)
 Calculate a hash of a stream.
 
static modifyRequest (RequestInterface $request, array $changes)
 Clone and modify a request with the given changes.
 
static readLine (StreamInterface $stream, int $maxLength=null)
 Read a line from the stream up to the maximum allowed buffer length.
 
static streamFor ($resource='', array $options=[])
 Create a new stream based on the input type.
 
static tryFopen (string $filename, string $mode)
 Safely opens a PHP stream resource using a filename.
 
static tryGetContents ($stream)
 Safely gets the contents of a given stream.
 
static uriFor ($uri)
 Returns a UriInterface for the given value.
 

Member Function Documentation

◆ copyToStream()

static GuzzleHttp\Psr7\Utils::copyToStream ( StreamInterface $source,
StreamInterface $dest,
int $maxLen = -1 )
static

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

Parameters
StreamInterface$sourceStream to read from
StreamInterface$destStream to write to
int$maxLenMaximum number of bytes to read. Pass -1 to read the entire stream.
Exceptions
RuntimeExceptionon error.

◆ copyToString()

static GuzzleHttp\Psr7\Utils::copyToString ( StreamInterface $stream,
int $maxLen = -1 )
static

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

Parameters
StreamInterface$streamStream to read
int$maxLenMaximum number of bytes to read. Pass -1 to read the entire stream.
Exceptions
RuntimeExceptionon error.

◆ hash()

static GuzzleHttp\Psr7\Utils::hash ( StreamInterface $stream,
string $algo,
bool $rawOutput = false )
static

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
StreamInterface$streamStream to calculate the hash for
string$algoHash algorithm (e.g. md5, crc32, etc)
bool$rawOutputWhether or not to use raw output
Exceptions
RuntimeExceptionon error.

◆ modifyRequest()

static GuzzleHttp\Psr7\Utils::modifyRequest ( RequestInterface $request,
array $changes )
static

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
RequestInterface$requestRequest to clone and modify.
array$changesChanges to apply.

◆ readLine()

static GuzzleHttp\Psr7\Utils::readLine ( StreamInterface $stream,
int $maxLength = null )
static

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

Parameters
StreamInterface$streamStream to read from
int | null$maxLengthMaximum buffer length

◆ streamFor()

static GuzzleHttp\Psr7\Utils::streamFor ( $resource = '',
array $options = [] )
static

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 | StreamInterface | callable | Iterator | null$resourceEntity body data
array{size?int, metadata?: array} $options Additional options
Exceptions
InvalidArgumentExceptionif the $resource arg is not valid.

◆ tryFopen()

static GuzzleHttp\Psr7\Utils::tryFopen ( string $filename,
string $mode )
static

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$filenameFile to open
string$modeMode used to open the file
Return values
resource
Exceptions
RuntimeExceptionif the file cannot be opened

◆ tryGetContents()

static GuzzleHttp\Psr7\Utils::tryGetContents ( $stream)
static

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.

Parameters
resource$stream
Exceptions
RuntimeExceptionif the stream cannot be read

◆ uriFor()

static GuzzleHttp\Psr7\Utils::uriFor ( $uri)
static

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 | UriInterface$uri
Exceptions
InvalidArgumentException

The documentation for this class was generated from the following file: