RequestInterface
in
Represents the HTTP request
It can be used for getting the information of the HTTP request: the request method (POST, GET, etc.), the query parameters, the headers, the information that created by the web server, the cookies and the uploaded files.
Tags
Table of Contents
- body() : string
- Returns with the request body
- bodyAsJson() : array<string|int, mixed>|null
- Returns with the request body as an associative array parsed from JSON
- cookie() : mixed
- Returns with a cookie value by name
- get() : mixed
- Returns with a parameter of the request, uses the $_REQUEST array
- header() : mixed
- Returns with a request header by name
- httpMethod() : string
- Returns the HTTP request method
- ip() : string|null
- Returns with the IP of the client if present, otherwise null
- server() : mixed
- Returns with the information that was created by the web server, uses the $_SERVER array
- setBody() : void
- Sets the request body
- setHeader() : void
- Sets a request header
- uploadedFile() : UploadedFile|array<string|int, UploadedFile>|null
- Returns with the uploaded file by parameter name
Methods
body()
Returns with the request body
public
body() : string
Return values
string —bodyAsJson()
Returns with the request body as an associative array parsed from JSON
public
bodyAsJson() : array<string|int, mixed>|null
Throws a MicroException if the JSON is invalid.
Tags
Return values
array<string|int, mixed>|null —cookie()
Returns with a cookie value by name
public
cookie(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Return values
mixed —get()
Returns with a parameter of the request, uses the $_REQUEST array
public
get(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Return values
mixed —header()
Returns with a request header by name
public
header(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Return values
mixed —httpMethod()
Returns the HTTP request method
public
httpMethod() : string
Return values
string —ip()
Returns with the IP of the client if present, otherwise null
public
ip() : string|null
Important! This value can't be trusted, this is just for hashing/logging purposes.
Return values
string|null —server()
Returns with the information that was created by the web server, uses the $_SERVER array
public
server(string $name[, mixed $default = null ]) : mixed
Parameters
- $name : string
- $default : mixed = null
Return values
mixed —setBody()
Sets the request body
public
setBody(string $content) : void
Parameters
- $content : string
Return values
void —setHeader()
Sets a request header
public
setHeader(string $name, string $value) : void
Parameters
- $name : string
- $value : string
Return values
void —uploadedFile()
Returns with the uploaded file by parameter name
public
uploadedFile(string $name) : UploadedFile|array<string|int, UploadedFile>|null
If the parameter not present it will return with a null. If only one file uploaded it will return with an UploadedFile instance. If more than one file uploaded it will return with an array.
Parameters
- $name : string