Documentation

Psr7

Interfaces, Classes and Traits

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.
Header
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.
Message
MimeType
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.
Query
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.
Utils
MessageTrait
Trait implementing functionality common to requests and responses.
StreamDecoratorTrait
Stream decorator trait

Table of Contents

str()  : string
Returns the string representation of an HTTP message.
uri_for()  : UriInterface
Returns a UriInterface for the given value.
stream_for()  : StreamInterface
Create a new stream based on the input type.
parse_header()  : array<string|int, mixed>
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.
normalize_header()  : array<string|int, mixed>
Converts an array of header values that may contain comma separated headers into an array of headers with no comma separated values.
modify_request()  : RequestInterface
Clone and modify a request with the given changes.
rewind_body()  : mixed
Attempts to rewind a message body and throws an exception on failure.
try_fopen()  : resource
Safely opens a PHP stream resource using a filename.
copy_to_string()  : string
Copy the contents of a stream into a string until the given number of bytes have been read.
copy_to_stream()  : mixed
Copy the contents of a stream into another stream until the given number of bytes have been read.
hash()  : string
Calculate a hash of a stream.
readline()  : string
Read a line from the stream up to the maximum allowed buffer length.
parse_request()  : Request
Parses a request message string into a request object.
parse_response()  : Response
Parses a response message string into a response object.
parse_query()  : array<string|int, mixed>
Parse a query string into an associative array.
build_query()  : string
Build a query string from an array of key value pairs.
mimetype_from_filename()  : string|null
Determines the mimetype of a file by looking at its extension.
mimetype_from_extension()  : string|null
Maps a file extensions to a mimetype.
get_message_body_summary()  : string|null
Get a short summary of the message body.

Functions

str()

Returns the string representation of an HTTP message.

str(MessageInterface $message) : string
Parameters
$message : MessageInterface

Message to convert to a string.

Tags
deprecated

str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.

uri_for()

Returns a UriInterface for the given value.

uri_for(string|UriInterface $uri) : UriInterface

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
$uri : string|UriInterface
Tags
throws
InvalidArgumentException
deprecated

uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.

stream_for()

Create a new stream based on the input type.

stream_for([resource|string|int|float|bool|StreamInterface|callable|Iterator|null $resource = '' ][, array<string|int, mixed> $options = [] ]) : StreamInterface

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 : resource|string|int|float|bool|StreamInterface|callable|Iterator|null = ''

Entity body data

$options : array<string|int, mixed> = []

Additional options

Tags
throws
InvalidArgumentException

if the $resource arg is not valid.

deprecated

stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

parse_header()

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.

parse_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
$header : string|array<string|int, mixed>

Header to parse into components.

Tags
deprecated

parse_header will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.

normalize_header()

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

normalize_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
$header : string|array<string|int, mixed>

Header to normalize.

Tags
deprecated

normalize_header will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.

modify_request()

Clone and modify a request with the given changes.

modify_request(RequestInterface $request, array<string|int, mixed> $changes) : RequestInterface

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
$request : RequestInterface

Request to clone and modify.

$changes : array<string|int, mixed>

Changes to apply.

Tags
deprecated

modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.

rewind_body()

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

rewind_body(MessageInterface $message) : mixed

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

Parameters
$message : MessageInterface

Message to rewind

Tags
throws
RuntimeException
deprecated

rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.

try_fopen()

Safely opens a PHP stream resource using a filename.

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

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

Parameters
$filename : string

File to open

$mode : string

Mode used to open the file

Tags
throws
RuntimeException

if the file cannot be opened

deprecated

try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.

copy_to_string()

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

copy_to_string(StreamInterface $stream[, int $maxLen = -1 ]) : string
Parameters
$stream : StreamInterface

Stream to read

$maxLen : int = -1

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

Tags
throws
RuntimeException

on error.

deprecated

copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.

copy_to_stream()

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

copy_to_stream(StreamInterface $source, StreamInterface $dest[, int $maxLen = -1 ]) : mixed
Parameters
$source : StreamInterface

Stream to read from

$dest : StreamInterface

Stream to write to

$maxLen : int = -1

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

Tags
throws
RuntimeException

on error.

deprecated

copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.

hash()

Calculate a hash of a stream.

hash(StreamInterface $stream, string $algo[, bool $rawOutput = false ]) : string

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

Parameters
$stream : StreamInterface

Stream to calculate the hash for

$algo : string

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

$rawOutput : bool = false

Whether or not to use raw output

Tags
throws
RuntimeException

on error.

deprecated

hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.

readline()

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

readline(StreamInterface $stream[, int|null $maxLength = null ]) : string
Parameters
$stream : StreamInterface

Stream to read from

$maxLength : int|null = null

Maximum buffer length

Tags
deprecated

readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.

parse_request()

Parses a request message string into a request object.

parse_request(string $message) : Request
Parameters
$message : string

Request message string.

Tags
deprecated

parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.

parse_response()

Parses a response message string into a response object.

parse_response(string $message) : Response
Parameters
$message : string

Response message string.

Tags
deprecated

parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.

parse_query()

Parse a query string into an associative array.

parse_query(string $str[, int|bool $urlEncoding = true ]) : array<string|int, mixed>

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
$str : string

Query string to parse

$urlEncoding : int|bool = true

How the query string is encoded

Tags
deprecated

parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.

build_query()

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

build_query(array<string|int, mixed> $params[, int|false $encoding = PHP_QUERY_RFC3986 ]) : string

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
$params : array<string|int, mixed>

Query string parameters.

$encoding : int|false = PHP_QUERY_RFC3986

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

Tags
deprecated

build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.

mimetype_from_filename()

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

mimetype_from_filename(string $filename) : string|null
Parameters
$filename : string
Tags
deprecated

mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.

get_message_body_summary()

Get a short summary of the message body.

get_message_body_summary(MessageInterface $message[, int $truncateAt = 120 ]) : string|null

Will return null if the response is not printable.

Parameters
$message : MessageInterface

The message to get the body summary

$truncateAt : int = 120

The maximum allowed size of the summary

Tags
deprecated

get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.

Search results