Request
extends Message
in package
implements
MessageInterface, RequestInterface
Uses
RequestTrait
Representation of an HTTP request.
Interfaces, Classes and Traits
- MessageInterface
- Expected behavior of an HTTP request
- RequestInterface
- Expected behavior of an HTTP request
Table of Contents
- $body : mixed
- Message body
- $globals : array<string|int, mixed>
- Stores values we've retrieved from PHP globals.
- $headerMap : array<string|int, mixed>
- Holds a map of lower-case header names and their normal-case key as it is in $headers.
- $headers : array<string, Header>
- List of all HTTP request headers.
- $ipAddress : string
- IP address of the current user.
- $method : string
- Request method.
- $protocolVersion : string
- Protocol version
- $proxyIPs : string|array<string|int, mixed>
- Proxy IPs
- $uri : URI
- A URI instance.
- $validProtocolVersions : array<string|int, mixed>
- List of valid protocol versions
- __construct() : mixed
- Constructor.
- 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)
- fetchGlobal() : mixed
- Fetches one or more items from a global, like cookies, get, post, etc.
- getBody() : mixed
- Returns the Message's body.
- getEnv() : mixed
- Fetch an item from the $_ENV array.
- getHeader() : array<string|int, mixed>|Header|null
- Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.
- getHeaderLine() : string
- Retrieves a comma-separated string of the values for a single header.
- getHeaders() : array<string, Header>
- Returns an array containing all headers.
- getIPAddress() : string
- Gets the user's IP address.
- getMethod() : string
- Get the request method.
- getProtocolVersion() : string
- Returns the HTTP Protocol Version.
- getServer() : mixed
- Fetch an item from the $_SERVER array.
- getUri() : URI
- Retrieves the URI instance.
- hasHeader() : bool
- Determines whether a header exists.
- header() : array<string|int, mixed>|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>
- Returns an array containing all Headers.
- isValidIP() : bool
- Validate an IP address
- populateHeaders() : void
- Populates the $headers array with any headers the getServer 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.
- setGlobal() : $this
- Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
- setHeader() : $this
- Sets a header and it's value.
- setMethod() : Request
- Sets the request method. Used when spoofing the request.
- setProtocolVersion() : $this
- Sets the HTTP protocol version.
- withMethod() : static
- Returns an instance with the specified method.
- getHeaderName() : string
- Takes a header name in any case, and returns the normal-case version of the header.
- populateGlobals() : mixed
- Saves a copy of the current state of one of several PHP globals so we can retrieve them later.
Properties
$body
Message body
protected
mixed
$body
$globals
Stores values we've retrieved from PHP globals.
protected
array<string|int, mixed>
$globals
= []
$headerMap
Holds a map of lower-case header names and their normal-case key as it is in $headers.
protected
array<string|int, mixed>
$headerMap
= []
Used for case-insensitive header access.
$headers
List of all HTTP request headers.
protected
array<string, Header>
$headers
= []
$ipAddress
IP address of the current user.
protected
string
$ipAddress
= ''
Tags
$method
Request method.
protected
string
$method
$protocolVersion
Protocol version
protected
string
$protocolVersion
$proxyIPs
Proxy IPs
protected
string|array<string|int, mixed>
$proxyIPs
Tags
$uri
A URI instance.
protected
URI
$uri
$validProtocolVersions
List of valid protocol versions
protected
array<string|int, mixed>
$validProtocolVersions
= ['1.0', '1.1', '2.0']
Methods
__construct()
Constructor.
public
__construct([object $config = null ]) : mixed
Parameters
- $config : object = null
Tags
Return values
mixed —appendBody()
Appends data to the body of the current message.
public
appendBody(mixed $data) : $this
Parameters
- $data : mixed
Return values
$this —appendHeader()
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
$this —fetchGlobal()
Fetches one or more items from a global, like cookies, get, post, etc.
public
fetchGlobal(string $method[, string|array<string|int, mixed>|null $index = null ][, int|null $filter = null ][, array<string|int, mixed>|int|null $flags = null ]) : mixed
Can optionally filter the input when you retrieve it by passing in a filter.
If $type is an array, it must conform to the input allowed by the filter_input_array method.
http://php.net/manual/en/filter.filters.sanitize.php
Parameters
- $method : string
-
Input filter constant
- $index : string|array<string|int, mixed>|null = null
- $filter : int|null = null
-
Filter constant
- $flags : array<string|int, mixed>|int|null = null
-
Options
Return values
mixed —getBody()
Returns the Message's body.
public
getBody() : mixed
Return values
mixed —getEnv()
Fetch an item from the $_ENV array.
public
getEnv([null $index = null ][, null $filter = null ][, null $flags = null ]) : mixed
Parameters
- $index : null = null
-
Index for item to be fetched from $_ENV
- $filter : null = null
-
A filter name to be applied
- $flags : null = null
Return values
mixed —getHeader()
Returns a single header object. If multiple headers with the same name exist, then will return an array of header objects.
public
getHeader(string $name) : array<string|int, mixed>|Header|null
Parameters
- $name : string
Tags
Return values
array<string|int, mixed>|Header|null —getHeaderLine()
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
string —getHeaders()
Returns an array containing all headers.
public
getHeaders() : array<string, Header>
Tags
Return values
array<string, Header> —An array of the request headers
getIPAddress()
Gets the user's IP address.
public
getIPAddress() : string
Return values
string —IP address
getMethod()
Get the request method.
public
getMethod([bool $upper = false ]) : string
Parameters
- $upper : bool = false
-
Whether to return in upper or lower case.
Tags
Return values
string —getProtocolVersion()
Returns the HTTP Protocol Version.
public
getProtocolVersion() : string
Return values
string —getServer()
Fetch an item from the $_SERVER array.
public
getServer([string|array<string|int, mixed>|null $index = null ][, int|null $filter = null ][, null $flags = null ]) : mixed
Parameters
- $index : string|array<string|int, mixed>|null = null
-
Index for item to be fetched from $_SERVER
- $filter : int|null = null
-
A filter name to be applied
- $flags : null = null
Return values
mixed —getUri()
Retrieves the URI instance.
public
getUri() : URI
Return values
URI —hasHeader()
Determines whether a header exists.
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
bool —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) : array<string|int, mixed>|Header|null
Parameters
- $name : string
Return values
array<string|int, mixed>|Header|null —headers()
Returns an array containing all Headers.
public
headers() : array<string, Header>
Return values
array<string, Header> —An array of the Header objects
isValidIP()
Validate an IP address
public
isValidIP([string $ip = null ][, string $which = null ]) : bool
Parameters
- $ip : string = null
-
IP Address
- $which : string = null
-
IP protocol: 'ipv4' or 'ipv6'
Tags
Return values
bool —populateHeaders()
Populates the $headers array with any headers the getServer knows about.
public
populateHeaders() : void
Return values
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
$this —removeHeader()
Removes a header from the list of headers we track.
public
removeHeader(string $name) : $this
Parameters
- $name : string
Return values
$this —setBody()
Sets the body of the current message.
public
setBody(mixed $data) : $this
Parameters
- $data : mixed
Return values
$this —setGlobal()
Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
public
setGlobal(string $method, mixed $value) : $this
Parameters
- $method : string
- $value : mixed
Return values
$this —setHeader()
Sets a header and it's value.
public
setHeader(string $name, array<string|int, mixed>|null|string $value) : $this
Parameters
- $name : string
- $value : array<string|int, mixed>|null|string
Return values
$this —setMethod()
Sets the request method. Used when spoofing the request.
public
setMethod(string $method) : Request
Parameters
- $method : string
Tags
Return values
Request —setProtocolVersion()
Sets the HTTP protocol version.
public
setProtocolVersion(string $version) : $this
Parameters
- $version : string
Tags
Return values
$this —withMethod()
Returns an instance with the specified method.
public
withMethod(string $method) : static
Parameters
- $method : string
Return values
static —getHeaderName()
Takes a header name in any case, and returns the normal-case version of the header.
protected
getHeaderName(string $name) : string
Parameters
- $name : string
Return values
string —populateGlobals()
Saves a copy of the current state of one of several PHP globals so we can retrieve them later.
protected
populateGlobals(string $method) : mixed
Parameters
- $method : string