abstract class Utilities

Abstract with some global static utility functions

Properties

static private $chars

Methods

static int
RandomRange()

Returns the number of possible characters for a digit in Random

static string
Random(int $length)

Returns a random string with the given length

static string
JSONEncode($data)

Encodes the data as JSON

static 
JSONDecode(string $data)

Decodes the JSON data as an array

static 
GetHashAlgo()

Returns the best password_hash algorithm available

static 
array_last(array|null $arr)

Returns the last element of an array or null if it's empty

static array
delete_value(array $arr, $value)

Deletes any of the given value from the given array reference

static string|null
ShortClassName(string|null $class)

Returns a class name with the namespace stripped

static string
FirstUpper(string $str)

Returns the given string with the first character capitalized

static int
return_bytes(string $val)

Returns a size string converted to bytes

static string
replace_first(string $search, string $replace, string $subject)

Equivalent to str_replace but only does one replacement

static string
CaptureOutput(callable $func)

Captures and returns any echoes or prints in the given function

static array
array_map_keys(callable $func, array $keys)

Performs a key-based array map

static array
getClassesMatching(string $match)

Returns all classes that are a $match type

static 
RunAtomic(callable $func)

Runs the given function with no execution timeouts or user aborts

Details

at line 116
static int RandomRange()

Returns the number of possible characters for a digit in Random

Return Value

int

at line 119
static string Random(int $length)

Returns a random string with the given length

Parameters

int $length

Return Value

string

at line 132
static string JSONEncode($data)

Encodes the data as JSON

Parameters

$data

Return Value

string

Exceptions

JSONEncodingException

at line 143
static JSONDecode(string $data)

Decodes the JSON data as an array

Parameters

string $data

Exceptions

JSONDecodingException

at line 151
static GetHashAlgo()

Returns the best password_hash algorithm available

at line 159
static array_last(array|null $arr)

Returns the last element of an array or null if it's empty

Parameters

array|null $arr

at line 167
static array delete_value(array $arr, $value)

Deletes any of the given value from the given array reference

Parameters

array $arr
$value

Return Value

array

at line 173
static string|null ShortClassName(string|null $class)

Returns a class name with the namespace stripped

Parameters

string|null $class

Return Value

string|null

at line 177
static string FirstUpper(string $str)

Returns the given string with the first character capitalized

Parameters

string $str

Return Value

string

at line 185
static int return_bytes(string $val)

Returns a size string converted to bytes

Parameters

string $val

a size string e.g. 32M or 4K

Return Value

int

formatted as bytes e.g. 33554432 or 4096

at line 200
static string replace_first(string $search, string $replace, string $subject)

Equivalent to str_replace but only does one replacement

Parameters

string $search
string $replace
string $subject

Return Value

string

at line 212
static string CaptureOutput(callable $func)

Captures and returns any echoes or prints in the given function

Parameters

callable $func

Return Value

string

at line 222
static array array_map_keys(callable $func, array $keys)

Performs a key-based array map

Parameters

callable $func

function to map onto each key

array $keys

array of keys to use in result

Return Value

array

at line 228
static array getClassesMatching(string $match)

Returns all classes that are a $match type

Parameters

string $match

Return Value

array

at line 235
static RunAtomic(callable $func)

Runs the given function with no execution timeouts or user aborts

Parameters

callable $func