Request
extends RequestResponseHandler
in package
Base class for Response and Request
Table of Contents
- $booter : z_framework
- $store : array<string|int, mixed>
- $urlParameters : array<string|int, mixed>
- __construct() : mixed
- Constructor that every request and response object should have
- 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
- Get the body of the request
- getBooterSettings() : mixed
- Gets a booter setting
- 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
- getJson() : mixed
- Decode request body as JSON.
- 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
- 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
- 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
- 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
$urlParameters
public
array<string|int, mixed>
$urlParameters
= []
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 ][, 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
Reads the raw input from the request body.
Return values
string —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[, 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
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()
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
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 —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 —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