slick/validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slick/validator

Composer 安装命令:

composer require slick/validator

包简介

Slick/Validator is a simple library with useful input validators

README 文档

README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

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:

Alias Description Class
notEmpty Fails if passed value is an empty string Slick\Validator\NotEmpty
email Fails if passed value is not a valid e-mail address Slick\Validator\Email
number Fails if passed value is not am integer number Slick\Validator\Number
alphaNumeric Fails if passed value is not an alpha numeric value Slick\Validator\AlphaNumeric
url Fails if passed value is not an URL Slick\Validator\URL

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.

统计信息

  • 总下载量: 3.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固