2015-01-30 09:40:06 +01:00
|
|
|
# Key
|
|
|
|
|
2017-03-27 22:04:13 +02:00
|
|
|
- `Key(mixed $key)`
|
|
|
|
- `Key(mixed $key, Validatable $rule)`
|
|
|
|
- `Key(mixed $key, Validatable $rule, bool $mandatory)`
|
2015-01-30 09:40:06 +01:00
|
|
|
|
|
|
|
Validates an array key.
|
|
|
|
|
|
|
|
```php
|
2015-10-18 03:44:47 +02:00
|
|
|
$dict = [
|
2015-01-30 09:40:06 +01:00
|
|
|
'foo' => 'bar'
|
2015-10-18 03:44:47 +02:00
|
|
|
];
|
2015-01-30 09:40:06 +01:00
|
|
|
|
2015-10-20 02:53:25 +02:00
|
|
|
v::key('foo')->validate($dict); // true
|
2015-01-30 09:40:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
You can also validate the key value itself:
|
|
|
|
|
|
|
|
```php
|
2015-10-20 02:53:25 +02:00
|
|
|
v::key('foo', v::equals('bar'))->validate($dict); // true
|
2015-01-30 09:40:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
Third parameter makes the key presence optional:
|
|
|
|
|
|
|
|
```php
|
2015-10-07 16:52:03 +02:00
|
|
|
v::key('lorem', v::stringType(), false)->validate($dict); // true
|
2015-01-30 09:40:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
The name of this validator is automatically set to the key name.
|
|
|
|
|
2019-05-11 18:32:13 +02:00
|
|
|
## Categorization
|
|
|
|
|
|
|
|
- Arrays
|
|
|
|
- Nesting
|
|
|
|
- Structures
|
|
|
|
|
2017-03-27 22:04:13 +02:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
Version | Description
|
|
|
|
--------|-------------
|
|
|
|
0.3.9 | Created
|
|
|
|
|
2015-08-20 06:38:41 +02:00
|
|
|
***
|
2015-01-30 09:40:06 +01:00
|
|
|
See also:
|
|
|
|
|
2018-12-11 13:31:50 +01:00
|
|
|
- [ArrayVal](ArrayVal.md)
|
2017-03-28 11:53:14 +02:00
|
|
|
- [Attribute](Attribute.md)
|
2018-12-11 13:31:50 +01:00
|
|
|
- [Each](Each.md)
|
|
|
|
- [KeyNested](KeyNested.md)
|
|
|
|
- [KeySet](KeySet.md)
|
|
|
|
- [KeyValue](KeyValue.md)
|