Documentation

Request
in package
implements RequestInterface

Interfaces, Classes, Traits and Enums

RequestInterface
Represents the HTTP request

Table of Contents

$body  : string
Stores the request body
$headers  : array<string|int, mixed>
The incoming HTTP request headers.
$uploadedFiles  : array<string|int, mixed>
The incoming uploaded files.
__construct()  : mixed
Fills up the `headers` and the `uploadedFiles` arrays.
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
createUploadedFile()  : UploadedFile
It will create an UploadedFile instance by an array (one element from the $_FILES)
createUploadedFiles()  : void
It will fill up the `uploadedFiles` array
createUploadedFilesFromArray()  : void
It will create an UploadedFile array by parameter name and puts into the `uploadedFiles` array

Properties

$body

Stores the request body

protected string $body = ''

$headers

The incoming HTTP request headers.

protected array<string|int, mixed> $headers = []

$uploadedFiles

The incoming uploaded files.

protected array<string|int, mixed> $uploadedFiles = []

Methods

__construct()

Fills up the `headers` and the `uploadedFiles` arrays.

public __construct() : mixed
Return values
mixed

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.

Return values
array<string|int, mixed>|null

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
Return values
UploadedFile|array<string|int, UploadedFile>|null

createUploadedFile()

It will create an UploadedFile instance by an array (one element from the $_FILES)

protected createUploadedFile(array<string|int, mixed> $file) : UploadedFile
Parameters
$file : array<string|int, mixed>
Return values
UploadedFile

createUploadedFiles()

It will fill up the `uploadedFiles` array

protected createUploadedFiles() : void
Return values
void

createUploadedFilesFromArray()

It will create an UploadedFile array by parameter name and puts into the `uploadedFiles` array

protected createUploadedFilesFromArray(string $name, array<string|int, mixed> $file) : void
Parameters
$name : string
$file : array<string|int, mixed>
Return values
void

Search results