Message
class Message implements Countable, Serializable, Iterator (View source)
The message class builds the foundation for any request and response message.
See http\Client\Request and http\Client\Response, as well as http\Env\Request and http\Env\Response.
Constants
TYPE_NONE |
No specific type of message. |
TYPE_REQUEST |
A request message. |
TYPE_RESPONSE |
A response message. |
Properties
protected int | $type | The message type. See http\Message::TYPE_* constants. |
|
protected Body | $body | The message's body. |
|
protected string | $requestMethod | The request method if the message is of type request. |
|
protected string | $requestUrl | The request url if the message is of type request. |
|
protected string | $responseStatus | The response status phrase if the message is of type response. |
|
protected int | $responseCode | The response code if the message is of type response. |
|
protected string | $httpVersion | A custom HTTP protocol version. |
|
protected array | $headers | Any message headers. |
|
protected Message | $parentMessage | Any parent message. |
Methods
Create a new HTTP message.
Retrieve the message serialized to a string.
Add headers, optionally appending values, if header keys already exist.
Implements Countable.
Implements iterator.
Retrieve a single header, optionally hydrated into a http\Header extending class.
Retrieve all message headers.
Retrieve the HTTP protocol version of the message.
Retrieve the first line of a request or response message.
Retrieve any parent message.
Retrieve the request method of the message.
Retrieve the request URL of the message.
Retrieve the response code of the message.
Retrieve the response status of the message.
Retrieve the type of the message.
Check whether this message is a multipart message based on it's content type.
Implements Iterator.
Implements Iterator.
Implements Iterator.
Implements Serializable.
Set the message headers.
Set the HTTP protocol version of the message.
Set the complete message info, i.e. type and response resp. request information, at once.
Set the request method of the message.
Set the request URL of the message.
Set the response status code.
Set the response status phrase.
Splits the body of a multipart message.
Stream the message through a callback.
Stream the message into stream $stream, starting from $offset, streaming $maxlen at most.
Retrieve the message serialized to a string.
Implements Serializable.
Implements Iterator.
Details
__construct(mixed $message = null, bool $greedy = true)
Create a new HTTP message.
string
__toString()
Retrieve the message serialized to a string.
Alias of http\Message::toString().
Message
addBody(Body $body)
Append the data of $body to the message's body.
See http\Message::setBody() and http\Message\Body::append().
Message
addHeader(string $name, mixed $value)
Add an header, appending to already existing headers.
See http\Message::addHeaders() and http\Message::setHeader().
Message
addHeaders(array $headers, bool $append = false)
Add headers, optionally appending values, if header keys already exist.
See http\Message::addHeader() and http\Message::setHeaders().
int
count()
Implements Countable.
mixed
current()
Implements iterator.
See http\Message::valid() and http\Message::rewind().
Message
detach()
Detach a clone of this message from any message chain.
Body
getBody()
Retrieve the message's body.
See http\Message::setBody().
mixed|Header
getHeader(string $header, string $into_class = null)
Retrieve a single header, optionally hydrated into a http\Header extending class.
array
getHeaders()
Retrieve all message headers.
See http\Message::setHeaders() and http\Message::getHeader().
string
getHttpVersion()
Retrieve the HTTP protocol version of the message.
See http\Message::setHttpVersion().
string|null
getInfo()
Retrieve the first line of a request or response message.
See http\Message::setInfo and also:
- http\Message::getType()
- http\Message::getHttpVersion()
- http\Message::getResponseCode()
- http\Message::getResponseStatus()
- http\Message::getRequestMethod()
- http\Message::getRequestUrl()
Message
getParentMessage()
Retrieve any parent message.
See http\Message::reverse().
string|false
getRequestMethod()
Retrieve the request method of the message.
See http\Message::setRequestMethod() and http\Message::getRequestUrl().
string|false
getRequestUrl()
Retrieve the request URL of the message.
See http\Message::setRequestUrl().
int|false
getResponseCode()
Retrieve the response code of the message.
See http\Message::setResponseCode() and http\Message::getResponseStatus().
string|false
getResponseStatus()
Retrieve the response status of the message.
See http\Message::setResponseStatus() and http\Message::getResponseCode().
int
getType()
Retrieve the type of the message.
See http\Message::setType() and http\Message::getInfo().
bool
isMultipart(string $boundary = null)
Check whether this message is a multipart message based on it's content type.
If the message is a multipart message and a reference $boundary is given, the boundary string of the multipart message will be stored in $boundary.
See http\Message::splitMultipartBody().
mixed
key()
Implements Iterator.
See http\Message::current() and http\Message::rewind().
void
next()
Implements Iterator.
See http\Message::valid() and http\Message::rewind().
Message
prepend(Message $message, bool $top = true)
Prepend message(s) $message to this message, or the top most message of this message chain.
NOTE: The message chains must not overlap.
Message
reverse()
Reverse the message chain and return the former top-most message.
NOTE: Message chains are ordered in reverse-parsed order by default, i.e. the last parsed message is the message you'll receive from any call parsing HTTP messages.
This call re-orders the messages of the chain and returns the message that was parsed first with any later parsed messages re-parentized.
void
rewind()
Implements Iterator.
string|null
serialize()
Implements Serializable.
Message
setBody(Body $body)
Set the message's body.
See http\Message::getBody() and http\Message::addBody().
Message
setHeader(string $header, mixed $value = null)
Set a single header.
See http\Message::getHeader() and http\Message::addHeader().
NOTE: Prior to v2.5.6/v3.1.0 headers with the same name were merged into a single header with values concatenated by comma.
Message
setHeaders(array $headers = null)
Set the message headers.
See http\Message::getHeaders() and http\Message::addHeaders().
NOTE: Prior to v2.5.6/v3.1.0 headers with the same name were merged into a single header with values concatenated by comma.
Message
setHttpVersion(string $http_version)
Set the HTTP protocol version of the message.
See http\Message::getHttpVersion().
Message
setInfo(string $http_info)
Set the complete message info, i.e. type and response resp. request information, at once.
See http\Message::getInfo().
Message
setRequestMethod(string $method)
Set the request method of the message.
See http\Message::getRequestMethod() and http\Message::setRequestUrl().
Message
setRequestUrl(string $url)
Set the request URL of the message.
See http\Message::getRequestUrl() and http\Message::setRequestMethod().
Message
setResponseCode(int $response_code, bool $strict = true)
Set the response status code.
See http\Message::getResponseCode() and http\Message::setResponseStatus().
NOTE: This method also resets the response status phrase to the default for that code.
Message
setResponseStatus(string $response_status)
Set the response status phrase.
See http\Message::getResponseStatus() and http\Message::setResponseCode().
Message
setType(int $type)
Set the message type and reset the message info.
See http\Message::getType() and http\Message::setInfo().
Message
splitMultipartBody()
Splits the body of a multipart message.
See http\Message::isMultipart() and http\Message\Body::addPart().
Message
toCallback(callable $callback)
Stream the message through a callback.
Message
toStream(resource $stream)
Stream the message into stream $stream, starting from $offset, streaming $maxlen at most.
string
toString(bool $include_parent = false)
Retrieve the message serialized to a string.
void
unserialize(string $data)
Implements Serializable.
bool
valid()
Implements Iterator.
See http\Message::current() and http\Message::rewind().