denis/validate 问题修复 & 功能扩展

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

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

denis/validate

Composer 安装命令:

composer require denis/validate

包简介

Data validation library for MobileXCo

README 文档

README

A sample data validation library. The goal was to create a data validation library as a composer module. This was a test requested by Mobile X Co.

Installing

This library can be installed with composer. To get composer:

curl -sS https://getcomposer.org/installer | php

Add this to your composer.json file.

{
    "require" : {
        "denis/validate": "dev-master"
    }
}

Then run composer install.

php composer.phar install

How to use

The schema is supplied in json format to the parse method. The isValid method is then called which returns a json response. The response will indicate if the data string is valid compared to the schema provided. If there are errors they will be in the response.

require_once 'vendor/autoload.php';

use MobileXCo\Validate;

$validate = new Validate();

$validate->parse($schema);

$result = $validate->isValid($data);

Data types supported

  • string (A string)
  • int (An integer)
  • email (Must be a string. Example "denis@gmail.com")
  • date (Must be a string. Example "2014-09-13")

Extra constraints

Elements can be marked as required by adding the required parameter. Type string and int can have a min and max length.

Testing

Testing with PHPUnit can be found under test folder.

Schema Example

{
    "id": {
        "type": "int",
        "required": true
    },
    "name": {
        "type": "string",
        "min": 5,
        "max": 30,
        "required": true
    },
    "description": {
        "type": "string",
        "max": 50
    },
    "price": {
        "type": "int",
        "min": 1
    },
    "orderOn": {
        "type": "date"
    },
    "address": {
        "type":"email"
    }
}

Data Examples

{
    "id": 25,
    "description": "Blue car."
}

isValid -> false, error: [name is required]

{
    "id": 21,
    "name": "Red car"
}

isValid -> true, error: []

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2014-11-28