v1.0.1 2020-01-28 22:05 UTC

This package is auto-updated.

Last update: 2024-05-05 16:59:31 UTC


README

Latest Version on Packagist

It's a simple packge for validation the data before touch your database.

Core Features

  • PSR-4 for autoloading.
  • PSR-2 for coding style.
  • Strategy Pattern for changing the rules in the runtime.
  • Facade Pattern for make it esey to use.
  • Implements your own rule.
  • Test 100%.

Installation

composer require mohammedalkutrani/validator

Simple Usage

    use Validator\Facade\Validation;
    use Validator\Rules;

    $v = Validation::make(
        [
            // the given data.
            'name' => 'mohammedalkutrani@gmail.com',
            'age' => 25
        ], [
            // the rules for the data.
            'name' => [Rules::NUMBER, Rules::MIN.'|4'],
            'age' => [Rules::EMAIL]
        ]
    );

    // check if it passed
    if(!$v->isPassed()) // it will return boolean
    { 
        print_r($v->getMessages()); // getting the messages.
    }
    

The result

    Array
    (
        [name] => Array
            (
                [0] => the name should be a number
                [1] => the name should shorter then 4
            )

        [age] => Array
            (
                [0] => the age should be an email
            )

    )