mahdyaslami/simple-validation

Simple validation with composite pattern.

Maintainers

Package info

github.com/mahdiaslami/simple-validation

pkg:composer/mahdyaslami/simple-validation

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

v0.5.1 2021-05-01 16:25 UTC

This package is auto-updated.

Last update: 2026-03-01 00:56:24 UTC


README

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