b-tokman/validation 问题修复 & 功能扩展

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

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

b-tokman/validation

Composer 安装命令:

composer require b-tokman/validation

包简介

Simple standalone PHP validation trait. That can be user in any object

README 文档

README

PHP VALIDATION TRAIT

Programming language Scrutinizer code quality Travis build

This is a simple PHP standalone trait, that can be used to validate properties in any object. The validation process based on the Symfony Validation Component

🚀 Installation

This library requeired PHP version 7.2 or highter. And composer - package manger for PHP.

  $ composer require b-tokman/validation 

💡 Usage

After the installation you'll be able to use the bTokman\validation\ValidationTrait trait in your app.

You cannot override a trait's property in the class where the trait is used. However, you can override a trait's property in a class that extends the class where the trait is used:

  • Start using trait in your base class
  • Declare validation rules in your extended class. List of availible Rules
  • On a new instance of your class just call method validate.
class BaseObject
{
    use bTokman\validation\ValidationTrait;
}

......

class ValidationObject extends BaseObject
{
    public $validationRules = [
        'password' => [NotBlank::class, [Length::class, ['min' => 8]]],
    ];

    public $password;
}

......

$object = new ValidationObject();
   
$result = $object->validate();

Or you can override a trait's property in a class constructor:

class ValidationObject
{
    use bTokman\validation\ValidationTrait;

    public function __construct()
    {
        $this->validationRules = [
            'password' => [NotBlank::class, [Length::class, ['min' => 8]]],
        ];
    }
    
    public $password;
}

$object = new ValidationObject();
   
$result = $object->validate();

The validation result is

  • array of errors [[fieldName] => [errorMessage1, errorMessag2, ...] .
  • null if the validation was passed.

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固