Message
in package
Table of Contents
Methods
- bodySummary() : string|null
- Get a short summary of the message body.
- parseMessage() : array<string|int, mixed>
- Parses an HTTP message into an associative array.
- parseRequest() : RequestInterface
- Parses a request message string into a request object.
- parseRequestUri() : string
- Constructs a URI for an HTTP request message.
- parseResponse() : ResponseInterface
- Parses a response message string into a response object.
- rewindBody() : void
- Attempts to rewind a message body and throws an exception on failure.
- toString() : string
- Returns the string representation of an HTTP message.
Methods
bodySummary()
Get a short summary of the message body.
public
static bodySummary(MessageInterface $message[, int|null $truncateAt = null ]) : string|null
Will return null if the response is not printable.
Reads seekable bodies from the beginning and restores the original cursor
position before returning. Pass null for $truncateAt to use the
default summary length.
Parameters
- $message : MessageInterface
-
The message to get the body summary
- $truncateAt : int|null = null
-
Maximum allowed size of the summary
Return values
string|nullparseMessage()
Parses an HTTP message into an associative array.
public
static parseMessage(string $message) : array<string|int, mixed>
The array contains the start-line key containing the start line of the
message, headers key containing an associative array of header array
values, and a body key containing the body of the message.
Parameters
- $message : string
-
HTTP request or response to parse.
Return values
array<string|int, mixed>parseRequest()
Parses a request message string into a request object.
public
static parseRequest(string $message) : RequestInterface
The request-target must be in origin form, absolute form (without a
userinfo component), authority form (CONNECT), or asterisk form
(OPTIONS), and any Host header must be a single valid value;
otherwise an InvalidArgumentException is thrown. Non-origin-form
targets are preserved on the returned request via withRequestTarget().
Parameters
- $message : string
-
Request message string.
Return values
RequestInterfaceparseRequestUri()
Constructs a URI for an HTTP request message.
public
static parseRequestUri(string $path, array<string|int, mixed> $headers) : string
The URI is composed from the start-line path and the Host header, using
https when the host's port is 443 and http otherwise. Without a
Host header, only the path is returned, with extra leading slashes
collapsed so an origin-form target cannot be parsed as a network-path
reference with its own authority. An InvalidArgumentException is thrown
when the Host header is invalid.
Parameters
- $path : string
-
Path from the start-line
- $headers : array<string|int, mixed>
-
Array of headers (each value an array).
Return values
stringparseResponse()
Parses a response message string into a response object.
public
static parseResponse(string $message) : ResponseInterface
Parameters
- $message : string
-
Response message string.
Return values
ResponseInterfacerewindBody()
Attempts to rewind a message body and throws an exception on failure.
public
static rewindBody(MessageInterface $message) : void
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
toString()
Returns the string representation of an HTTP message.
public
static toString(MessageInterface $message) : string
Parameters
- $message : MessageInterface
-
Message to convert to a string.