class Utils

Utility static functions

Methods

static bool
checkVersion(string $currentVersion, string $requiredVersion, string|null $operator = null)

Return true if required version = current or <

static bool
isValidUrl(string $url)

Return true if url is valid

static array
getClasses(string $phpCode)

Return classes from php code

static string|false
getParentPath(string $path)

Get parent path

static string
createRandomKey()

Create random key

static string
createToken(string $prefix = '', bool $long = false)

Create unique token

static bool
isValidIp(string $ip)

Return true if ip is valid.

static bool
isImplemented(object $obj, string $interfaceName)

Check if class implement interface

static mixed
constant(string $name, mixed $default = null)

Return constant value or default if constant not defined.

static string
convertPathToUrl(string $path)

Convert path to url

static bool
isJson(string|null $jsonText)

Return true if text is valid JSON

static string
jsonEncode(array $data)

Encode array to JSON

static string
cleanJson(string $text)

Clean JSON text

static array
jsonDecode(string|null $text, bool $clean = true, bool|null $associative = true)

Decode JSON text

static mixed
callStatic(string $class, string $method, array|null $args = null)

Call static method

static mixed
call(object $obj, string|null $method, array|null $args = null)

Call object method

static bool
isEmail(string $email)

Return true if email is valid

static bool
hasHtml(string $text)

Check if text contains thml tags

static string|null
removeBOM(string $text)

Remove BOM from text

static bool
isEmpty(mixed $var)

Check if variable is empty

static string
formatVersion(string|null $version)

Format version to full version format 0.0.0

static string
createKey(string $text, string|null $pathItem = null, string $separator = '.')

Create key

mixed
getDefault(mixed $variable, mixed $default)

Return default if variable is empty

static string
getValueAsText(mixed $value)

Convert value to text

static bool
isClosure(mixed $variable)

Return true if variable is Closure

static bool
isUtf(mixed $text)

Return true if text is utf8 encoded string

static string
slug(string $text, string $separator = '-')

Create slug

static string|array
getMemorySizeText(integer $size, string|null $labels = null, bool $asText = true)

Get memory size text.

static string
getBaseClassName(string|object $class)

Return base class name

static int
getExecutionTime(string $constantName = 'APP_START_TIME')

Get script execution time

Details

at line 28
static bool checkVersion(string $currentVersion, string $requiredVersion, string|null $operator = null)

Return true if required version = current or <

Parameters

string $currentVersion
string $requiredVersion
string|null $operator

Return Value

bool

at line 46
static bool isValidUrl(string $url)

Return true if url is valid

Parameters

string $url

Return Value

bool

at line 57
static array getClasses(string $phpCode)

Return classes from php code

Parameters

string $phpCode

Return Value

array

at line 83
static string|false getParentPath(string $path)

Get parent path

Parameters

string $path

Return Value

string|false

at line 98
static string createRandomKey()

Create random key

Return Value

string

at line 110
static string createToken(string $prefix = '', bool $long = false)

Create unique token

Parameters

string $prefix
bool $long

Return Value

string

at line 125
static bool isValidIp(string $ip)

Return true if ip is valid.

Parameters

string $ip

Return Value

bool

at line 137
static bool isImplemented(object $obj, string $interfaceName)

Check if class implement interface

Parameters

object $obj
string $interfaceName

Return Value

bool

at line 164
static mixed constant(string $name, mixed $default = null)

Return constant value or default if constant not defined.

Parameters

string $name
mixed $default

Return Value

mixed

at line 175
static string convertPathToUrl(string $path)

Convert path to url

Parameters

string $path

Return Value

string

at line 186
static bool isJson(string|null $jsonText)

Return true if text is valid JSON

Parameters

string|null $jsonText

Return Value

bool

at line 206
static string jsonEncode(array $data)

Encode array to JSON

Parameters

array $data

Return Value

string

at line 217
static string cleanJson(string $text)

Clean JSON text

Parameters

string $text

Return Value

string

at line 238
static array jsonDecode(string|null $text, bool $clean = true, bool|null $associative = true)

Decode JSON text

Parameters

string|null $text
bool $clean
bool|null $associative

Return Value

array

at line 256
static mixed callStatic(string $class, string $method, array|null $args = null)

Call static method

Parameters

string $class
string $method
array|null $args

Return Value

mixed

at line 269
static mixed call(object $obj, string|null $method, array|null $args = null)

Call object method

Parameters

object $obj
string|null $method
array|null $args

Return Value

mixed

at line 294
static bool isEmail(string $email)

Return true if email is valid

Parameters

string $email

Return Value

bool

at line 305
static bool hasHtml(string $text)

Check if text contains thml tags

Parameters

string $text

Return Value

bool

at line 316
static string|null removeBOM(string $text)

Remove BOM from text

Parameters

string $text

Return Value

string|null

at line 327
static bool isEmpty(mixed $var)

Check if variable is empty

Parameters

mixed $var

Return Value

bool

at line 338
static string formatVersion(string|null $version)

Format version to full version format 0.0.0

Parameters

string|null $version

Return Value

string

at line 357
static string createKey(string $text, string|null $pathItem = null, string $separator = '.')

Create key

Parameters

string $text
string|null $pathItem
string $separator

Return Value

string

at line 369
mixed getDefault(mixed $variable, mixed $default)

Return default if variable is empty

Parameters

mixed $variable
mixed $default

Return Value

mixed

at line 380
static string getValueAsText(mixed $value)

Convert value to text

Parameters

mixed $value

Return Value

string

at line 398
static bool isClosure(mixed $variable)

Return true if variable is Closure

Parameters

mixed $variable

Return Value

bool

at line 409
static bool isUtf(mixed $text)

Return true if text is utf8 encoded string

Parameters

mixed $text

Return Value

bool

at line 421
static string slug(string $text, string $separator = '-')

Create slug

Parameters

string $text
string $separator

Return Value

string

at line 445
static string|array getMemorySizeText(integer $size, string|null $labels = null, bool $asText = true)

Get memory size text.

Parameters

integer $size
string|null $labels
bool $asText

Return Value

string|array

at line 461
static string getBaseClassName(string|object $class)

Return base class name

Parameters

string|object $class

Return Value

string

at line 475
static int getExecutionTime(string $constantName = 'APP_START_TIME')

Get script execution time

Parameters

string $constantName

Return Value

int