Request
extends RequestResponseHandler
in package
Base class for Response and Request
Table of Contents
- $booter : z_framework
- $store : array<string|int, mixed>
- __construct() : mixed
- Constructor that every request and response object should have
- checkPermission() : mixed
- Checks if the current user has a permission. If the user is not logged in, they will be redirected to the login page.
- getActionStack() : array<string|int, string>
- Returns a list of all visited actions
- getBooterSettings() : mixed
- Gets a booter setting
- getConfigFile() : string
- Gets the relative path to the config file of the framework
- getControllerStack() : array<string|int, string>
- Returns a list of all visited controllers
- getCookie() : mixed
- Gets a cookie
- getCurrentURL() : string
- Returns the current URL
- getDomain() : string
- Returns the app domain as specified in the configuration (`host=`)
- getExecutionTime() : mixed
- getFile() : string|mixed
- Gets a posted file
- getGet() : string|mixed
- Gets a GET parameter
- getLastController() : string
- Returns the last controller visited before the current one
- getModel() : z_model
- Gets the database communication interface
- 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
- getPreAction() : string
- Returns the last action visited before the current one
- 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
- getReCaptchaV3Score() : float
- A backend implementation of the Google reCAPTCHA v3 API
- 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.
- getZControllers() : string
- Returns the ZControllers directory
- 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() : bool|string
- 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() : mixed
- updateErrorHandling() : mixed
- Updates the error handling state.
- userAgent() : mixed
- validateCED() : FormResult
- Validates a "Create Edit Delete" input
- validateForm() : FormResult
- Validates form data from the client
Properties
$booter
public
z_framework
$booter
The framework object
$store
public
array<string|int, mixed>
$store
= []
Store values within the Request to pass through data within internal redirects
Methods
__construct()
Constructor that every request and response object should have
public
__construct(z_framework $booter) : mixed
Parameters
- $booter : z_framework
-
The framework object
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 ]) : mixed
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
Return values
mixed —getActionStack()
Returns a list of all visited actions
public
getActionStack() : array<string|int, string>
Return values
array<string|int, string> —All visited actions as an array
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
getConfigFile()
Gets the relative path to the config file of the framework
public
getConfigFile() : string
Return values
string —Relative path to the config file
getControllerStack()
Returns a list of all visited controllers
public
getControllerStack() : array<string|int, string>
Return values
array<string|int, string> —All visited controllers as an array
getCookie()
Gets a cookie
public
getCookie(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
mixed —Content of the cookie
getCurrentURL()
Returns the current URL
public
getCurrentURL() : string
Return values
string —The actual URL that was requested including parameters and host
getDomain()
Returns the app domain as specified in the configuration (`host=`)
public
getDomain() : string
Return values
string —the domain
getExecutionTime()
public
getExecutionTime() : mixed
Return values
mixed —getFile()
Gets a posted file
public
getFile(string $key[, mixed $default = null ]) : string|mixed
Parameters
- $key : string
-
The name of the file
- $default : mixed = null
-
Default value if the file is not posted
Return values
string|mixed —The posted file
getGet()
Gets a GET parameter
public
getGet(string $key[, mixed $default = null ]) : string|mixed
Parameters
- $key : string
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
string|mixed —The content of the GET value
getLastController()
Returns the last controller visited before the current one
public
getLastController() : string
Return values
string —The last controller visited before the current one
getModel()
Gets the database communication interface
public
getModel() : z_model
Return values
z_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 $key[, mixed $default = null ]) : string|mixed
Parameters
- $key : string
-
The key of the parameter
- $default : mixed = null
-
Default value
Return values
string|mixed —The content of the POST value
getPreAction()
Returns the last action visited before the current one
public
getPreAction() : string
Return values
string —The last action visited before the current one
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
getReCaptchaV3Score()
A backend implementation of the Google reCAPTCHA v3 API
public
getReCaptchaV3Score(string $response, string $action, string $secretKey[, bool $checkHostname = true ]) : float
Parameters
- $response : string
-
The response you have received from the Google reCAPTCHA execution
- $action : string
-
The action name used in reCAPTCHA verification
- $secretKey : string
-
Your reCAPTCHA secret key. (Can be retrieved from https://www.google.com/recaptcha/intro/v3.html)
- $checkHostname : bool = true
-
Whether to check if the hostname matches
Return values
float —The score between 0-1 returned by Google
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
getZControllers()
Returns the ZControllers directory
public
getZControllers() : string
Return values
string —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() : bool|string
Return values
bool|string —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() : mixed
Return values
mixed —updateErrorHandling()
Updates the error handling state.
public
updateErrorHandling(int $state) : mixed
Parameters
- $state : int
-
Error state. See: z_framework::updateErrorHandling($state)
Return values
mixed —userAgent()
public
userAgent() : mixed
Return values
mixed —validateCED()
Validates a "Create Edit Delete" input
public
validateCED(string $name, array<string|int, mixed> $rules) : FormResult
Parameters
- $name : string
-
Name of the input field
- $rules : array<string|int, mixed>
-
Array of rules for validating
Return values
FormResult —Result of the validation. Needed to perform response actions
validateForm()
Validates form data from the client
public
validateForm(array<string|int, FormField> $fields[, array<string|int, mixed> $data = null ]) : FormResult
Parameters
- $fields : array<string|int, FormField>
-
Array of fields with the validation rules
- $data : array<string|int, mixed> = null
-
Input for the validation. $_GET or $_POST can be used here as parameters
Return values
FormResult —A result to work with