2015-10-05 21:20:04 +02:00
|
|
|
# KeyNested
|
|
|
|
|
2017-03-27 14:47:07 +02:00
|
|
|
- `KeyNested(string $name)`
|
|
|
|
- `KeyNested(string $name, Validatable $rule)`
|
|
|
|
- `KeyNested(string $name, Validatable $rule, bool $mandatory)`
|
2015-10-05 21:20:04 +02:00
|
|
|
|
|
|
|
Validates an array key or an object property using `.` to represent nested data.
|
|
|
|
|
|
|
|
Validating keys from arrays or `ArrayAccess` instances:
|
|
|
|
|
|
|
|
```php
|
2015-10-18 03:44:47 +02:00
|
|
|
$array = [
|
|
|
|
'foo' => [
|
2015-10-05 21:20:04 +02:00
|
|
|
'bar' => 123,
|
2015-10-18 03:44:47 +02:00
|
|
|
],
|
|
|
|
];
|
2015-10-05 21:20:04 +02:00
|
|
|
|
|
|
|
v::keyNested('foo.bar')->validate($array); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
Validating object properties:
|
|
|
|
|
|
|
|
```php
|
|
|
|
$object = new stdClass();
|
|
|
|
$object->foo = new stdClass();
|
|
|
|
$object->foo->bar = 42;
|
|
|
|
|
|
|
|
v::keyNested('foo.bar')->validate($object); // true
|
|
|
|
```
|
|
|
|
|
|
|
|
This rule was inspired by [Yii2 ArrayHelper][].
|
|
|
|
|
2019-05-11 18:32:13 +02:00
|
|
|
## Categorization
|
|
|
|
|
|
|
|
- Arrays
|
|
|
|
- Nesting
|
|
|
|
- Structures
|
|
|
|
|
2017-03-27 22:04:13 +02:00
|
|
|
## Changelog
|
|
|
|
|
|
|
|
Version | Description
|
|
|
|
--------|-------------
|
|
|
|
1.0.0 | Created
|
|
|
|
|
2015-10-05 21:20:04 +02:00
|
|
|
***
|
|
|
|
See also:
|
|
|
|
|
2017-03-28 11:53:14 +02:00
|
|
|
- [Attribute](Attribute.md)
|
|
|
|
- [Key](Key.md)
|
2018-12-11 13:31:50 +01:00
|
|
|
- [KeyValue](KeyValue.md)
|
2015-10-05 21:20:04 +02:00
|
|
|
|
|
|
|
[Yii2 ArrayHelper]: https://github.com/yiisoft/yii2/blob/68c30c1/framework/helpers/BaseArrayHelper.php "Yii2 ArrayHelper"
|