PHP Classes

Wepesi Validation: Validate a set of values using rule classes

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 26 All time: 11,235 This week: 660Up
Version License PHP version Categories
wepesi_validation 1.0The PHP License5PHP 5, Validation
Description 

Authors

Boss Ibrahim Mussa Gregoire
Masikilizano Emanuel Domeshow


Contributor

This package can validate a set of values using rule classes.

It can take an associative array with keys set to field names and values assigned to validation objects.

The validation objects can be defined using calls to validation class functions that implement different validation rules.

Currently, the package implements several types of validation rules:

- Non-empty value

- Minimum and a maximum number value

- Positive or negative number

- Email address

- Etc.

Picture of Boss Ibrahim Mussa
  Performance   Level  
Innovation award
Innovation award
Nominee: 5x

 

Example

<?php
/*
 * Copyright (c) 2022. Wepesi validation.
 * @author Boss Ibrahim Mussa
 */

$validate = new \Wepesi\App\Validate();
$schema = new \Wepesi\App\Schema();
$data_source = [
   
"age" => 20,
   
"length" => 0,
   
"height" =>"35",
   
"width" =>"",
   
"direction" => -7
];
$rules=[
   
"age" => $schema->number()->min(8)->max(15)->required()->generate(),
   
"length" => $schema->number()->min(1)->max(10)->required()->generate(),
   
"height" => $schema->number()->min(18)->max(50)->required()->generate(),
   
"width" => $schema->number()->min(3)->max(50)->required()->generate(),
   
"direction" => $schema->number()->min(3)->max(50)->positive()->required()->generate(),
    ];
$validate->check($data_source,$rules);

var_dump($validate->passed());
var_dump($validate->errors());


Details

wepesi_validation

this module will help to do your own input validation from http request POST or GET.

INTEGRATION

The integration is the simple thing to do. First you need to define the rule of the input data, and easy way to do so is by using a schema model which help hundle all of the process, then create an instance of Validate which will help validate data input according to rules already defined. While have the instance of validation, you can access check method, with take two parameters, the source and rules;

    $valid = new \Wepesi\App\Validate();
    $schema = new \Wepesi\App\Schema();
    $source = [];
    $rules = ["name" => $schema->string()->min(3)->max(5)->generate()];    
    $valid->check($source,$rules);
  • `source` 
    The `source` is array object of information to be checked.
    $source=[
        "name"=>"wepesi",
        "email"=>"infos@wepesi.cd",
        "link"=>"https://github.com/bim-g/wepesi_validation/",
        "age"=>1
        ];
    
  • `rules` The `rules` contains all the rule for each element of the source to be checked. you start with the name of the index key you want to check, the with the method you want to check. different method are now available according to you need.

    * `Validation Method` now you can validate your keys according to a specify type witch are: - string - number - date, - boolean - file

    // rules 
    $rules=[
        "email"=>$schema->string()->email()->min(9)->max(50)->required()->generate(),    
        "year"=>$schema->number()->email()->min(35)->max(60)->required()->generate()    
    ];

in the example bellow, for the first rule

    "email"=>$schema->string()->email()->min(9)->max(50)->required()->generate()
    
    // check `email` keys should be a:
    // - string: type of the value to be check should be a string
    // - email: that string should be a email
    // - min:9=> the email should have minimum caracters  9 caracter
    // - max:50=> the email should have maximum caracters should exid 50 caracters
    // - required=> it will no be empty

STRING method allow to validation:

- `required`: this to specify that the key will be required means `is not null`.
- `min`: this will check the minimum length of a string,
- `max`: this will check the maximum length of a string,
- `email`: this will check if the value is an email,
- `url`: this will check if the value is url or a link,
- `matches`: this is used tho check if two key has the same value, you should specify the second field to check.

In the example bellow, you can see a complete procured on how to validate data-source

    $source=[
        "name"=>"wepesi",
        "email"=>"infos@wepesi.cd",
        "link"=>"https://github.com/bim-g/wepesi_validation/",
        "age"=>1
        ];
$valid = new \Wepesi\App\Validate();
$schema = new \Wepesi\App\Schema();
    $rules=[
        "name"=>$schema->string()->required()->min(3)->max(30)->generate(),
        "email"=>$schema->string()->required()->min(3)->max(60)->email()->generate(),
        "link"=>$schema->string()->required()->min(3)->max(60)->url()->generate(),
        "age"=>$schema->number()->required()->positive()->generate()
    ];
    
    $valid->check($source,$rules);
    var_dump($valid->passed()); // if everything is correct return true
    var_dump($valid->errors()); // return all errors according to the validation type

  Files folder image Files (42)  
File Role Description
Files folder image.idea (5 files)
Files folder imageexample (5 files)
Files folder imagesrc (2 files, 5 directories)
Files folder imagetest (1 file, 2 directories)
Accessible without login Plain text file .phpunit-watcher.yml Data Auxiliary data
Accessible without login Plain text file .phpunit.result.cache Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:0
All time:11,235
This week:660Up