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() : IHttpContent|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.
- 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.
- 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.
- isBencodedContent() : bool
- Checks if the body content is BencodedContent.
- isFormContent() : bool
- Checks if the body content is FormContent.
- isJsonContent() : bool
- Checks if the body content is JsonContent.
- isStreamContent() : bool
- Checks if the body content is StreamContent.
- isStringContent() : bool
- Checks if the body content is StringContent.
Methods
__construct()
public
__construct(string $version, string $method, string $path, array<string, mixed> $params, array<string, string> $cookies, HttpHeaders $headers, IHttpContent|null $content) : mixed
Parameters
- $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 : IHttpContent|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() : IHttpContent|null
Return values
IHttpContent|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.
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.
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.
isBencodedContent()
Checks if the body content is BencodedContent.
public
isBencodedContent() : bool
Return values
bool —true if it is BencodedContent.
isFormContent()
Checks if the body content is FormContent.
public
isFormContent() : bool
Return values
bool —true if it is FormContent.
isJsonContent()
Checks if the body content is JsonContent.
public
isJsonContent() : bool
Return values
bool —true if it is JsonContent.
isStreamContent()
Checks if the body content is StreamContent.
public
isStreamContent() : bool
Return values
bool —true if it is StreamContent.
isStringContent()
Checks if the body content is StringContent.
public
isStringContent() : bool
Return values
bool —true if it is StringContent.