stantabcorp / validator
A PHP Validation library
Installs: 1 180
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- adbario/php-dot-notation: ^2.2
Requires (Dev)
- ext-json: *
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^6.0
README
A simple PHP validation library
Installation
composer require stantabcorp/validator
Using the library
$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
$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
composer run-script test