mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 11:52:34 +02:00
10df3211f5
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
52 lines
835 B
Markdown
52 lines
835 B
Markdown
# Key
|
|
|
|
- `Key(mixed $key)`
|
|
- `Key(mixed $key, Validatable $rule)`
|
|
- `Key(mixed $key, Validatable $rule, bool $mandatory)`
|
|
|
|
Validates an array key.
|
|
|
|
```php
|
|
$dict = [
|
|
'foo' => 'bar'
|
|
];
|
|
|
|
v::key('foo')->validate($dict); // true
|
|
```
|
|
|
|
You can also validate the key value itself:
|
|
|
|
```php
|
|
v::key('foo', v::equals('bar'))->validate($dict); // true
|
|
```
|
|
|
|
Third parameter makes the key presence optional:
|
|
|
|
```php
|
|
v::key('lorem', v::stringType(), false)->validate($dict); // true
|
|
```
|
|
|
|
The name of this validator is automatically set to the key name.
|
|
|
|
## Categorization
|
|
|
|
- Arrays
|
|
- Nesting
|
|
- Structures
|
|
|
|
## Changelog
|
|
|
|
Version | Description
|
|
--------|-------------
|
|
0.3.9 | Created
|
|
|
|
***
|
|
See also:
|
|
|
|
- [ArrayVal](ArrayVal.md)
|
|
- [Attribute](Attribute.md)
|
|
- [Each](Each.md)
|
|
- [KeyNested](KeyNested.md)
|
|
- [KeySet](KeySet.md)
|
|
- [KeyValue](KeyValue.md)
|