mahdyaslami / simple-validation
Simple validation with composite pattern.
v0.5.1
2021-05-01 16:25 UTC
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-05-01 00:06:39 UTC
README
This package provide validation array, object and etc.
I have use compsite pattern to writing this package.
Usage without helpers
<?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.
Usage with helpers
<?php $validator = objectWith([ required('id', [integer(), lowerThan(5)]), sometimes('data', arrayOf([ integer() ])) ]);
How can create my own rule
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.
Validators
arrayOf, objectOf,
required, sometimes,
integer, numeric, lowerThan