-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Readme.md, change to custom validation to take only one parameter…
…, add error messages to php unit tests Signed-off-by: Thibault JUNIN <[email protected]>
- Loading branch information
1 parent
a65fa51
commit 4ae0d96
Showing
7 changed files
with
2,432 additions
and
2,174 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Validator | ||
|
||
A simple PHP validation library | ||
|
||
[![PHP Composer](https://github.com/stantabcorp/validator/actions/workflows/php.yml/badge.svg)](https://github.com/stantabcorp/validator/actions/workflows/php.yml) | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require stantabcorp/validator | ||
``` | ||
|
||
## Using the library | ||
|
||
```php | ||
$validator = new Stantabcorp\Validator\Validator(["array" => ["to" => "validate"]]); // Init the library providing an array to validate. | ||
$validator->required("array.to"); // Test if the key `to` in the array `array` is present. | ||
$validator->array("array"); // Test if the key `array` is an array. | ||
|
||
$validator->isValid(); // Return a boolean is the array is valid or not. | ||
|
||
$validator->getErrors(); // Return a list of string containing the error messages. | ||
``` | ||
|
||
### Custom validation | ||
|
||
```php | ||
$validator->customValidation("array", function (\Stantabcorp\Validator\CustomValidator $customValidator) { | ||
$customValidator->getKey(); // The key (`array` in this case) | ||
$customValidator->getValue(); // The associated value | ||
|
||
// Mark the kay as invalid and add an error message. | ||
$customValidator->addError("This is an error message"); | ||
}); | ||
``` | ||
|
||
## Testing | ||
|
||
```bash | ||
composer run-script test | ||
``` |
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.