respect-validation/docs/KeyNested.md
2015-10-17 22:56:32 -03:00

836 B

KeyNested

  • v::keyNested(string $name)
  • v::keyNested(string $name, v $validator)
  • v::keyNested(string $name, v $validator, boolean $mandatory = true)

Validates an array key or an object property using . to represent nested data.

Validating keys from arrays or ArrayAccess instances:

$array = [
    'foo' => [
        'bar' => 123,
    ],
];

v::keyNested('foo.bar')->validate($array); // true

Validating object properties:

$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.


See also: