Skip to content

Helpers API

Complete API reference for helper classes.

get(string $key, mixed $default = null): mixed

Section titled “get(string $key, mixed $default = null): mixed”

Get raw environment variable value.

$value = EnvHelper::get('APP_NAME', 'default');

Check if environment variable exists.

if (EnvHelper::has('API_KEY')) {
$apiKey = EnvHelper::get('API_KEY');
}

string(string $key, mixed $default = null, bool $forceCast = true): ?string

Section titled “string(string $key, mixed $default = null, bool $forceCast = true): ?string”

Get environment variable as string.

$appName = EnvHelper::string('APP_NAME', 'My App');

integer(string $key, mixed $default = null, bool $forceCast = true): ?int

Section titled “integer(string $key, mixed $default = null, bool $forceCast = true): ?int”

Get environment variable as integer.

$port = EnvHelper::integer('APP_PORT', 8080);

boolean(string $key, mixed $default = null, bool $forceCast = true): ?bool

Section titled “boolean(string $key, mixed $default = null, bool $forceCast = true): ?bool”

Get environment variable as boolean.

$debug = EnvHelper::boolean('APP_DEBUG', false);

float(string $key, mixed $default = null, bool $forceCast = true): ?float

Section titled “float(string $key, mixed $default = null, bool $forceCast = true): ?float”

Get environment variable as float.

$timeout = EnvHelper::float('REQUEST_TIMEOUT', 30.0);

array(string $key, ?array $default = [], string $separator = ','): ?array

Section titled “array(string $key, ?array $default = [], string $separator = ','): ?array”

Get environment variable as array (comma-separated by default).

$hosts = EnvHelper::array('ALLOWED_HOSTS', ['localhost']);
$tags = EnvHelper::array('TAGS', [], '|'); // Custom separator

add(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float

Section titled “add(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float”

Add two numbers with high precision.

$result = MathHelper::add(0.1, 0.2, 2); // 0.3
$result = MathHelper::add('10.5', '20.3', 2); // 30.8

subtract(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float

Section titled “subtract(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float”

Subtract two numbers with high precision.

$result = MathHelper::subtract(1.0, 0.3, 2); // 0.7
$result = MathHelper::subtract('10', '5', 2); // 5.0

multiply(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float

Section titled “multiply(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): float”

Multiply two numbers with high precision.

$result = MathHelper::multiply(2.5, 3.0, 2); // 7.5
$result = MathHelper::multiply('2.5', '4', 2); // 10.0

divide(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16, bool $throwExceptionAtDivisionByZero = true): float

Section titled “divide(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16, bool $throwExceptionAtDivisionByZero = true): float”

Divide two numbers with high precision.

$result = MathHelper::divide(10.0, 3.0, 4); // 3.3333
$result = MathHelper::divide('10', '3', 2); // 3.33

compare(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): int

Section titled “compare(null|float|int|string $num1, null|float|int|string $num2, int $scale = 16): int”

Compare two numbers. Returns -1 if num1 < num2, 0 if equal, 1 if num1 > num2.

$cmp = MathHelper::compare(1.0, 2.0); // -1
$cmp = MathHelper::compare(2.0, 2.0); // 0
$cmp = MathHelper::compare(3.0, 2.0); // 1

sum(array $numbers, int $scale = 16): float

Section titled “sum(array $numbers, int $scale = 16): float”

Calculate sum of array values.

$result = MathHelper::sum([10, 20, 30]); // 60.0

average(array $numbers, int $scale = 16): float

Section titled “average(array $numbers, int $scale = 16): float”

Calculate average of array values.

$result = MathHelper::average([10, 20, 30]); // 20.0

min(array $numbers, int $scale = 16): float

Section titled “min(array $numbers, int $scale = 16): float”

Find minimum value in array.

$result = MathHelper::min([10, 5, 20, 3]); // 3.0

max(array $numbers, int $scale = 16): float

Section titled “max(array $numbers, int $scale = 16): float”

Find maximum value in array.

$result = MathHelper::max([10, 5, 20, 3]); // 20.0

Get singleton instance.

use event4u\DataHelpers\Helpers\ConfigHelper;
$config = ConfigHelper::getInstance();

get(string $key, mixed $default = null): mixed

Section titled “get(string $key, mixed $default = null): mixed”

Get configuration value with dot notation.

$config = ConfigHelper::getInstance();
$value = $config->get('cache.max_entries', 1000);

getBoolean(string $key, bool $default = false): bool

Section titled “getBoolean(string $key, bool $default = false): bool”

Get configuration value as boolean.

$config = ConfigHelper::getInstance();
$enabled = $config->getBoolean('feature.enabled', false);

getInteger(string $key, int $default = 0): int

Section titled “getInteger(string $key, int $default = 0): int”

Get configuration value as integer.

$config = ConfigHelper::getInstance();
$maxEntries = $config->getInteger('cache.max_entries', 1000);

getFloat(string $key, float $default = 0.0): float

Section titled “getFloat(string $key, float $default = 0.0): float”

Get configuration value as float.

$config = ConfigHelper::getInstance();
$ratio = $config->getFloat('logging.sampling.errors', 1.5);

getString(string $key, string $default = ''): string

Section titled “getString(string $key, string $default = ''): string”

Get configuration value as string.

$config = ConfigHelper::getInstance();
$mode = $config->getString('performance_mode', 'fast');

getArray(string $key, array $default = []): array

Section titled “getArray(string $key, array $default = []): array”

Get configuration value as array.

$config = ConfigHelper::getInstance();
$cacheConfig = $config->getArray('cache', []);

Check if configuration key exists.

$config = ConfigHelper::getInstance();
if ($config->has('database.host')) {
// ...
}

Set configuration value.

$config = ConfigHelper::getInstance();
$config->set('app.debug', true);

Reset configuration to original values.

$config = ConfigHelper::getInstance();
$config->reset();

Split dot-notation path into segments.

use event4u\DataHelpers\Helpers\DotPathHelper;
$segments = DotPathHelper::segments('users.*.name');
// ['users', '*', 'name']

buildPrefix(string $prefix, int|string $segment): string

Section titled “buildPrefix(string $prefix, int|string $segment): string”

Build dot-notation path from prefix and segment.

$path = DotPathHelper::buildPrefix('users', 0);
// 'users.0'

Check if segment is a wildcard.

$isWildcard = DotPathHelper::isWildcard('*'); // true
$isWildcard = DotPathHelper::isWildcard('name'); // false

Check if path contains wildcards.

$hasWildcard = DotPathHelper::containsWildcard('users.*.name'); // true
$hasWildcard = DotPathHelper::containsWildcard('users.0.name'); // false

copy(object $object, bool $recursive = true, int $maxLevel = 10): object

Section titled “copy(object $object, bool $recursive = true, int $maxLevel = 10): object”

Create a deep copy of an object with recursion control.

use event4u\DataHelpers\Helpers\ObjectHelper;
$object = (object)['name' => 'John', 'age' => 30];
$clone = ObjectHelper::copy($object);
// Shallow copy (no recursion)
$shallowClone = ObjectHelper::copy($object, false);
// Deep copy with max recursion level
$deepClone = ObjectHelper::copy($object, true, 5);