HttpRequest
extends HttpMessage
in package
Represents a HTTP request message.
Table of Contents
Methods
- __construct() : mixed
- fromRequest() : HttpRequest
- Creates an HttpRequest instance from the current request.
- getContent() : HttpContent|null
- Retrieves message body contents, if present.
- getCookie() : mixed
- Retrieves an HTTP request cookie, or null if it is not present.
- getCookies() : array<string, string>
- Retrieves all HTTP request cookies.
- getCountryCode() : string
- Returns the origin ISO 3166 country code.
- getHeader() : HttpHeader
- Retrieves a header by name.
- getHeaderFirstLine() : string
- Gets the first line of a header.
- getHeaderLine() : string
- Gets the contents of a header as a string.
- getHeaderLines() : array<string|int, string>
- Gets lines of a header.
- getHeaders() : array<string|int, HttpHeader>
- Retrieves the collection of headers for this HTTP message.
- getHttpVersion() : string
- Retrieves the HTTP version of this message.
- getMethod() : string
- Retrieves the HTTP request method.
- getParam() : mixed
- Retrieves an HTTP request query field, or null if it is not present.
- getParams() : array<string, mixed>
- Retrieves all HTTP request query fields.
- getParamString() : string
- Retrieves all HTTP request query fields as a query string.
- getPath() : string
- Retrieves the HTTP request path.
- getRemoteAddress() : string
- Returns the origin remote address.
- hasContent() : bool
- Checks whether this HTTP message has body contents.
- hasCookie() : bool
- Checks if a cookie is present.
- hasHeader() : bool
- Checks if a header is present.
- hasParam() : bool
- Checks if a query field is present.
- isBencodeContent() : bool
- Checks if the body content is BencodeHttpContent.
- isFormContent() : bool
- Checks if the body content is FormHttpContent.
- isJsonContent() : bool
- Checks if the body content is JsonHttpContent.
- isSecure() : bool
- Returns whether the request was made over HTTPS or not.
- isStringContent() : bool
- Checks if the body content is StringHttpContent.
Methods
__construct()
public
__construct(string $remoteAddr, bool $secure, string $countryCode, string $version, string $method, string $path, array<string, mixed> $params, array<string, string> $cookies, HttpHeaders $headers, HttpContent|null $content) : mixed
Parameters
- $remoteAddr : string
-
Origin remote address.
- $secure : bool
-
true if HTTPS.
- $countryCode : string
-
Origin ISO 3166 country code.
- $version : string
-
HTTP message version.
- $method : string
-
HTTP request method.
- $path : string
-
HTTP request path.
- $params : array<string, mixed>
-
HTTP request query parameters.
- $cookies : array<string, string>
-
HTTP request cookies.
- $headers : HttpHeaders
-
HTTP message headers.
- $content : HttpContent|null
-
Body contents.
fromRequest()
Creates an HttpRequest instance from the current request.
public
static fromRequest() : HttpRequest
Return values
HttpRequest —An instance representing the current request.
getContent()
Retrieves message body contents, if present.
public
getContent() : HttpContent|null
Return values
HttpContent|null —Body contents, null if none present.
getCookie()
Retrieves an HTTP request cookie, or null if it is not present.
public
getCookie(string $name[, int $filter = FILTER_DEFAULT ][, array<string, mixed>|int $options = 0 ]) : mixed
Parameters
- $name : string
-
Name of the request cookie.
- $filter : int = FILTER_DEFAULT
-
A PHP filter extension filter constant.
- $options : array<string, mixed>|int = 0
-
Options for the PHP filter.
Return values
mixed —Value of the cookie, null if not present.
getCookies()
Retrieves all HTTP request cookies.
public
getCookies() : array<string, string>
Return values
array<string, string> —All cookies.
getCountryCode()
Returns the origin ISO 3166 country code.
public
getCountryCode() : string
Return values
string —Two letter country code.
getHeader()
Retrieves a header by name.
public
getHeader(string $name) : HttpHeader
Parameters
- $name : string
-
Name of the header.
Tags
Return values
HttpHeader —Instance of the requested header.
getHeaderFirstLine()
Gets the first line of a header.
public
getHeaderFirstLine(string $name) : string
Parameters
- $name : string
-
Name of the header.
Return values
string —First line of the header.
getHeaderLine()
Gets the contents of a header as a string.
public
getHeaderLine(string $name) : string
Parameters
- $name : string
-
Name of the header.
Return values
string —Contents of the header.
getHeaderLines()
Gets lines of a header.
public
getHeaderLines(string $name) : array<string|int, string>
Parameters
- $name : string
-
Name of the header.
Return values
array<string|int, string> —Header lines.
getHeaders()
Retrieves the collection of headers for this HTTP message.
public
getHeaders() : array<string|int, HttpHeader>
Return values
array<string|int, HttpHeader> —HTTP headers.
getHttpVersion()
Retrieves the HTTP version of this message.
public
getHttpVersion() : string
Return values
string —HTTP version.
getMethod()
Retrieves the HTTP request method.
public
getMethod() : string
Return values
string —HTTP request method.
getParam()
Retrieves an HTTP request query field, or null if it is not present.
public
getParam(string $name[, int $filter = FILTER_DEFAULT ][, array<string|int, mixed>|int $options = 0 ]) : mixed
Parameters
- $name : string
-
Name of the request query field.
- $filter : int = FILTER_DEFAULT
-
A PHP filter extension filter constant.
- $options : array<string|int, mixed>|int = 0
-
Options for the PHP filter.
Return values
mixed —Value of the query field, null if not present.
getParams()
Retrieves all HTTP request query fields.
public
getParams() : array<string, mixed>
Return values
array<string, mixed> —Query fields.
getParamString()
Retrieves all HTTP request query fields as a query string.
public
getParamString([bool $spacesAsPlus = false ]) : string
Parameters
- $spacesAsPlus : bool = false
-
true if spaces should be represented with a +, false if %20.
Return values
string —Query string representation of query fields.
getPath()
Retrieves the HTTP request path.
public
getPath() : string
Return values
string —HTTP request path.
getRemoteAddress()
Returns the origin remote address.
public
getRemoteAddress() : string
Return values
string —Printable remote address.
hasContent()
Checks whether this HTTP message has body contents.
public
hasContent() : bool
Return values
bool —true if it has body contents.
hasCookie()
Checks if a cookie is present.
public
hasCookie(string $name) : bool
Parameters
- $name : string
-
Name of the cookie.
Return values
bool —true if the cookie is present, false if not.
hasHeader()
Checks if a header is present.
public
hasHeader(string $name) : bool
Parameters
- $name : string
-
Name of the header.
Return values
bool —true if the header is present.
hasParam()
Checks if a query field is present.
public
hasParam(string $name) : bool
Parameters
- $name : string
-
Name of the query field.
Return values
bool —true if the field is present, false if not.
isBencodeContent()
Checks if the body content is BencodeHttpContent.
public
isBencodeContent() : bool
Return values
bool —true if it is BencodeHttpContent.
isFormContent()
Checks if the body content is FormHttpContent.
public
isFormContent() : bool
Return values
bool —true if it is FormHttpContent.
isJsonContent()
Checks if the body content is JsonHttpContent.
public
isJsonContent() : bool
Return values
bool —true if it is JsonHttpContent.
isSecure()
Returns whether the request was made over HTTPS or not.
public
isSecure() : bool
Return values
bool —true if HTTPS, false if not.
isStringContent()
Checks if the body content is StringHttpContent.
public
isStringContent() : bool
Return values
bool —true if it is StringHttpContent.