Skip to content

mahdiaslami/simple-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Validation

This package provide validation array, object and etc.

I have use compsite pattern to writing this package.

UML Diagram

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

About

A simple validation library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages