respect-validation/docs/rules/Key.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

833 B

Key

  • Key(mixed $key)
  • Key(mixed $key, Validatable $rule)
  • Key(mixed $key, Validatable $rule, bool $mandatory)

Validates an array key.

$dict = [
    'foo' => 'bar'
];

v::key('foo')->validate($dict); // true

You can also validate the key value itself:

v::key('foo', v::equals('bar'))->validate($dict); // true

Third parameter makes the key presence optional:

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: