Primitives¶
By default the error message will be Value is not of type {primitive}
. You can change it via:
Lists¶
This constraint validates the input is an array
and all values are consecutive (1).
- No index value specified, be it
int
s orstring
s.
You can also validate that each value in the list is of a given type. Here's how to validate a list os string
s:
Specified value¶
This constraint makes sure the the input value is the expected one.
If you call the constraint with any other value than 42
, the validation will fail. Of course you can specify any value of any type you wish.
Tip
This is especially useful to define discriminators when the input can be multiple shapes that are defined by a key.
use Innmind\Validation\Is;
$shapeA = Is::shape('discriminator', Is::value('a'))
->with('some-key', Is::string());
$shapeB = Is::shape('discriminator', Is::value('b'))
->with('other-key', Is::int());
$validate = $shapeA->or($shapeB);
If you can $validate
with one of the following values it will succeed:
Otherwise it will fail for any other array shape.