Request
    
            
            in package
            
        
    
    
    
        
            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 (@see UploadedFile).
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
- The Request constructor
- body() : bool|string
- Returns with the request body
- bodyAsJson() : mixed|null
- Returns with the request body as an associative array parsed from JSON
- cookie() : mixed|null
- Returns with a cookie value by name
- get() : mixed|null
- Returns with a parameter of the request, uses the $_REQUEST array
- header() : mixed|null
- 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|null
- Returns with the information that was created by the web server, uses the $_SERVER array
- setBody() : mixed
- Sets the request body
- setHeader() : mixed
- 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() : mixed
- It will fill up the `uploadedFiles` array
- createUploadedFilesFromArray() : mixed
- 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()
The Request constructor
    public
                    __construct() : mixed
        Fills up the headers and the uploadedFiles arrays.
Tags
Return values
mixed —body()
Returns with the request body
    public
                    body() : bool|string
    
    
    
        Return values
bool|string —The request body
bodyAsJson()
Returns with the request body as an associative array parsed from JSON
    public
                    bodyAsJson() : mixed|null
        Throws an MicroException if the JSON is invalid.
Tags
Return values
mixed|null —Returns with an associative array from parsed JSON or null if the request body is empty
cookie()
Returns with a cookie value by name
    public
                    cookie(string $name[, mixed|null $default = null ]) : mixed|null
    
        Parameters
- $name : string
- 
                    The name of the cookie 
- $default : mixed|null = null
- 
                    The default value if the cookie doesn't present 
Return values
mixed|null —The cookie value or the default value
get()
Returns with a parameter of the request, uses the $_REQUEST array
    public
                    get(string $name[, mixed|null $default = null ]) : mixed|null
    
        Parameters
- $name : string
- 
                    The name of the parameter 
- $default : mixed|null = null
- 
                    The default value if the parameter doesn't present 
Return values
mixed|null —The value of the parameter or the default value
header()
Returns with a request header by name
    public
                    header(string $name[, mixed|null $default = null ]) : mixed|null
    
        Parameters
- $name : string
- 
                    The header name 
- $default : mixed|null = null
- 
                    The default value if the header doesn't present 
Return values
mixed|null —The header value or the default value
httpMethod()
Returns the HTTP request method
    public
                    httpMethod() : string
    
    
    
        Return values
string —The request method. Can be GET, POST, PUT, OPTIONS, PATCH, DELETE
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|null $default = null ]) : mixed|null
    
        Parameters
- $name : string
- 
                    The name of the server info 
- $default : mixed|null = null
- 
                    The default value if the info doesn't present 
Return values
mixed|null —The info created by the web server or the default value
setBody()
Sets the request body
    public
                    setBody(string $content) : mixed
    
        Parameters
- $content : string
Return values
mixed —setHeader()
Sets a request header
    public
                    setHeader(string $name, string $value) : mixed
    
        Parameters
- $name : string
- 
                    The name of the header 
- $value : string
- 
                    The value of the header 
Return values
mixed —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 the more than one file uploaded it will return with an array.
Parameters
- $name : string
- 
                    The name of the parameter of the POST request 
Return values
UploadedFile|array<string|int, UploadedFile>|null —Returns the UploadedFile instance or array or 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>
- 
                    One element of the $_FILES array 
Return values
UploadedFile —The UploadedFile instance
createUploadedFiles()
It will fill up the `uploadedFiles` array
    protected
                    createUploadedFiles() : mixed
    
    
    
        Return values
mixed —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) : mixed
    
        Parameters
- $name : string
- 
                    The name of the parameter 
- $file : array<string|int, mixed>
- 
                    One element of the $_FILES array