Giter Site home page Giter Site logo

ep-validate's Introduction

ep-validate

Another validate tool

说明

校验参数可能是遇到最多的问题,特别是在导入数据的时候。一个定义清晰的校验工具就不可获取了。

宏观的去考察一下,有个 json schema 的项目特别令人愉悦,但奈何类库代码颇多,有时候校验并不需要引入如此庞大的一套体系。

在纠结了几天后,决定还是简单来一个吧,自己用着比较舒服,遂放到这块。

安装

composer install xiangshouding/ep-validate

使用

$data = array(
    'name' => 'bozlll',
    'age' => 27,
    'gender' => 'm',
    'ext' => array(
        'school' => 'HIT',
        'class' => 4
    )
);

$rules = array(
    'name' => 'required|string|max:30',
    'age' => 'required|int',
    'gender' => 'required|enum:m,f',
    'ext' => '$ref:ext',
    '$define' => array(
        'ext' => array(
            'school' => 'string',
            'class' => 'string'
        )
    ),
);

$validate = new Ep_Validate($data, $rules);

if (!$validate->ok()) {
    throw new Exception($validate->getValidateError());
}

...

检验规则

...

ep-validate's People

Contributors

oxund avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.