1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/movim_ynh.git synced 2024-09-03 19:46:19 +02:00
movim_ynh/sources/vendor/respect/validation/docs/Attribute.md
2016-03-14 23:16:11 +01:00

656 B

Attribute

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

Validates an object attribute.

$obj = new stdClass;
$obj->foo = 'bar';

v::attribute('foo')->validate($obj); // true

You can also validate the attribute itself:

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

Third parameter makes the attribute presence optional:

v::attribute('lorem', v::stringType(), false)->validate($obj); // true

The name of this validator is automatically set to the attribute name.


See also: