-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from bim-g/dev
Refactor validation API
- Loading branch information
Showing
24 changed files
with
365 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,42 +9,54 @@ | |
|
||
$schema = new Schema(); | ||
$validate = new Validate(); | ||
$source = [ | ||
"name" =>"wepesi", | ||
"email" => "[email protected]", | ||
"possessions" => [ | ||
"cars" => 2, | ||
"plane" => 0, | ||
"houses" => 4, | ||
"children" => -3, | ||
"children_name" => ['alfa', 3, false], | ||
"children_age" => [12,'6.2', 'rachel'], | ||
$data_source_pass = [ | ||
"family" => [ | ||
"children" => 3, | ||
"children_name" => ['alfa', 'beta', 'omega'], | ||
"children_age" => [12, 9, 3], | ||
"location" => [ | ||
"goma" => "Q.Virunga 08", | ||
"bukabu" => "Bagira 10", | ||
"kinshasa" => "matadi kibala 05" | ||
"bukabu" => "Bagira 10" | ||
] | ||
] | ||
]; | ||
$data_source_fail = [ | ||
"family" => [ | ||
"children" => 3, | ||
"children_name" => ['alfa', 3, 'blue'], | ||
"children_age" => [12, '6.2', 'rachel'], | ||
"location" => [ | ||
"goma" => "goma", | ||
"bukabu" => "Bagira", | ||
"kinshasa" => "Gombe ", | ||
"Lubumbashi" => "lushi" | ||
] | ||
] | ||
]; | ||
|
||
$rules =[ | ||
"name" => $schema->string()->min(1)->max(10)->required()->generate(), | ||
"email" => $schema->string()->email()->required()->generate(), | ||
"possessions" => $schema->array()->min(1)->max(20)->required()->structure([ | ||
"cars" => $schema->number()->min(1)->required()->generate(), | ||
"plane" => $schema->number()->min(1)->required()->generate(), | ||
"houses" => $schema->number()->min(6)->required()->generate(), | ||
"children" => $schema->number()->positive()->required()->generate(), | ||
'children_name' => $schema->array()->string()->generate(), | ||
'children_age' => $schema->array()->number()->generate(), | ||
"location" => $schema->array()->min(2)->structure([ | ||
"goma" => $schema->string()->min(20)->generate(), | ||
"bukabu" => $schema->string()->min(20)->generate(), | ||
"kinshasa" => $schema->string()->min(20)->generate(), | ||
])->generate() | ||
])->generate() | ||
$rules = [ | ||
"family" => $schema->array()->min(1)->max(20)->required()->structure([ | ||
"children" => $schema->number()->positive()->min(1)->max(5)->required(), | ||
'children_name' => $schema->array()->string(), | ||
'children_age' => $schema->array()->number(), | ||
"location" => $schema->array()->min(2)->max(3)->structure([ | ||
"goma" => $schema->string(), | ||
"bukabu" => $schema->string(), | ||
"kinshasa" => $schema->any(), | ||
"Lubumbashi" => $schema->any(), | ||
]) | ||
]) | ||
]; | ||
|
||
$validate->check($source, $rules); | ||
//// check if the validation passed or not | ||
include_once __DIR__ . '/vardump.php'; | ||
// check if the validation passed or not | ||
$validate->check($data_source_pass, $rules); | ||
var_dump([ | ||
'passed' => $validate->passed(), | ||
'errors' => $validate->errors() | ||
]); | ||
|
||
$validate->check($data_source_fail, $rules); | ||
var_dump([ | ||
'passed' => $validate->passed(), | ||
'errors' => $validate->errors() | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,44 @@ | |
|
||
$schema = new Schema(); | ||
$validate = new Validate(); | ||
$source = [ | ||
$source_to_pass = [ | ||
'name' => 'ibrahim', | ||
'country' => "", | ||
'country' => null, | ||
'password' => '1234567', | ||
'new_password' => 123456, | ||
'new_password' => 1234567, | ||
'email' => '[email protected]', | ||
'link' => 'https://github.com/bim-g/wepesi_validation/', | ||
'ip' => '127.0.0.1', | ||
]; | ||
$source_to_fail = [ | ||
'name' => 'ibrahim', | ||
'country' => "", | ||
'password' => '1234567', | ||
'new_password' => 123456, | ||
'email' => '[email protected]', | ||
'link' => 'google', | ||
'ip' => '192.168', | ||
]; | ||
$rules = [ | ||
"name" => $schema->string()->email()->min(35)->max(50)->required()->generate(), | ||
"country" => $schema->string()->min(30)->max(40)->required()->generate(), | ||
"password" => $schema->string()->min(3)->max(40)->generate(), | ||
"new_password" => $schema->string()->min(3)->max(40)->match("password")->generate(), | ||
"email" => $schema->string()->min(3)->max(40)->email()->generate(), | ||
"link" => $schema->string()->min(3)->max(40)->url()->generate(), | ||
"ip" => $schema->string()->addressIp()->generate() | ||
"name" => $schema->string()->min(3)->max(50)->required(), | ||
"country" => $schema->any(), | ||
"password" => $schema->string()->min(3)->max(40), | ||
"new_password" => $schema->string()->min(3)->max(40)->match("password"), | ||
"email" => $schema->string()->min(10)->max(40)->email(), | ||
"link" => $schema->string()->min(10)->max(45)->url(), | ||
"ip" => $schema->string()->addressIp() | ||
]; | ||
$validate->check($source, $rules); | ||
//// check if the validation passed or not | ||
include_once __DIR__."/vardump.php"; | ||
|
||
$validate->check($source_to_pass, $rules); | ||
// validation pass | ||
var_dump([ | ||
'passed' => $validate->passed(), | ||
'errors' => $validate->errors() | ||
]); | ||
|
||
// validation fail | ||
$validate->check($source_to_fail, $rules); | ||
var_dump([ | ||
'passed' => $validate->passed(), | ||
'errors' => $validate->errors() | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.