PHP Classes

Wepesi Validation: Validate a set of values using rule classes

Recommend this page to a friend!
  Info   View files Example   View files View files (42)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 26 This week: 1All time: 11,100 This week: 560Up
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  
Name: Boss Ibrahim Mussa <contact>
Classes: 13 packages by
Country: Congo Congo
Age: ???
All time rank: 29051 in Congo Congo
Week rank: 109 Up1 in Congo Congo Equal
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  
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

  Files folder image Files  /  .idea  
File Role Description
  Accessible without login Plain text file deployment.xml Data Auxiliary data
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data
  Accessible without login Plain text file wepesi_validation.iml Data Auxiliary data

  Files folder image Files  /  example  
File Role Description
  Accessible without login Plain text file boolean.php Example Example script
  Accessible without login Plain text file date.php Example Example script
  Accessible without login Plain text file index.php Aux. Auxiliary script
  Accessible without login Plain text file number.php Example Example script
  Accessible without login Plain text file string.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageProviders (2 files, 1 directory)
Files folder imageResolver (2 files)
Files folder imageSchema (4 files)
Files folder imageTraits (2 files)
Files folder imageValidator (4 files)
  Plain text file Schema.php Class Class source
  Plain text file Validate.php Class Class source

  Files folder image Files  /  src  /  Providers  
File Role Description
Files folder imageContracts (3 files)
  Plain text file SChemaProvider.php Class Class source
  Plain text file ValidatorProvider.php Class Class source

  Files folder image Files  /  src  /  Providers  /  Contracts  
File Role Description
  Plain text file Contracts.php Class Class source
  Plain text file SchemaContracts.php Class Class source
  Plain text file ValidatorContracts.php Class Class source

  Files folder image Files  /  src  /  Resolver  
File Role Description
  Plain text file Option.php Class Class source
  Plain text file OptionsResolver.php Class Class source

  Files folder image Files  /  src  /  Schema  
File Role Description
  Plain text file BooleanSchema.php Class Class source
  Plain text file DateSchema.php Class Class source
  Plain text file NumberSchema.php Class Class source
  Plain text file StringSchema.php Class Class source

  Files folder image Files  /  src  /  Traits  
File Role Description
  Plain text file ExceptionTraits.php Class Class source
  Plain text file InitTrait.php Class Class source

  Files folder image Files  /  src  /  Validator  
File Role Description
  Plain text file BooleanValidator.php Class Class source
  Plain text file DateValidator.php Class Class source
  Plain text file NumberValidator.php Class Class source
  Plain text file StringValidator.php Class Class source

  Files folder image Files  /  test  
File Role Description
Files folder imageSchema (4 files)
Files folder imageScript (1 file)
  Plain text file SchemaTest.php Class Class source

  Files folder image Files  /  test  /  Schema  
File Role Description
  Plain text file BooleanSchemaTest.php Class Class source
  Plain text file DateSchemaTest.php Class Class source
  Plain text file NumberSchemaTest.php Class Class source
  Plain text file StringSchemaTest.php Class Class source

  Files folder image Files  /  test  /  Script  
File Role Description
  Plain text file StringValidationTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:1
All time:11,100
This week:560Up