Download the PHP package ko-ko-ko/assert without Composer
On this page you can find all versions of the php package ko-ko-ko/assert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package assert
php-assert
Yet another validator, WHY??
It's very fast and designed to be used in any method
There are many other cool asserts, but for their usability you must pay by time & memory of execution. This assert gives you very simple and fast API.
Installation
The preferred way to install this extension is through composer.
or add line to require section of composer.json
Usage
BASIC API
assert($value, $name)
Build validation object
$valuechecking value. MUST be: array, bool, float, int, null, string$namename of variable, used in exception message. MUST be string
VALIDATION API
General asserts
isEmpty Check if value empty
- Antipode: notEmpty
isArray Check if value is array
bool Check if value is bool
float Check if value is float
int Check if value is int
numeric Check if value is numeric
isNull Check if value is null
- Antipode: notNull
string Check if value is string
resource Check if value is resource
inArray($range) Check if value is in array $range
Arguments:
$rangeMUST be array
isSame($anotherValue) Check if value is same as $anotherValue
- Antipode: notSame
Arguments:
$anotherValueMUST be not object
notSame($anotherValue) Check if value is not same as $anotherValue
- Antipode: isSame
Arguments:
$anotherValueMUST be not object
String asserts
All string asserts run previously:
- string
digit Check if value contains only digits
match($pattern) Check if value match RegExp pattern
Arguments:
$patternMUST be correct RegExp pattern
glob($pattern) Check if value match glob pattern
length($length) Check if value has length exactly $length
Arguments:
$lengthMUST be integer >= 0
lengthLess($length) Check if value has length less than $length
- Antipode: lengthMore
Arguments:
$lengthMUST be integer > 0
lengthBetween($from, $to) Check that value length is $from <= $value <= $to
Arguments:
$fromMUST be integer >= 0$toMUST be integer >= 0$fromMUST less than$to
Number asserts (int or float)
All number MUST be int or float
positive Check if value is positive (not 0)
- Antipode: negative
Check if value is negative (not 0)
less($number) Check if value is $value <= $number
- Similar: lessStrict Check that value is
$value < $number - Antipode: more Check that value is
$value >= $number - Antipode: moreStrict Check that value is
$value > $number
Arguments:
$numberMUST be integer or float
between($from, $to) Check that value is $from <= $value <= $to
- Similar: betweenStrict Check that value is
$from < $value < $to
Arguments:
$fromMUST be int or float$toMUST be int or float$fromMUST less than$to
Array asserts
hasKey($key) Check if array key exists
Arguments:
$keyMUST be string or int
count($count) Check if array elements count is same as $count
Arguments:
$countMUST be int and greater than 0
LOOP ASSERTS API
forList Run callable function for each element in list
forMap Run callable function for each element in map
Attention: arrays like ['1' => 'a', '2' => 'b'] php will convert to [1 => 'a', 2 => 'b']
CAST API
get Returns value as is
toBool Converts any type to bool
toFloat Converts any type (except array) to float
Value MUST NOT be array
toInt Converts any type (except array) to int
Value MUST NOT be array
toString Converts any type (except array) to string
Value MUST NOT be array

