Psr7
Table of Contents
Namespaces
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.
- Header
- HttpFactory
- Implements all of the PSR-17 interfaces.
- InflateStream
- Uses PHP's zlib.inflate filter to inflate zlib (HTTP deflate, RFC1950) or gzipped (RFC1952) 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.
- ServerRequest
- Server-side HTTP request
- Stream
- PHP stream implementation.
- StreamWrapper
- Converts Guzzle streams into PHP stream resources.
- UploadedFile
- Uri
- PSR-7 URI implementation.
- UriComparator
- Provides methods to determine if a modified URL should be considered cross-origin.
- 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
- 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.
Traits
- MessageTrait
- Trait implementing functionality common to requests and responses.
- StreamDecoratorTrait
- Stream decorator trait
Functions
- 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.
- 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 will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
str(MessageInterface $message) : string
Parameters
- $message : MessageInterface
-
Message to convert to a string.
Return values
stringuri_for()
Returns a UriInterface for the given value.
uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
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
Return values
UriInterfacestream_for()
Create a new stream based on the input type.
stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
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 implementsIterator
, 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 callnext
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
: Whennull
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 returnfalse
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
Return values
StreamInterfaceparse_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 will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
parse_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
- $header : string|array<string|int, mixed>
-
Header to parse into components.
Return values
array<string|int, mixed> —Returns the parsed header values.
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 will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
normalize_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
- $header : string|array<string|int, mixed>
-
Header to normalize.
Return values
array<string|int, mixed> —Returns the normalized header field values.
modify_request()
Clone and modify a request with the given changes.
modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
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.
Return values
RequestInterfacerewind_body()
Attempts to rewind a message body and throws an exception on failure.
rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
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
try_fopen()
Safely opens a PHP stream resource using a filename.
try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
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
Return values
resourcecopy_to_string()
Copy the contents of a stream into a string until the given number of bytes have been read.
copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
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
Return values
stringcopy_to_stream()
Copy the contents of a stream into another stream until the given number of bytes have been read.
copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
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
hash()
Calculate a hash of a stream.
hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
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
Return values
string —Returns the hash of the stream
readline()
Read a line from the stream up to the maximum allowed buffer length.
readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
readline(StreamInterface $stream[, int|null $maxLength = null ]) : string
Parameters
- $stream : StreamInterface
-
Stream to read from
- $maxLength : int|null = null
-
Maximum buffer length
Return values
stringparse_request()
Parses a request message string into a request object.
parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
parse_request(string $message) : Request
Parameters
- $message : string
-
Request message string.
Return values
Requestparse_response()
Parses a response message string into a response object.
parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
parse_response(string $message) : Response
Parameters
- $message : string
-
Response message string.
Return values
Responseparse_query()
Parse a query string into an associative array.
parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
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
Return values
array<string|int, mixed>build_query()
Build a query string from an array of key value pairs.
build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
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.
Return values
stringmimetype_from_filename()
Determines the mimetype of a file by looking at its extension.
mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
mimetype_from_filename(string $filename) : string|null
Parameters
- $filename : string
Return values
string|nullmimetype_from_extension()
Maps a file extensions to a mimetype.
mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
mimetype_from_extension(mixed $extension) : string|null
Parameters
- $extension : mixed
-
string The file extension.
Tags
Return values
string|nullget_message_body_summary()
Get a short summary of the message body.
get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
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
Return values
string|nullstr()
Returns the string representation of an HTTP message.
str will be removed in guzzlehttp/psr7:2.0. Use Message::toString instead.
str(MessageInterface $message) : string
Parameters
- $message : MessageInterface
-
Message to convert to a string.
Return values
stringuri_for()
Returns a UriInterface for the given value.
uri_for will be removed in guzzlehttp/psr7:2.0. Use Utils::uriFor instead.
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
Return values
UriInterfacestream_for()
Create a new stream based on the input type.
stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.
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 implementsIterator
, 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 callnext
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
: Whennull
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 returnfalse
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
Return values
StreamInterfaceparse_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 will be removed in guzzlehttp/psr7:2.0. Use Header::parse instead.
parse_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
- $header : string|array<string|int, mixed>
-
Header to parse into components.
Return values
array<string|int, mixed> —Returns the parsed header values.
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 will be removed in guzzlehttp/psr7:2.0. Use Header::normalize instead.
normalize_header(string|array<string|int, mixed> $header) : array<string|int, mixed>
Parameters
- $header : string|array<string|int, mixed>
-
Header to normalize.
Return values
array<string|int, mixed> —Returns the normalized header field values.
modify_request()
Clone and modify a request with the given changes.
modify_request will be removed in guzzlehttp/psr7:2.0. Use Utils::modifyRequest instead.
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.
Return values
RequestInterfacerewind_body()
Attempts to rewind a message body and throws an exception on failure.
rewind_body will be removed in guzzlehttp/psr7:2.0. Use Message::rewindBody instead.
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
try_fopen()
Safely opens a PHP stream resource using a filename.
try_fopen will be removed in guzzlehttp/psr7:2.0. Use Utils::tryFopen instead.
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
Return values
resourcecopy_to_string()
Copy the contents of a stream into a string until the given number of bytes have been read.
copy_to_string will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToString instead.
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
Return values
stringcopy_to_stream()
Copy the contents of a stream into another stream until the given number of bytes have been read.
copy_to_stream will be removed in guzzlehttp/psr7:2.0. Use Utils::copyToStream instead.
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
hash()
Calculate a hash of a stream.
hash will be removed in guzzlehttp/psr7:2.0. Use Utils::hash instead.
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
Return values
string —Returns the hash of the stream
readline()
Read a line from the stream up to the maximum allowed buffer length.
readline will be removed in guzzlehttp/psr7:2.0. Use Utils::readLine instead.
readline(StreamInterface $stream[, int|null $maxLength = null ]) : string
Parameters
- $stream : StreamInterface
-
Stream to read from
- $maxLength : int|null = null
-
Maximum buffer length
Return values
stringparse_request()
Parses a request message string into a request object.
parse_request will be removed in guzzlehttp/psr7:2.0. Use Message::parseRequest instead.
parse_request(string $message) : Request
Parameters
- $message : string
-
Request message string.
Return values
Requestparse_response()
Parses a response message string into a response object.
parse_response will be removed in guzzlehttp/psr7:2.0. Use Message::parseResponse instead.
parse_response(string $message) : Response
Parameters
- $message : string
-
Response message string.
Return values
Responseparse_query()
Parse a query string into an associative array.
parse_query will be removed in guzzlehttp/psr7:2.0. Use Query::parse instead.
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
Return values
array<string|int, mixed>build_query()
Build a query string from an array of key value pairs.
build_query will be removed in guzzlehttp/psr7:2.0. Use Query::build instead.
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.
Return values
stringmimetype_from_filename()
Determines the mimetype of a file by looking at its extension.
mimetype_from_filename will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromFilename instead.
mimetype_from_filename(string $filename) : string|null
Parameters
- $filename : string
Return values
string|nullmimetype_from_extension()
Maps a file extensions to a mimetype.
mimetype_from_extension will be removed in guzzlehttp/psr7:2.0. Use MimeType::fromExtension instead.
mimetype_from_extension(mixed $extension) : string|null
Parameters
- $extension : mixed
-
string The file extension.
Tags
Return values
string|nullget_message_body_summary()
Get a short summary of the message body.
get_message_body_summary will be removed in guzzlehttp/psr7:2.0. Use Message::bodySummary instead.
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