mahdyaslami / simple-validation
Simple validation with composite pattern.
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 3
pkg:composer/mahdyaslami/simple-validation
Requires (Dev)
- mockery/mockery: ^1.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-12-01 00:06:44 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