RequestInterface
extends
OutgoingRequestInterface
in
Representation of an incoming, server-side HTTP request.
Corresponds to Psr7\ServerRequestInterface.
Table of Contents
Methods
- appendBody() : $this
- Appends data to the body of the current message.
- appendHeader() : $this
- Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
- getBody() : string|null
- Gets the body of the message.
- getHeaderLine() : string
- Retrieves a comma-separated string of the values for a single header.
- getIPAddress() : string
- Gets the user's IP address.
- getMethod() : string
- Retrieves the HTTP method of the request.
- getProtocolVersion() : string
- Retrieves the HTTP protocol version as a string.
- getServer() : mixed
- Fetch an item from the $_SERVER array.
- getUri() : URI
- Retrieves the URI instance.
- hasHeader() : bool
- Checks if a header exists by the given case-insensitive name.
- header() : Header|array<int, Header>|null
- Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.
- headers() : array<string, Header|array<int, Header>>
- Returns an array containing all Headers.
- populateHeaders() : void
- Populates the $headers array with any headers the server knows about.
- prependHeader() : $this
- Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
- removeHeader() : $this
- Removes a header from the list of headers we track.
- setBody() : $this
- Sets the body of the current message.
- setHeader() : $this
- Sets a header and it's value.
- setProtocolVersion() : $this
- Sets the HTTP protocol version.
- withMethod() : static
- Return an instance with the provided HTTP method.
- withUri() : static
- Returns an instance with the provided URI.
Methods
appendBody()
Appends data to the body of the current message.
public
appendBody(string $data) : $this
Parameters
- $data : string
Return values
$thisappendHeader()
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
public
appendHeader(string $name, string|null $value) : $this
Parameters
- $name : string
- $value : string|null
Return values
$thisgetBody()
Gets the body of the message.
public
getBody() : string|null
Tags
Return values
string|nullgetHeaderLine()
Retrieves a comma-separated string of the values for a single header.
public
getHeaderLine(string $name) : string
This method returns all of the header values of the given case-insensitive header name as a string concatenated together using a comma.
NOTE: Not all header values may be appropriately represented using comma concatenation. For such headers, use getHeader() instead and supply your own delimiter when concatenating.
Parameters
- $name : string
Return values
stringgetIPAddress()
Gets the user's IP address.
public
getIPAddress() : string
Supplied by RequestTrait.
Return values
string —IP address
getMethod()
Retrieves the HTTP method of the request.
public
getMethod() : string
Return values
string —Returns the request method.
getProtocolVersion()
Retrieves the HTTP protocol version as a string.
public
getProtocolVersion() : string
The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
Return values
string —HTTP protocol version.
getServer()
Fetch an item from the $_SERVER array.
public
getServer([array<string|int, mixed>|string|null $index = null ][, int|null $filter = null ]) : mixed
Supplied by RequestTrait.
Parameters
- $index : array<string|int, mixed>|string|null = null
-
Index for item to be fetched from $_SERVER
- $filter : int|null = null
-
A filter name to be applied
getUri()
Retrieves the URI instance.
public
getUri() : URI
Tags
Return values
URIhasHeader()
Checks if a header exists by the given case-insensitive name.
public
hasHeader(string $name) : bool
Parameters
- $name : string
-
Case-insensitive header field name.
Return values
bool —Returns true if any header names match the given header name using a case-insensitive string comparison. Returns false if no matching header name is found in the message.
header()
Returns a single Header object. If multiple headers with the same name exist, then will return an array of header objects.
public
header(string $name) : Header|array<int, Header>|null
Parameters
- $name : string
Return values
Header|array<int, Header>|nullheaders()
Returns an array containing all Headers.
public
headers() : array<string, Header|array<int, Header>>
Return values
array<string, Header|array<int, Header>> —An array of the Header objects
populateHeaders()
Populates the $headers array with any headers the server knows about.
public
populateHeaders() : void
prependHeader()
Adds an additional header value to any headers that accept multiple values (i.e. are an array or implement ArrayAccess)
public
prependHeader(string $name, string $value) : $this
Parameters
- $name : string
- $value : string
Return values
$thisremoveHeader()
Removes a header from the list of headers we track.
public
removeHeader(string $name) : $this
Parameters
- $name : string
Return values
$thissetBody()
Sets the body of the current message.
public
setBody(string $data) : $this
Parameters
- $data : string
Return values
$thissetHeader()
Sets a header and it's value.
public
setHeader(string $name, array<string|int, mixed>|string|null $value) : $this
Parameters
- $name : string
- $value : array<string|int, mixed>|string|null
Return values
$thissetProtocolVersion()
Sets the HTTP protocol version.
public
setProtocolVersion(string $version) : $this
Parameters
- $version : string
Tags
Return values
$thiswithMethod()
Return an instance with the provided HTTP method.
public
withMethod(string $method) : static
While HTTP method names are typically all uppercase characters, HTTP method names are case-sensitive and thus implementations SHOULD NOT modify the given string.
This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the changed request method.
Parameters
- $method : string
-
Case-sensitive method.
Tags
Return values
staticwithUri()
Returns an instance with the provided URI.
public
withUri(URI $uri[, bool $preserveHost = false ]) : static
This method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request.
You can opt-in to preserving the original state of the Host header by
setting $preserveHost
to true
. When $preserveHost
is set to
true
, this method interacts with the Host header in the following ways:
- If the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request.
- If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request.
- If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request.
This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the new UriInterface instance.
Parameters
- $uri : URI
-
New request URI to use.
- $preserveHost : bool = false
-
Preserve the original state of the Host header.