Request
class Request extends Message (View source)
The http\Env\Request class' instances represent the server's current HTTP request.
See http\Message for inherited members.
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. |
from Message |
protected Body | $body | The message's body. |
from Message |
protected string | $requestMethod | The request method if the message is of type request. |
from Message |
protected string | $requestUrl | The request url if the message is of type request. |
from Message |
protected string | $responseStatus | The response status phrase if the message is of type response. |
from Message |
protected int | $responseCode | The response code if the message is of type response. |
from Message |
protected string | $httpVersion | A custom HTTP protocol version. |
from Message |
protected array | $headers | Any message headers. |
from Message |
protected Message | $parentMessage | Any parent message. |
from Message |
protected QueryString | $query | The request's query parameters. ($_GET) |
|
protected QueryString | $form | The request's form parameters. ($_POST) |
|
protected array | $files | The request's form uploads. ($_FILES) |
|
protected array | $cookie | The request's cookies. ($_COOKIE) |
Methods
Create an instance of the server's current HTTP request.
Add an header, appending to already existing headers.
Add headers, optionally appending values, if header keys already exist.
Retrieve a single header, optionally hydrated into a http\Header extending class.
Check whether this message is a multipart message based on it's content type.
Prepend message(s) $message to this message, or the top most message of this message chain.
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 response status code.
Stream the message into stream $stream, starting from $offset, streaming $maxlen at most.
Retrieve the message serialized to a string.
Retrieve an URL query value ($_GET).
Retrieve the uploaded files list ($_FILES).
Retrieve a form value ($_POST).
Retrieve an URL query value ($_GET).
Details
__construct()
Create an instance of the server's current HTTP request.
Upon construction, the http\Env\Request acquires http\QueryString instances of query parameters ($_GET) and form parameters ($_POST).
It also compiles an array of uploaded files ($_FILES) more comprehensive than the original $_FILES array, see http\Env\Request::getFiles() for that matter.
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().
QueryString|string|mixed
getCookie(string $name = null, mixed $type = null, mixed $defval = null, bool $delete = false)
Retrieve an URL query value ($_GET).
See http\QueryString::get() and http\QueryString::TYPE_* constants.
array
getFiles()
Retrieve the uploaded files list ($_FILES).
QueryString|string|mixed
getForm(string $name = null, mixed $type = null, mixed $defval = null, bool $delete = false)
Retrieve a form value ($_POST).
See http\QueryString::get() and http\QueryString::TYPE_* constants.
QueryString|string|mixed
getQuery(string $name = null, mixed $type = null, mixed $defval = null, bool $delete = false)
Retrieve an URL query value ($_GET).
See http\QueryString::get() and http\QueryString::TYPE_* constants.