Request
extends RequestResponseHandler
in package
Uses
CanValidateForm, CanValidateMultiForm, CanRetrieveFromInput
Base class for Response and Request
Table of Contents
- $booter : ZubZet
- $input : State
- $store : array<string|int, mixed>
- $urlParameters : array<string|int, mixed>
- $urlParts : array<string|int, mixed>
- __construct() : mixed
- checkPermission() : bool
- Checks if the current user has a permission. If the user is not logged in, they will be redirected to the login page.
- checkSuperPermission() : bool
- getBody() : string|null
- Get the body of the request
- getBooterSettings() : mixed
- Gets a booter setting
- getCookie() : mixed
- Gets a cookie
- getCookies() : array<string|int, mixed>
- Alias for getCookie() to get all cookies
- getCurrentURL() : string
- Returns the current URL
- getDomain() : string
- Returns the app domain as specified in the configuration (`host=`)
- getExecutionTime() : float|null
- getFile() : mixed
- Gets a posted file
- getFiles() : array<string|int, mixed>
- Alias for getFile() to get all posted files
- getGet() : string|mixed
- Gets a GET parameter
- getJson() : mixed
- Decode request body as JSON.
- getModel() : Model
- Returns a model
- getParameters() : array<string|int, mixed>|string
- Gets the URL parameters (including the leading controller and action) specified by the path.
- getPost() : string|mixed
- Gets a POST parameter
- getReadableParameter() : array<string|int, string>
- Works like getParameters and decodes an SEO optimized URL. Example: test.com/episodes/this-is-some-text-64 The 64 is an id
- getRequestingUser() : User
- Gets the user who made the request.
- getRoot() : string
- Returns the current root URL including protocol and root directory
- getRootFolder() : string
- Gets the path to the root folder of the project.
- getRouteParameter() : mixed
- getUrlParts() : array<string|int, mixed>
- getZRoot() : string
- Returns the framework root directory
- getZViews() : string
- Returns the ZViews directory
- hasFormData() : bool
- Checks if the request contains form data. When it contains form data, methods like validateForm() can be used.
- ip() : string|null
- Gets the IP of a request
- isAction() : bool
- Checks if the request is an async AJAX request of a given type
- isCli() : bool
- Detects if a request was made from the console
- referer() : string|null
- userAgent() : string|null
- validateCED() : Result
- Validates a "Create Edit Delete" input
- validateForm() : Result
- Validates form data from the client
Properties
$booter
public
ZubZet
$booter
The framework object
$input
public
State
$input
$store
public
array<string|int, mixed>
$store
= []
Store values within the Request to pass through data within internal redirects
$urlParameters
public
array<string|int, mixed>
$urlParameters
= []
$urlParts
public
array<string|int, mixed>
$urlParts
Methods
__construct()
public
__construct(State $input) : mixed
Parameters
- $input : State
Return values
mixed —checkPermission()
Checks if the current user has a permission. If the user is not logged in, they will be redirected to the login page.
public
checkPermission(string $permission[, bool $boolResult = false ][, bool $includeSuperUser = false ]) : bool
If the user is logged in but does not have the permission, they will be redirected to 403.
Parameters
- $permission : string
-
Permission to check for
- $boolResult : bool = false
-
If true, the function will return a boolean result instead of redirecting
- $includeSuperUser : bool = false
Return values
bool —checkSuperPermission()
public
checkSuperPermission(string $permission[, bool $boolResult = false ]) : bool
Parameters
- $permission : string
- $boolResult : bool = false
Return values
bool —getBody()
Get the body of the request
public
getBody() : string|null
Reads the raw input from the request body.
Return values
string|null —The raw body content of the request (Returns an empty string if empty or unavailable).
getBooterSettings()
Gets a booter setting
public
getBooterSettings([string $key = null ][, mixed $useDefault = true ][, mixed $default = null ]) : mixed
Parameters
- $key : string = null
-
Key of the setting
- $useDefault : mixed = true
- $default : mixed = null
Return values
mixed —Value of the key
getCookie()
Gets a cookie
public
getCookie([string $key = null ][, mixed $default = null ]) : mixed
Parameters
- $key : string = null
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
mixed —Content of the cookie
getCookies()
Alias for getCookie() to get all cookies
public
getCookies() : array<string|int, mixed>
Return values
array<string|int, mixed> —The cookies
getCurrentURL()
Returns the current URL
public
getCurrentURL() : string
Return values
string —Returns the current URL, consisting of the configured host and the actual current path
getDomain()
Returns the app domain as specified in the configuration (`host=`)
public
getDomain() : string
Return values
string —the domain
getExecutionTime()
public
getExecutionTime() : float|null
Return values
float|null —getFile()
Gets a posted file
public
getFile([string|null $key = null ][, mixed $default = null ]) : mixed
Parameters
- $key : string|null = null
-
The name of the file
- $default : mixed = null
-
Default value if the file is not posted
Return values
mixed —The posted file
getFiles()
Alias for getFile() to get all posted files
public
getFiles() : array<string|int, mixed>
Return values
array<string|int, mixed> —The posted files
getGet()
Gets a GET parameter
public
getGet([string $key = null ][, mixed $default = null ]) : string|mixed
Parameters
- $key : string = null
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
string|mixed —The content of the GET value
getJson()
Decode request body as JSON.
public
getJson() : mixed
This method decodes the raw request body as JSON and returns the resulting value. Objects and arrays are returned as associative arrays.
Tags
Return values
mixed —The decoded JSON value, or null if the body is empty.
getModel()
Returns a model
public
getModel(string $model[, string $dir = null ]) : Model
Parameters
- $model : string
-
Name of the model
- $dir : string = null
-
Set this when the model is stored in a specific directory
Return values
Model —The model
getParameters()
Gets the URL parameters (including the leading controller and action) specified by the path.
public
getParameters(int $offset[, int $length = null ][, string $val = null ]) : array<string|int, mixed>|string
Parameters
- $offset : int
-
The offset from which to start. Can be -1 if action_fallback is used
- $length : int = null
-
The amount of array elements that will be returned at the set offset. If null, every element will be returned
- $val : string = null
-
If the length is 1, a Boolean will be returned. $val will be compared to the parameter
Return values
array<string|int, mixed>|string —getPost()
Gets a POST parameter
public
getPost([string|null $key = null ][, mixed $default = null ]) : string|mixed
Parameters
- $key : string|null = null
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
string|mixed —The content of the POST value
getReadableParameter()
Works like getParameters and decodes an SEO optimized URL. Example: test.com/episodes/this-is-some-text-64 The 64 is an id
public
getReadableParameter(int $offset) : array<string|int, string>
Parameters
- $offset : int
-
The offset from which to start. Can be -1 if action_fallback is used
Return values
array<string|int, string> —[id, text] of the URL
getRequestingUser()
Gets the user who made the request.
public
getRequestingUser() : User
Return values
User —Object of the requesting user
getRoot()
Returns the current root URL including protocol and root directory
public
getRoot() : string
Return values
string —a URL like $opt["root"] but including the host before
getRootFolder()
Gets the path to the root folder of the project.
public
getRootFolder() : string
Return values
string —Path to the root folder
getRouteParameter()
public
getRouteParameter([mixed $key = null ]) : mixed
Parameters
- $key : mixed = null
Return values
mixed —getUrlParts()
public
getUrlParts() : array<string|int, mixed>
Return values
array<string|int, mixed> —getZRoot()
Returns the framework root directory
public
getZRoot() : string
Return values
string —getZViews()
Returns the ZViews directory
public
getZViews() : string
Return values
string —hasFormData()
Checks if the request contains form data. When it contains form data, methods like validateForm() can be used.
public
hasFormData() : bool
Return values
bool —ip()
Gets the IP of a request
public
ip() : string|null
Return values
string|null —The IP of the client. False if no IP is detected
isAction()
Checks if the request is an async AJAX request of a given type
public
isAction(string $type) : bool
Parameters
- $type : string
-
Type of the request. Request is sent via Z.js => Z.Request.action()
Return values
bool —True if the request is of the specified type
isCli()
Detects if a request was made from the console
public
isCli() : bool
Return values
bool —True if the request was made from a console
referer()
public
referer() : string|null
Return values
string|null —userAgent()
public
userAgent() : string|null
Return values
string|null —validateCED()
Validates a "Create Edit Delete" input
public
validateCED(string $name, array<string|int, mixed> $rules) : Result
Parameters
- $name : string
-
Name of the input field
- $rules : array<string|int, mixed>
-
Array of rules for validating
Return values
Result —Result of the validation. Needed to perform response actions
validateForm()
Validates form data from the client
public
validateForm(array<string|int, Field> $fields[, array<string|int, mixed> $data = null ]) : Result
Parameters
- $fields : array<string|int, Field>
-
Array of fields with the validation rules
- $data : array<string|int, mixed> = null
-
Input for the validation. getGet() or getPost() can be used here as parameters
Return values
Result —A result to work with