mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Currently, the Property rule has a third parameter that allows the validation of the wrapped rule to be optional, meaning that the validation will only happen if the property exists. That parameter makes the rule harder to understand at times. I'm splitting the Property rule into Property, PropertyExists, and PropertyOptional. That way, it becomes apparent when someone wants only to validate whether a property exists or if they will validate the value of the property only when it exists. I deliberately didn't create an abstract class because those rules are different enough not to have an abstraction. In fact, I can see myself deleting the AbstractRelated after I refactor the KeyNested rule. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
1 KiB
1 KiB
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: