This package provide validation array, object and etc.
I have use compsite pattern to writing this package.
<?php
$validator = new ObjectRule([
new RequiredRule('id', [new IntegerRule(), new LowerRule(5)]),
new SometimesRule('data', [new ArrayRule([
new IntegerRule()
])]);
]);
$validator->validate($value);
Call validate method throw ValidationException
on errors and do nothing on correct.
<?php
$validator = objectWith([
required('id', [integer(), lowerThan(5)]),
sometimes('data', arrayOf([
integer()
]))
]);
Extend a contract and implement validate
method.
if you extend CompositeValidator
or you should call validateChildren
method in validate
method too.
you can override validateChildren
too.
arrayOf, objectOf,
required, sometimes,
integer, numeric, lowerThan