class Validators

Validation utilities.

Constants

private BuiltinTypes

Properties

static protected $validators
static protected array<string,callable> $counters

Methods

static void
assert(mixed $value, string $expected, string $label = 'variable')

Verifies that the value is of expected types separated by pipe.

static void
assertField(array $array, $key, string|null $expected = null, string $label = "item '%' in array")

Verifies that element $key in array is of expected types separated by pipe.

static bool
is(mixed $value, string $expected)

Verifies that the value is of expected types separated by pipe.

static bool
everyIs(iterable $values, string $expected)

Finds whether all values are of expected types separated by pipe.

static bool
isNumber(mixed $value)

Checks if the value is an integer or a float.

static bool
isNumericInt(mixed $value)

Checks if the value is an integer or a integer written in a string.

static bool
isNumeric(mixed $value)

Checks if the value is a number or a number written in a string.

static bool
isCallable(mixed $value)

Checks if the value is a syntactically correct callback.

static bool
isUnicode(mixed $value)

Checks if the value is a valid UTF-8 string.

static bool
isNone(mixed $value)

Checks if the value is 0, '', false or null.

static bool
isMixed()

No description

static bool
isList(mixed $value) deprecated

Checks if a variable is a zero-based integer indexed array.

static bool
isInRange(mixed $value, array $range)

Checks if the value is in the given range [min, max], where the upper or lower limit can be omitted (null).

static bool
isEmail(string $value)

Checks if the value is a valid email address. It does not verify that the domain actually exists, only the syntax is verified.

static bool
isUrl(string $value)

Checks if the value is a valid URL address.

static bool
isUri(string $value)

Checks if the value is a valid URI address, that is, actually a string beginning with a syntactically valid schema.

static bool
isType(string $type) deprecated

Checks whether the input is a class, interface or trait.

static bool
isPhpIdentifier(string $value)

Checks whether the input is a valid PHP identifier.

static bool
isBuiltinType(string $type)

Determines if type is PHP built-in type. Otherwise, it is the class name.

static bool
isClassKeyword(string $name)

Determines if type is special class name self/parent/static.

static bool
isTypeDeclaration(string $type)

Checks whether the given type declaration is syntactically valid.

Details

at line 99
static void assert(mixed $value, string $expected, string $label = 'variable')

Verifies that the value is of expected types separated by pipe.

Parameters

mixed $value
string $expected
string $label

Return Value

void

Exceptions

AssertionException

at line 121
static void assertField(array $array, $key, string|null $expected = null, string $label = "item '%' in array")

Verifies that element $key in array is of expected types separated by pipe.

Parameters

array $array
$key
string|null $expected
string $label

Return Value

void

Exceptions

AssertionException

at line 140
static bool is(mixed $value, string $expected)

Verifies that the value is of expected types separated by pipe.

Parameters

mixed $value
string $expected

Return Value

bool

at line 202
static bool everyIs(iterable $values, string $expected)

Finds whether all values are of expected types separated by pipe.

Parameters

iterable $values
string $expected

Return Value

bool

at line 218
static bool isNumber(mixed $value)

Checks if the value is an integer or a float.

Parameters

mixed $value

Return Value

bool

at line 228
static bool isNumericInt(mixed $value)

Checks if the value is an integer or a integer written in a string.

Parameters

mixed $value

Return Value

bool

at line 238
static bool isNumeric(mixed $value)

Checks if the value is a number or a number written in a string.

Parameters

mixed $value

Return Value

bool

at line 247
static bool isCallable(mixed $value)

Checks if the value is a syntactically correct callback.

Parameters

mixed $value

Return Value

bool

at line 256
static bool isUnicode(mixed $value)

Checks if the value is a valid UTF-8 string.

Parameters

mixed $value

Return Value

bool

at line 266
static bool isNone(mixed $value)

Checks if the value is 0, '', false or null.

Parameters

mixed $value

Return Value

bool

at line 273
static bool isMixed()

internal  
 

No description

Return Value

bool

at line 284
static bool isList(mixed $value) deprecated

deprecated use Nette\Utils\Arrays::isList

Checks if a variable is a zero-based integer indexed array.

Parameters

mixed $value

Return Value

bool

at line 294
static bool isInRange(mixed $value, array $range)

Checks if the value is in the given range [min, max], where the upper or lower limit can be omitted (null).

Numbers, strings and DateTime objects can be compared.

Parameters

mixed $value
array $range

Return Value

bool

at line 320
static bool isEmail(string $value)

Checks if the value is a valid email address. It does not verify that the domain actually exists, only the syntax is verified.

Parameters

string $value

Return Value

bool

at line 338
static bool isUrl(string $value)

Checks if the value is a valid URL address.

Parameters

string $value

Return Value

bool

at line 361
static bool isUri(string $value)

Checks if the value is a valid URI address, that is, actually a string beginning with a syntactically valid schema.

Parameters

string $value

Return Value

bool

at line 371
static bool isType(string $type) deprecated

deprecated

Checks whether the input is a class, interface or trait.

Parameters

string $type

Return Value

bool

at line 380
static bool isPhpIdentifier(string $value)

Checks whether the input is a valid PHP identifier.

Parameters

string $value

Return Value

bool

at line 389
static bool isBuiltinType(string $type)

Determines if type is PHP built-in type. Otherwise, it is the class name.

Parameters

string $type

Return Value

bool

at line 398
static bool isClassKeyword(string $name)

Determines if type is special class name self/parent/static.

Parameters

string $name

Return Value

bool

at line 407
static bool isTypeDeclaration(string $type)

Checks whether the given type declaration is syntactically valid.

Parameters

string $type

Return Value

bool

Traits

Static class.