maer / validator
A simple validation library
1.0.0
2018-06-08 12:13 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- phpunit/phpunit: ^6.5
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-12-16 14:13:21 UTC
README
Simple usage
$data = [ 'foo' => 'bar', 'lorem' => [ 'ipsum' => 'loremipsum', ] ]; $rules = [ 'foo' => ['required', 'in:bar,foo'], 'lorem.ipsum' => ['required', 'minLength:10'], ], $v = new \Maer\Validator\Validator($data, $rules); if ($v->isValid() === false) { print_r($v->getErrors()); }
Add custom rules
class MyRules extends \Maer\Validator\Sets\AbstractSet { public function myRule(mixed $input): string|bool { if ($input === 'hello-world') { return true; } return "Input must be hello-world"; } public function rules(): array { return [ 'myNewRule' => [$this, 'myRule'], ]; } } $data = [ 'foo' => 'hello-world', ]; $rules = [ 'foo' => ['myNewRule'], ]; $v = new Validator($data, $rules); // Add ruleset $v->addSet(new MyRules);