respect-validation/docs/rules/KeyNested.md
Henrique Moody 250fd93682
Rename "Attribute" rule to "Property"
Because now we have the concept of attributes in PHP, the rule with the
name "Attribute" makes no sense because it doesn't validate attributes
but properties.

In the future, it might be possible that Validation will have a rule
called "Attribute" to validate PHP attributes.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2024-01-28 15:07:42 +01:00

976 B

KeyNested

  • KeyNested(string $name)
  • KeyNested(string $name, Validatable $rule)
  • KeyNested(string $name, Validatable $rule, bool $mandatory)

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.

Categorization

  • Arrays
  • Nesting
  • Structures

Changelog

Version Description
1.0.0 Created

See also: