Utils
in package
Table of Contents
- assertValidName() : mixed
- Upholds the spec rules about naming.
- assign() : object
- charCodeAt() : mixed
- Returns UTF-8 char code at given $positing of the $string
- chr() : string
- UTF-8 compatible chr()
- each() : void
- every() : bool
- filter() : array<string|int, mixed>
- find() : mixed|null
- getVariableType() : string
- groupBy() : array<string|int, array<string|int, mixed>>
- Splits original iterable to several arrays with keys equal to $keyFn return
- invariant() : mixed
- isInvalid() : bool
- Check if the value is invalid
- isValidNameError() : Error|null
- Returns an Error if a name is invalid.
- keyMap() : array<string|int, mixed>
- keyValMap() : array<string|int, mixed>
- map() : array<string|int, mixed>
- mapKeyValue() : array<string|int, mixed>
- ord() : mixed
- UTF-8 compatible ord()
- orList() : string
- printCharCode() : string
- printSafe() : string
- printSafeJson() : string
- quotedOrList() : string
- some() : bool
- suggestionList() : array<string|int, string>
- Given an invalid input string and a list of valid options, returns a filtered list of valid options sorted based on their similarity with the input.
- undefined() : mixed
- withErrorHandling() : callable
- Wraps original callable with PHP error handling (using set_error_handler).
Methods
assertValidName()
Upholds the spec rules about naming.
public
static assertValidName(string $name) : mixed
Parameters
- $name : string
Tags
Return values
mixed —assign()
public
static assign(object $obj, array<string|int, mixed> $vars[, array<string|int, string> $requiredKeys = [] ]) : object
Parameters
- $obj : object
- $vars : array<string|int, mixed>
- $requiredKeys : array<string|int, string> = []
Return values
object —charCodeAt()
Returns UTF-8 char code at given $positing of the $string
public
static charCodeAt(string $string, int $position) : mixed
Parameters
- $string : string
- $position : int
Return values
mixed —chr()
UTF-8 compatible chr()
public
static chr(string $ord[, string $encoding = 'UTF-8' ]) : string
Parameters
- $ord : string
- $encoding : string = 'UTF-8'
Return values
string —each()
public
static each(iteratable<string|int, mixed> $iterable, callable $fn) : void
Parameters
- $iterable : iteratable<string|int, mixed>
- $fn : callable
Return values
void —every()
public
static every(iteratable<string|int, mixed> $iterable, callable $predicate) : bool
Parameters
- $iterable : iteratable<string|int, mixed>
- $predicate : callable
Return values
bool —filter()
public
static filter(iteratable<string|int, mixed> $iterable, callable $predicate) : array<string|int, mixed>
Parameters
- $iterable : iteratable<string|int, mixed>
- $predicate : callable
Tags
Return values
array<string|int, mixed> —find()
public
static find(iteratable<string|int, mixed> $iterable, callable $predicate) : mixed|null
Parameters
- $iterable : iteratable<string|int, mixed>
- $predicate : callable
Return values
mixed|null —getVariableType()
public
static getVariableType(Type|mixed $var) : string
Parameters
- $var : Type|mixed
Return values
string —groupBy()
Splits original iterable to several arrays with keys equal to $keyFn return
public
static groupBy(iteratable<string|int, mixed> $iterable, callable $keyFn) : array<string|int, array<string|int, mixed>>
E.g. Utils::groupBy([1, 2, 3, 4, 5], function($value) {return $value % 3}) will output: [ 1 => [1, 4], 2 => [2, 5], 0 => [3], ]
$keyFn is also allowed to return array of keys. Then value will be added to all arrays with given keys
Parameters
- $iterable : iteratable<string|int, mixed>
- $keyFn : callable
Return values
array<string|int, array<string|int, mixed>> —invariant()
public
static invariant(bool $test[, string $message = '' ]) : mixed
Parameters
- $test : bool
- $message : string = ''
Return values
mixed —isInvalid()
Check if the value is invalid
public
static isInvalid(mixed $value) : bool
Parameters
- $value : mixed
Return values
bool —isValidNameError()
Returns an Error if a name is invalid.
public
static isValidNameError(string $name[, Node|null $node = null ]) : Error|null
Parameters
- $name : string
- $node : Node|null = null
Return values
Error|null —keyMap()
public
static keyMap(iteratable<string|int, mixed> $iterable, callable $keyFn) : array<string|int, mixed>
Parameters
- $iterable : iteratable<string|int, mixed>
- $keyFn : callable
Tags
Return values
array<string|int, mixed> —keyValMap()
public
static keyValMap(iteratable<string|int, mixed> $iterable, callable $keyFn, callable $valFn) : array<string|int, mixed>
Parameters
- $iterable : iteratable<string|int, mixed>
- $keyFn : callable
- $valFn : callable
Return values
array<string|int, mixed> —map()
public
static map(iteratable<string|int, mixed> $iterable, callable $fn) : array<string|int, mixed>
Parameters
- $iterable : iteratable<string|int, mixed>
- $fn : callable
Tags
Return values
array<string|int, mixed> —mapKeyValue()
public
static mapKeyValue(iteratable<string|int, mixed> $iterable, callable $fn) : array<string|int, mixed>
Parameters
- $iterable : iteratable<string|int, mixed>
- $fn : callable
Tags
Return values
array<string|int, mixed> —ord()
UTF-8 compatible ord()
public
static ord(string $char[, string $encoding = 'UTF-8' ]) : mixed
Parameters
- $char : string
- $encoding : string = 'UTF-8'
Return values
mixed —orList()
public
static orList(array<string|int, string> $items) : string
Parameters
- $items : array<string|int, string>
Return values
string —printCharCode()
public
static printCharCode(int|null $code) : string
Parameters
- $code : int|null
Return values
string —printSafe()
public
static printSafe(Type|mixed $var) : string
Parameters
- $var : Type|mixed
Return values
string —printSafeJson()
public
static printSafeJson(mixed $var) : string
Parameters
- $var : mixed
Return values
string —quotedOrList()
public
static quotedOrList(array<string|int, string> $items) : string
Parameters
- $items : array<string|int, string>
Return values
string —some()
public
static some(iteratable<string|int, mixed> $iterable, callable $predicate) : bool
Parameters
- $iterable : iteratable<string|int, mixed>
- $predicate : callable
Return values
bool —suggestionList()
Given an invalid input string and a list of valid options, returns a filtered list of valid options sorted based on their similarity with the input.
public
static suggestionList(string $input, array<string|int, string> $options) : array<string|int, string>
Includes a custom alteration from Damerau-Levenshtein to treat case changes as a single edit which helps identify mis-cased values with an edit distance of 1
Parameters
- $input : string
- $options : array<string|int, string>
Return values
array<string|int, string> —undefined()
public
static undefined() : mixed
Return values
mixed —withErrorHandling()
Wraps original callable with PHP error handling (using set_error_handler).
public
static withErrorHandling(callable $fn, array<string|int, ErrorException> &$errors) : callable
Resulting callable will collect all PHP errors that occur during the call in $errors array.
Parameters
- $fn : callable
- $errors : array<string|int, ErrorException>