2017 © Pedro PelĂĄez
 

project validation-engine

image

pbrus/validation-engine

  • Sunday, November 19, 2017
  • by PBrus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Validation-engine

Written in PHP License, (*1)

This is a simple validation engine written in PHP OOP for fun. If you need a robust PHP validator I recommend this one., (*2)

Installation

Install the package using Composer:, (*3)

$ composer require pbrus/validation-engine=dev-master

Then go to the validation-engine/ directory and make dump-autoload:, (*4)

$ cd vendor/pbrus/validation-engine/
$ composer dump-autoload

If don't know what Composer is, see the simplified PHP installation., (*5)

Usage

Define a validator and set its labels (here username and id):, (*6)

$validator = new ValidationEngine();

$validator->setLabels(array(
    'username',
    'id'
));

In the next step set constraints for each label:, (*7)

$validator->setConstraints('username', array(
    new NotEmptyValidator(array(
        'notEmptyMessage' => 'Field username must be filled out'
    )),
    new LengthValidator(array(
        'minLength' => 3,
        'maxLength' => 25,
        'lengthMessage' => "Field username must contain 3-25 letters"
    ))
));

$validator->setConstraints('id', array(
    new NotEmptyValidator(array(
        'notEmptyMessage' => "You must type your ID"
    )),
    new LengthValidator(array(
        'minLength' => 10,
        'maxLength' => 10,
        'lengthMessage' => "Field ID must consist of 10 integers"
    ))
));

Then we can validate data:, (*8)

if (!$validator->setFields(array(
    'username' => 'John',   // not validated: 'Jo'
    'id' => '9876543210'    // not validated: '123'
))
) {
    echo $validator->getErrorMessage();
}

If you encounter any problems, please see the demo file index.php., (*9)

Classes

The following examples of classes are defined:, (*10)

  • NotEmptyValidator
  • LengthValidator

Feel free to add own classes., (*11)

License

Validation-engine is licensed under the MIT license., (*12)

The Versions

19/11 2017

dev-master

9999999-dev https://github.com/pbrus/validation-engine

  Sources   Download

MIT

The Requires

  • php ^7.0