Welcome to FrostSW!

FrostMVC PHP Framework

Documentation   |   Version

Functions

FrostMVC\Functions

use FrostMVC\Functions;

General-purpose utility methods for the FrostMVC framework.

Methods

::Bush()

Obfuscates a string by interspersing random hex byte pairs between each character. A trailing random hex pair is appended. Intended for lightweight display obfuscation only — not a cryptographic or security mechanism.

->call() —
::countries() —
::default()

Returns a default value when the given variable is null, empty, or absent from an array.

::error()

Renders the standard error page with the given HTTP status and message. Terminates the current request via die().

::generateCaptcha()

Generates a random 7-character captcha code using an unambiguous character set (ambiguous characters like 0/O, 1/I are excluded). No character repeats.

::generateOTP()

Generates a numeric OTP of the requested length. The first digit is never zero. Within the first five digits, no digit repeats. After the fifth digit, no digit is the same as the immediately preceding one.

::generateToken()

Generates a cryptographically random alphanumeric token.

::getErrorMessage()

Returns and clears the stored error message set by setErrorMessage().

::getMaxUploadSize()

Returns the smaller of the post_max_size and upload_max_filesize PHP INI values, in bytes. The result is computed once and cached in a static variable.

::io_relocate()

Performs a client-side redirect by rendering the io_relocate Twig template. Terminates the current request via die().

::parse_size()

Parses a human-readable PHP INI size string (e.g. '8M', '256K', '1G') into bytes.

::sendSMS() —
::setErrorMessage()

Stores a one-time error message to be retrieved with getErrorMessage(). Useful for passing validation errors through non-redirect flows.

::ToByteUnit()

Converts a byte count into a human-readable string with the appropriate unit (bytes, KB, MB, or GB), rounded to 2 decimal places.

::val()

Extracts a floating-point number from a string that may contain non-numeric characters. Retains digits, decimal point, sign characters (+/-), and hyphen.

::writeLog() —
::xhrResult()

Emits a JSON response with an optional refreshed CSRF token and terminates the request. If $result is an array it is used directly as the response object; otherwise it is placed under the 'result' key alongside any $data fields.

Bush() static

Functions::Bush($value)

Obfuscates a string by interspersing random hex byte pairs between each character. A trailing random hex pair is appended. Intended for lightweight display obfuscation only — not a cryptographic or security mechanism.

Parameters

$value string

The string to obfuscate.

Returns

string

call()

$functions->call($callback, ...$args)

No description yet.

Parameters

$callback mixed
...$args mixed

countries() static

Functions::countries()

No description yet.

default() static

Functions::default($var, ...$params)

Returns a default value when the given variable is null, empty, or absent from an array.

Forms:

  • default($var, $fallback): returns $var, or $fallback when $var is null/empty string.
  • default($array, 'key', $fallback): reads $array['key'], or $fallback on absence.
  • default($var, 'callable', ...args): calls 'callable' with $var (and optional args) when $var is present. Use the '${value}' placeholder among args to control where $var is injected.

Parameters

$var mixed

The value or array to inspect.

...$params mixed

Fallback value, callable, or array key + fallback.

Returns

mixed

error() static

Functions::error($message, $error = '', $code = 404, $title = 'Not Found', $uri = false)

Renders the standard error page with the given HTTP status and message. Terminates the current request via die().

Parameters

$message string

Human-readable error description.

$error string

Error title or type (shown in Development mode).

Default: ''
$code int

HTTP status code. Defaults to 404.

Default: 404
$title string

HTTP status phrase.

Default: 'Not Found'
$uri string|false

Optional URI context to include in the error view.

Default: false

generateCaptcha() static

Functions::generateCaptcha()

Generates a random 7-character captcha code using an unambiguous character set (ambiguous characters like 0/O, 1/I are excluded). No character repeats.

Returns

string

generateOTP() static

Functions::generateOTP($length = 8)

Generates a numeric OTP of the requested length. The first digit is never zero. Within the first five digits, no digit repeats. After the fifth digit, no digit is the same as the immediately preceding one.

Parameters

$length int

Number of digits. Defaults to 8.

Default: 8

Returns

string

generateToken() static

Functions::generateToken($length)

Generates a cryptographically random alphanumeric token.

Parameters

$length int

The number of characters in the token.

Returns

string

getErrorMessage() static

Functions::getErrorMessage()

Returns and clears the stored error message set by setErrorMessage().

Returns

string The message, or an empty string if none was set.

getMaxUploadSize() static

Functions::getMaxUploadSize()

Returns the smaller of the post_max_size and upload_max_filesize PHP INI values, in bytes. The result is computed once and cached in a static variable.

Returns

int Maximum upload size in bytes, or -1 if indeterminate.

io_relocate() static

Functions::io_relocate($url, $reload = false)

Performs a client-side redirect by rendering the io_relocate Twig template. Terminates the current request via die().

Parameters

$url string

The destination URL.

$reload bool

When true, signals the client that the current page should reload.

Default: false

parse_size() static

Functions::parse_size($size)

Parses a human-readable PHP INI size string (e.g. '8M', '256K', '1G') into bytes.

Parameters

$size string

A value from ini_get(), such as '8M'.

Returns

float The size in bytes.

sendSMS() static

Functions::sendSMS($phonenumber, $message)

No description yet.

Parameters

$phonenumber mixed
$message mixed

setErrorMessage() static

Functions::setErrorMessage($message)

Stores a one-time error message to be retrieved with getErrorMessage(). Useful for passing validation errors through non-redirect flows.

Parameters

$message string

ToByteUnit() static

Functions::ToByteUnit($byte)

Converts a byte count into a human-readable string with the appropriate unit (bytes, KB, MB, or GB), rounded to 2 decimal places.

Parameters

$byte int

Size in bytes.

Returns

string

val() static

Functions::val($string)

Extracts a floating-point number from a string that may contain non-numeric characters. Retains digits, decimal point, sign characters (+/-), and hyphen.

Parameters

$string string

The string to parse.

Returns

float

writeLog() static deprecated

Functions::writeLog($file, $value = false)
Deprecated.

Use Logs::write() instead.

No description yet.

Parameters

$file mixed
$value mixed Default: false

xhrResult() static

Functions::xhrResult($result, $data = [], $jsonFlag = JSON_INVALID_UTF8_SUBSTITUTE)

Emits a JSON response with an optional refreshed CSRF token and terminates the request. If $result is an array it is used directly as the response object; otherwise it is placed under the 'result' key alongside any $data fields.

Parameters

$result mixed

The primary result value, or an associative array used as the full response.

$data mixed

Additional key-value pairs to merge into the response, or a message string.

Default: []
$jsonFlag int

json_encode() flags. Defaults to JSON_INVALID_UTF8_SUBSTITUTE.

Default: JSON_INVALID_UTF8_SUBSTITUTE

Generated from core/classes/Functions.php (FrostMVC ).