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

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

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

bileji/validator

Composer 安装命令:

composer require bileji/validator

包简介

deep level data validator

README 文档

README

The suggested installation method is via composer:

php composer.phar require "bileji/validator:~1.0.0"

Usage

Example

$validator = new \Bileji\Validator\Validator();

$validator->execute([
    "fruit" => "apple",
    "attribute" => [
        [
            "price" => 5,
            "time" => "2016-03-14 12:00:00"
        ],
        [
            "price" => 4,
            "time" => "2016-03-15 12:00:00"
        ]
    ],
    "email" => "shuc324@gmail.com",
    "colors" => ["color1" => "red", "color2" => "green"]
], [
    "fruit" => "required|string",
    "attribute._.price" => "required|numeric",
    "attribute._.time" => "required|string",
    "email" => "email",
    "colors" => "required|map"
]);

if ($validator->fails()) {
    $validator->errors()->first()->getMessage();
} else {
    var_dump($validator->getData());
}

array(4) {
  ["fruit"]=>
  string(5) "apple"
  ["attribute"]=>
  array(2) {
    [0]=>
    array(2) {
      ["price"]=>
      string(1) "5"
      ["time"]=>
      string(19) "2016-03-14 12:00:00"
    }
    [1]=>
    array(2) {
      ["price"]=>
      string(1) "4"
      ["time"]=>
      string(19) "2016-03-15 12:00:00"
    }
  }
  ["email"]=>
  string(17) "shuc324@gmail.com"
  ["colors"]=>
  array(2) {
    ["color1"]=>
    string(3) "red"
    ["color2"]=>
    string(5) "green"
  }
}

Validator

map

list

string

numeric

float

required

between:min,max

url

email

phone

chinese

regex

before:time

after:time

enum:enum

Custom error message

$validator->withMessage([
    'fruit|required' => ":field的名字不能为空"
])->execute([
    "fruit" => "apple",
    "attribute" => [
        [
            "price" => 5,
            "time" => "2016-03-14 12:00:00"
        ],
        [
            "price" => 4,
            "time" => "2016-03-15 12:00:00"
        ]
    ],
    "email" => "shuc324@gmail.com",
    "colors" => ["color1" => "red", "color2" => "green"]
], [
    "fruit" => "required|string",
    "attribute._.price" => "required|numeric",
    "attribute._.time" => "required|string",
    "email" => "email",
    "colors" => "required|map"
]);

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固