slick / validator
Slick/Validator is a simple library with useful input validators
Installs: 3 176
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- slick/common: ^1.1
Requires (Dev)
- behat/behat: ~3.0.4
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
This package is auto-updated.
Last update: 2024-11-20 11:36:00 UTC
README
Slick/Validator
is a set of input validation tools that can be used to check your input data.
It also has the concept of Validation Chain that can combine validators for a specific validation.
This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.
Install
Via Composer
$ composer require slick/validator
Usage
One of the easiest ways of using a validator is using StaticValidator
class to check a value:
use Slick\Validator\StaticValidator; if (StaticValidator::validates('notEmpty', $value) { // Some code with valid value } else { print StaticValidator::getMessage(); // Print out validation messages }
Slick/Validator
comes with the following validators:
StaticValidator
is also a validator objects factory. For example:
use Slick\Validator\StaticValidator; $urlValidator = StaticValidator::create('notEmpty', 'You must enter a valid URL.'); if ($urlValidator->validates($_POST['url']) { // URL is valid use it... } else { print $urlValidator->getMessage(); // Will print out 'You must enter a valid URL.' }
Combining various validator to use it as a single validation can be done with
ValidationChain
.
use Slick\Validator\StaticValidator; use Slick\Validator\ValidationChain; $emailValidation = new ValidationChain(); $emailValidation ->add(StaticValidator::create('notEmpty', 'Email address cannot be empty.')) ->add(StaticValidator::create('email', 'The entered e-mail is not a valid address.'); if ($emailValidation->validates($_POST['email']) { // URL is valid use it... } else { print implode(', ', $emailValidation->getMessages()); // Will print out the validation messages for the validator(s) that fail. }
You can always create your own validator and use the StaticValidator
or the ValidationChain
as long
as you implement the Slick\Validator\ValidatorInterface
or Slick\Validator\ValidationChainInterface
.
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email silvam.filipe@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.