Validators
in package
uses
StaticClass
Validation utilities.
Table of Contents
Constants
- BuiltinTypes = ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1, 'object' => 1, 'callable' => 1, 'iterable' => 1, 'void' => 1, 'null' => 1, 'mixed' => 1, 'false' => 1, 'never' => 1, 'true' => 1]
Properties
- $counters : array<string, callable>
- $validators : array<string, callable|null>
Methods
- __callStatic() : mixed
- Call to undefined static method.
- assert() : void
- Verifies that the value is of expected types separated by pipe.
- assertField() : void
- Verifies that element $key in array is of expected types separated by pipe.
- everyIs() : bool
- Finds whether all values are of expected types separated by pipe.
- is() : bool
- Verifies that the value is of expected types separated by pipe.
- isBuiltinType() : bool
- Determines if type is PHP built-in type. Otherwise, it is the class name.
- isCallable() : bool
- Checks if the value is a syntactically correct callback.
- isClassKeyword() : bool
- Determines if type is special class name self/parent/static.
- isEmail() : bool
- Checks if the value is a valid email address. It does not verify that the domain actually exists, only the syntax is verified.
- isInRange() : bool
- Checks if the value is in the given range [min, max], where the upper or lower limit can be omitted (null).
- isList() : ($value is list ? true : false)
- Checks if a variable is a zero-based integer indexed array.
- isNone() : ($value is 0|""|false|null ? true : false)
- Checks if the value is 0, '', false or null.
- isNumber() : ($value is int|float ? true : false)
- Checks if the value is an integer or a float.
- isNumeric() : ($value is non-empty-string ? bool : ($value is int|float ? true : false))
- Checks if the value is a number or a number written in a string.
- isNumericInt() : ($value is non-empty-string ? bool : ($value is int ? true : false))
- Checks if the value is an integer or a integer written in a string.
- isPhpIdentifier() : bool
- Checks whether the input is a valid PHP identifier.
- isType() : bool
- Checks whether the input is a class, interface or trait.
- isTypeDeclaration() : bool
- Checks whether the given type declaration is syntactically valid.
- isUnicode() : bool
- Checks if the value is a valid UTF-8 string.
- isUri() : bool
- Checks if the value is a valid URI address, that is, actually a string beginning with a syntactically valid schema.
- isUrl() : bool
- Checks if the value is a valid URL address.
- __construct() : mixed
- Class is static and cannot be instantiated.
Constants
BuiltinTypes
private
mixed
BuiltinTypes
= ['string' => 1, 'int' => 1, 'float' => 1, 'bool' => 1, 'array' => 1, 'object' => 1, 'callable' => 1, 'iterable' => 1, 'void' => 1, 'null' => 1, 'mixed' => 1, 'false' => 1, 'never' => 1, 'true' => 1]
Properties
$counters
protected
static array<string, callable>
$counters
= ['string' => 'strlen', 'unicode' => [\Nette\Utils\Strings::class, 'length'], 'array' => 'count', 'list' => 'count', 'alnum' => 'strlen', 'alpha' => 'strlen', 'digit' => 'strlen', 'lower' => 'strlen', 'space' => 'strlen', 'upper' => 'strlen', 'xdigit' => 'strlen']
$validators
protected
static array<string, callable|null>
$validators
= [
// PHP types
'array' => 'is_array',
'bool' => 'is_bool',
'boolean' => 'is_bool',
'float' => 'is_float',
'int' => 'is_int',
'integer' => 'is_int',
'null' => 'is_null',
'object' => 'is_object',
'resource' => 'is_resource',
'scalar' => 'is_scalar',
'string' => 'is_string',
// pseudo-types
'callable' => [self::class, 'isCallable'],
'iterable' => 'is_iterable',
'list' => [\Nette\Utils\Arrays::class, 'isList'],
'mixed' => [self::class, 'isMixed'],
'none' => [self::class, 'isNone'],
'number' => [self::class, 'isNumber'],
'numeric' => [self::class, 'isNumeric'],
'numericint' => [self::class, 'isNumericInt'],
// string patterns
'alnum' => 'ctype_alnum',
'alpha' => 'ctype_alpha',
'digit' => 'ctype_digit',
'lower' => 'ctype_lower',
'pattern' => null,
'space' => 'ctype_space',
'unicode' => [self::class, 'isUnicode'],
'upper' => 'ctype_upper',
'xdigit' => 'ctype_xdigit',
// syntax validation
'email' => [self::class, 'isEmail'],
'identifier' => [self::class, 'isPhpIdentifier'],
'uri' => [self::class, 'isUri'],
'url' => [self::class, 'isUrl'],
// environment validation
'class' => 'class_exists',
'interface' => 'interface_exists',
'directory' => 'is_dir',
'file' => 'is_file',
'type' => [self::class, 'isType'],
]
Methods
__callStatic()
Call to undefined static method.
public
static __callStatic(string $name, array<string|int, mixed> $args) : mixed
Parameters
- $name : string
- $args : array<string|int, mixed>
Tags
assert()
Verifies that the value is of expected types separated by pipe.
public
static assert(mixed $value, string $expected[, string $label = 'variable' ]) : void
Parameters
- $value : mixed
- $expected : string
- $label : string = 'variable'
Tags
assertField()
Verifies that element $key in array is of expected types separated by pipe.
public
static assertField(array<string|int, mixed> $array, mixed $key[, string|null $expected = null ][, string $label = "item '%' in array" ]) : void
Parameters
- $array : array<string|int, mixed>
- $key : mixed
- $expected : string|null = null
- $label : string = "item '%' in array"
Tags
everyIs()
Finds whether all values are of expected types separated by pipe.
public
static everyIs(array<string|int, mixed> $values, string $expected) : bool
Parameters
- $values : array<string|int, mixed>
- $expected : string
Return values
boolis()
Verifies that the value is of expected types separated by pipe.
public
static is(mixed $value, string $expected) : bool
Parameters
- $value : mixed
- $expected : string
Return values
boolisBuiltinType()
Determines if type is PHP built-in type. Otherwise, it is the class name.
public
static isBuiltinType(string $type) : bool
Parameters
- $type : string
Return values
boolisCallable()
Checks if the value is a syntactically correct callback.
public
static isCallable(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolisClassKeyword()
Determines if type is special class name self/parent/static.
public
static isClassKeyword(string $name) : bool
Parameters
- $name : string
Return values
boolisEmail()
Checks if the value is a valid email address. It does not verify that the domain actually exists, only the syntax is verified.
public
static isEmail(string $value) : bool
Parameters
- $value : string
Return values
boolisInRange()
Checks if the value is in the given range [min, max], where the upper or lower limit can be omitted (null).
public
static isInRange(mixed $value, array<string|int, mixed> $range) : bool
Numbers, strings and DateTime objects can be compared.
Parameters
- $value : mixed
- $range : array<string|int, mixed>
Return values
boolisList()
Checks if a variable is a zero-based integer indexed array.
public
static isList(mixed $value) : ($value is list ? true : false)
use Nette\Utils\Arrays::isList
Parameters
- $value : mixed
Return values
($value is list ? true : false)isNone()
Checks if the value is 0, '', false or null.
public
static isNone(mixed $value) : ($value is 0|""|false|null ? true : false)
Parameters
- $value : mixed
Return values
($value is 0|""|false|null ? true : false)isNumber()
Checks if the value is an integer or a float.
public
static isNumber(mixed $value) : ($value is int|float ? true : false)
Parameters
- $value : mixed
Return values
($value is int|float ? true : false)isNumeric()
Checks if the value is a number or a number written in a string.
public
static isNumeric(mixed $value) : ($value is non-empty-string ? bool : ($value is int|float ? true : false))
Parameters
- $value : mixed
Return values
($value is non-empty-string ? bool : ($value is int|float ? true : false))isNumericInt()
Checks if the value is an integer or a integer written in a string.
public
static isNumericInt(mixed $value) : ($value is non-empty-string ? bool : ($value is int ? true : false))
Parameters
- $value : mixed
Return values
($value is non-empty-string ? bool : ($value is int ? true : false))isPhpIdentifier()
Checks whether the input is a valid PHP identifier.
public
static isPhpIdentifier(string $value) : bool
Parameters
- $value : string
Return values
boolisType()
Checks whether the input is a class, interface or trait.
public
static isType(string $type) : bool
Parameters
- $type : string
Return values
boolisTypeDeclaration()
Checks whether the given type declaration is syntactically valid.
public
static isTypeDeclaration(string $type) : bool
Parameters
- $type : string
Return values
boolisUnicode()
Checks if the value is a valid UTF-8 string.
public
static isUnicode(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolisUri()
Checks if the value is a valid URI address, that is, actually a string beginning with a syntactically valid schema.
public
static isUri(string $value) : bool
Parameters
- $value : string
Return values
boolisUrl()
Checks if the value is a valid URL address.
public
static isUrl(string $value) : bool
Parameters
- $value : string
Return values
bool__construct()
Class is static and cannot be instantiated.
private
__construct() : mixed