Skip to content

Toolkit

Toolkit provides basic utility methods.

final class Toolkit

Since1.0.0
SourceUtil/Toolkit.php
MethodDescription
[`buildUrl(array{scheme?: string, host?: string, port?: (intstring), user?: string, pass?: string, path?: string, query?: string, fragment?: string} $parts): string`](#buildurl)
canonicalName(string $name): stringReturns the canonical name for a dot-separated view/action/model name.
[`clearCache(string $path = ”): boolvoid`](#clearcache)
evaluateModuleDirective(string $moduleName, string $directiveNameFragment, array<string, mixed> $variables = []): stringEvaluates a given Config per-module directive using the given info.
expandDirectives(?string $value): ?stringReplace configuration directive identifiers in a string.
expandVariables(?string $string, array<string, mixed> $arguments = []): stringExpand variables in a string.
[`floorDivide(float $numerator, intfloat $denominator, int &$remainder): int`](#floordivide)
[`getValueByKeyList(array $array, array<intstring> $keys, mixed $default = null): mixed`](#getvaluebykeylist)
isNotArray(mixed $value): boolChecks if a value is not an array
isPathAbsolute(string $path): boolDetermine if a filesystem path is absolute.
isPortNecessary(string $scheme, int $port): boolDetermines whether a port declaration is necessary in a URL authority.
literalize(mixed $value, bool $expandDirectives = true): mixedLiteralize a string value.
mkdir(string $path, int $mode = 509, bool $recursive = false, resource $context = null): boolCreates a directory without sucking at permissions.
normalizePath(string $path): stringNormalizes a path to contain only ’/’ as path delimiter.
overloadHelper(array<int, array{parameters: array<int, string>, name: string}> $definitions, array<int, mixed> $parameters): stringReturns the method from the given definition list matching the given parameters.
stringBase(string $baseString, string $compString, int &$equalAmount = 0): stringReturns the base for two strings (the part at the beginning of both which is equal)
uniqid(string $prefix = ''): stringGenerate a proper unique ID.

public static function buildUrl(array{scheme?: string, host?: string, port?: (int | string), user?: string, pass?: string, path?: string, query?: string, fragment?: string} $parts): string

Counterpart of PHP’s parse_url().

The parts of the URL as defined by parse_url()

ParameterTypeDescription
$parts`array{scheme?: string, host?: string, port?: (intstring), user?: string, pass?: string, path?: string, query?: string, fragment?: string}`

Returns string

public static function canonicalName(string $name): string

Returns the canonical name for a dot-separated view/action/model name.

The view/action/model name.

ParameterTypeDescription
$namestringThe view/action/model name.

Returns string — The canonical name.

public static function clearCache(string $path = ''): bool|void

Deletes a specified path in the cache dir recursively.

The path to remove

ParameterTypeDescription
$pathstringThe path to remove

Returns bool``|``void — False if the given path could not be resolved.

public static function evaluateModuleDirective(string $moduleName, string $directiveNameFragment, array<string, mixed> $variables = []): string

Evaluates a given Config per-module directive using the given info.

The variables to expand in the directive value.

ParameterTypeDescription
$moduleNamestringThe name of the module
$directiveNameFragmentstringThe relevant name fragment of the directive
$variablesarray``<``string``, ``mixed``>The variables to expand in the directive value.

Returns string — The final value

public static function expandDirectives(?string $value): ?string

Replace configuration directive identifiers in a string.

The value on which to run the replacement procedure.

ParameterTypeDescription
$value?``stringThe value on which to run the replacement procedure.

Returns ?``string — The new value.

public static function expandVariables(?string $string, array<string, mixed> $arguments = []): string

Expand variables in a string.

The variables to use.

ParameterTypeDescription
$string?``stringThe format string.
$argumentsarray``<``string``, ``mixed``>The variables to use.

Returns string — The expanded string.

public static function floorDivide(float $numerator, int|float $denominator, int &$remainder): int

This function takes the numerator and divides it through the denominator while storing the remainder and returning the quotient.

The remainder.

ParameterTypeDescription
$numeratorfloatThe numerator.
$denominator`int““float`
$remainderintThe remainder.

Returns int — The floored quotient.

public static function getValueByKeyList(array<mixed> $array, array<int|string> $keys, mixed $default = null): mixed

Tries to grab a value from the given array using the given list of keys.

A default return value, defaults to null.

ParameterTypeDescription
$arrayarray``<``mixed``>The array to search in.
$keys`array<int“string>`
$defaultmixedA default return value, defaults to null.

Returns mixed — The found value, or the default value if nothing found.

public static function isNotArray(mixed $value): bool

Checks if a value is not an array

The value to check

ParameterTypeDescription
$valuemixedThe value to check

Returns bool — The result.

public static function isPathAbsolute(string $path): bool

Determine if a filesystem path is absolute.

A filesystem path.

ParameterTypeDescription
$pathstringA filesystem path.

Returns bool — true, if the path is absolute, otherwise false.

public static function isPortNecessary(string $scheme, int $port): bool

Determines whether a port declaration is necessary in a URL authority.

The port.

ParameterTypeDescription
$schemestringThe scheme (protocol identifier).
$portintThe port.

Returns bool — True, if port must be included, otherwise false.

public static function literalize(mixed $value, bool $expandDirectives = true): mixed

Literalize a string value.

Whether a leftover string also has its %directive% references expanded. Pass false for text that did not come from a configuration file — EnvPlaceholder literalizes what the environment answered, and what a setting means should not depend on whether a deployment’s variable happens to hold a directive reference.

ParameterTypeDescription
$valuemixedThe value to literalize.
$expandDirectivesboolWhether a leftover string also has its %directive% references expanded. Pass false for text that did not come from a configuration file — EnvPlaceholder literalizes what the environment answered, and what a setting means should not depend on whether a deployment’s variable happens to hold a directive reference.

Returns mixed — A literalized value.

public static function mkdir(string $path, int $mode = 509, bool $recursive = false, resource $context = null): bool

Creates a directory without sucking at permissions.

A Context.

ParameterTypeDescription
$pathstringThe path name.
$modeintThe mode. Really. Defaults to 0775.
$recursiveboolRecursive or not.
$contextresourceA Context.

Returns bool — The mkdir return value.

public static function normalizePath(string $path): string

Normalizes a path to contain only ’/’ as path delimiter.

The path to normalize.

ParameterTypeDescription
$pathstringThe path to normalize.

Returns string — The unified bool The mkdir return value.

public static function overloadHelper(array<int, array{parameters: array<int, string>, name: string}> $definitions, array<int, mixed> $parameters): string

Returns the method from the given definition list matching the given parameters.

The parameters which were passed to the function.

ParameterTypeDescription
$definitionsarray``<``int``, ``array{parameters: array<int, string>, name: string}``>The definitions of the functions.
$parametersarray``<``int``, ``mixed``>The parameters which were passed to the function.

Returns string — The name of the function which matched.

public static function stringBase(string $baseString, string $compString, int &$equalAmount = 0): string

Returns the base for two strings (the part at the beginning of both which is equal)

The number of characters which are equal.

ParameterTypeDescription
$baseStringstringThe base string.
$compStringstringThe string which should be compared to the base string.
$equalAmountintThe number of characters which are equal.

Returns string — The equal part at the beginning of both strings.

public static function uniqid(string $prefix = ''): string

Generate a proper unique ID.

An optional prefix

ParameterTypeDescription
$prefixstringAn optional prefix

Returns string — A properly unique ID