pbrus / validation-engine
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^7.0
This package is not auto-updated.
Last update: 2025-05-25 08:44:21 UTC
README
This is a simple validation engine written in PHP OOP for fun. If you need a robust PHP validator I recommend this one.
Installation
Install the package using Composer:
$ composer require pbrus/validation-engine=dev-master
Then go to the validation-engine/
directory and make dump-autoload
:
$ cd vendor/pbrus/validation-engine/
$ composer dump-autoload
If don't know what Composer is, see the simplified PHP installation.
Usage
Define a validator and set its labels (here username
and id
):
$validator = new ValidationEngine(); $validator->setLabels(array( 'username', 'id' ));
In the next step set constraints for each label:
$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:
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
.
Classes
The following examples of classes are defined:
- NotEmptyValidator
- LengthValidator
Feel free to add own classes.
License
Validation-engine is licensed under the MIT license.