Recommend this page to a friend! |
this module will help to do your own input validation from http request POST
or GET
.
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
Classes of Boss Ibrahim Mussa | > | Wepesi Validation | > | Download .zip .tar.gz | > | Support forum | > | Blog | > | Latest changes |
|
Groups | Applications | Files |
Groups |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Validation | Validation algorithms | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
.idea (5 files) | ||||
example (5 files) | ||||
src (2 files, 5 directories) | ||||
test (1 file, 2 directories) | ||||
.phpunit-watcher.yml | Data | Auxiliary data | ||
.phpunit.result.cache | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
index.php | Aux. | Auxiliary script | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | .idea |
File | Role | Description |
---|---|---|
deployment.xml | Data | Auxiliary data |
modules.xml | Data | Auxiliary data |
php.xml | Data | Auxiliary data |
vcs.xml | Data | Auxiliary data |
wepesi_validation.iml | Data | Auxiliary data |
Files | / | example |
File | Role | Description |
---|---|---|
boolean.php | Example | Example script |
date.php | Example | Example script |
index.php | Aux. | Auxiliary script |
number.php | Example | Example script |
string.php | Example | Example script |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Providers (2 files, 1 directory) | ||||
Resolver (2 files) | ||||
Schema (4 files) | ||||
Traits (2 files) | ||||
Validator (4 files) | ||||
Schema.php | Class | Class source | ||
Validate.php | Class | Class source |
Files | / | src | / | Providers |
File | Role | Description | ||
---|---|---|---|---|
Contracts (3 files) | ||||
SChemaProvider.php | Class | Class source | ||
ValidatorProvider.php | Class | Class source |
Files | / | src | / | Providers | / | Contracts |
File | Role | Description |
---|---|---|
Contracts.php | Class | Class source |
SchemaContracts.php | Class | Class source |
ValidatorContracts.php | Class | Class source |
Files | / | src | / | Resolver |
File | Role | Description |
---|---|---|
Option.php | Class | Class source |
OptionsResolver.php | Class | Class source |
Files | / | src | / | Schema |
File | Role | Description |
---|---|---|
BooleanSchema.php | Class | Class source |
DateSchema.php | Class | Class source |
NumberSchema.php | Class | Class source |
StringSchema.php | Class | Class source |
Files | / | src | / | Traits |
File | Role | Description |
---|---|---|
ExceptionTraits.php | Class | Class source |
InitTrait.php | Class | Class source |
Files | / | src | / | Validator |
File | Role | Description |
---|---|---|
BooleanValidator.php | Class | Class source |
DateValidator.php | Class | Class source |
NumberValidator.php | Class | Class source |
StringValidator.php | Class | Class source |
Files | / | test |
File | Role | Description | ||
---|---|---|---|---|
Schema (4 files) | ||||
Script (1 file) | ||||
SchemaTest.php | Class | Class source |
Files | / | test | / | Schema |
File | Role | Description |
---|---|---|
BooleanSchemaTest.php | Class | Class source |
DateSchemaTest.php | Class | Class source |
NumberSchemaTest.php | Class | Class source |
StringSchemaTest.php | Class | Class source |
Download all files: wepesi_validation.tar.gz wepesi_validation.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|
Files |
File | Role | Description | ||
---|---|---|---|---|
.idea (5 files) | ||||
example (5 files) | ||||
src (2 files, 5 directories) | ||||
test (1 file, 2 directories) | ||||
.phpunit-watcher.yml | Data | Auxiliary data | ||
.phpunit.result.cache | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
index.php | Aux. | Auxiliary script | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | .idea |
File | Role | Description |
---|---|---|
deployment.xml | Data | Auxiliary data |
modules.xml | Data | Auxiliary data |
php.xml | Data | Auxiliary data |
vcs.xml | Data | Auxiliary data |
wepesi_validation.iml | Data | Auxiliary data |
Files | / | example |
File | Role | Description |
---|---|---|
boolean.php | Example | Example script |
date.php | Example | Example script |
index.php | Aux. | Auxiliary script |
number.php | Example | Example script |
string.php | Example | Example script |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Providers (2 files, 1 directory) | ||||
Resolver (2 files) | ||||
Schema (4 files) | ||||
Traits (2 files) | ||||
Validator (4 files) | ||||
Schema.php | Class | Class source | ||
Validate.php | Class | Class source |
Files | / | src | / | Providers |
File | Role | Description | ||
---|---|---|---|---|
Contracts (3 files) | ||||
SChemaProvider.php | Class | Class source | ||
ValidatorProvider.php | Class | Class source |
Files | / | src | / | Providers | / | Contracts |
File | Role | Description |
---|---|---|
Contracts.php | Class | Class source |
SchemaContracts.php | Class | Class source |
ValidatorContracts.php | Class | Class source |
Files | / | src | / | Resolver |
File | Role | Description |
---|---|---|
Option.php | Class | Class source |
OptionsResolver.php | Class | Class source |
Files | / | src | / | Schema |
File | Role | Description |
---|---|---|
BooleanSchema.php | Class | Class source |
DateSchema.php | Class | Class source |
NumberSchema.php | Class | Class source |
StringSchema.php | Class | Class source |
Files | / | src | / | Traits |
File | Role | Description |
---|---|---|
ExceptionTraits.php | Class | Class source |
InitTrait.php | Class | Class source |
Files | / | src | / | Validator |
File | Role | Description |
---|---|---|
BooleanValidator.php | Class | Class source |
DateValidator.php | Class | Class source |
NumberValidator.php | Class | Class source |
StringValidator.php | Class | Class source |
Files | / | test |
File | Role | Description | ||
---|---|---|---|---|
Schema (4 files) | ||||
Script (1 file) | ||||
SchemaTest.php | Class | Class source |
Files | / | test | / | Schema |
File | Role | Description |
---|---|---|
BooleanSchemaTest.php | Class | Class source |
DateSchemaTest.php | Class | Class source |
NumberSchemaTest.php | Class | Class source |
StringSchemaTest.php | Class | Class source |
Download all files: wepesi_validation.tar.gz wepesi_validation.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|