RequestTrait
Request Trait
Additional methods to make a PSR-7 Request class compliant with the framework's own RequestInterface.
Tags
Table of Contents
Properties
- $config : App
- Configuration settings.
- $globals : array{get?: array, post?: array, request?: array, cookie?: array, server?: array}
- Stores values we've retrieved from PHP globals.
- $ipAddress : string
- IP address of the current user.
Methods
- fetchGlobal() : array<string|int, mixed>|bool|float|int|object|string|null
- Fetches one or more items from a global, like cookies, get, post, etc.
- getEnv() : mixed
- Fetch an item from the $_ENV array.
- getIPAddress() : string
- Gets the user's IP address.
- getServer() : mixed
- Fetch an item from the $_SERVER array.
- setGlobal() : $this
- Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
- populateGlobals() : void
- Saves a copy of the current state of one of several PHP globals, so we can retrieve them later.
- getClientIP() : string|null
- Gets the client IP address from the HTTP header.
Properties
$config
Configuration settings.
protected
App
$config
$globals
Stores values we've retrieved from PHP globals.
protected
array{get?: array, post?: array, request?: array, cookie?: array, server?: array}
$globals
= []
$ipAddress
IP address of the current user.
Will become private in a future release
protected
string
$ipAddress
= ''
Methods
fetchGlobal()
Fetches one or more items from a global, like cookies, get, post, etc.
public
fetchGlobal(string $name[, array<string|int, mixed>|int|string|null $index = null ][, int|null $filter = null ][, array<string|int, mixed>|int|null $flags = null ]) : array<string|int, mixed>|bool|float|int|object|string|null
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
- $name : string
-
Supergrlobal name (lowercase)
- $index : array<string|int, mixed>|int|string|null = null
- $filter : int|null = null
-
Filter constant
- $flags : array<string|int, mixed>|int|null = null
-
Options
Tags
Return values
array<string|int, mixed>|bool|float|int|object|string|nullgetEnv()
Fetch an item from the $_ENV array.
public
getEnv([array<string|int, mixed>|string|null $index = null ][, int|null $filter = null ][, array<string|int, mixed>|int|null $flags = null ]) : mixed
This method does not work from the beginning. Use env()
.
Parameters
- $index : array<string|int, mixed>|string|null = null
-
Index for item to be fetched from $_ENV
- $filter : int|null = null
-
A filter name to be applied
- $flags : array<string|int, mixed>|int|null = null
getIPAddress()
Gets the user's IP address.
public
getIPAddress() : string
Return values
string —IP address if it can be detected. If the IP address is not a valid IP address, then will return '0.0.0.0'.
getServer()
Fetch an item from the $_SERVER array.
public
getServer([array<string|int, mixed>|string|null $index = null ][, int|null $filter = null ][, array<string|int, mixed>|int|null $flags = null ]) : mixed
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
- $flags : array<string|int, mixed>|int|null = null
setGlobal()
Allows manually setting the value of PHP global, like $_GET, $_POST, etc.
public
setGlobal(string $name, mixed $value) : $this
Parameters
- $name : string
-
Supergrlobal name (lowercase)
- $value : mixed
Tags
Return values
$thispopulateGlobals()
Saves a copy of the current state of one of several PHP globals, so we can retrieve them later.
protected
populateGlobals(string $name) : void
Parameters
- $name : string
-
Superglobal name (lowercase)
Tags
getClientIP()
Gets the client IP address from the HTTP header.
private
getClientIP(string $header) : string|null
Parameters
- $header : string