mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 07:45:45 +01:00
605 B
605 B
Key
new Key(string $name)new Key(string $name, Validatable $rule)new Key(string $name, Validatable $rule, bool $mandatory)
Validates an array key.
$dict = [
'foo' => 'bar'
];
v::key('foo')->validate($dict); // true
You can also validate the key value itself:
v::key('foo', v::equals('bar'))->validate($dict); // true
Third parameter makes the key presence optional:
v::key('lorem', v::stringType(), false)->validate($dict); // true
The name of this validator is automatically set to the key name.
See also: