定制 ebidtech/validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ebidtech/validator

Composer 安装命令:

composer require ebidtech/validator

包简介

A validator on top of Symfony validator

README 文档

README

A validator on top of Symfony validator.

Latest Stable Version Build Status Coverage Status Scrutinizer Quality Score Dependency Status

Why to use?

Using Symfony validator with annotations or configuration (yml or xml) is just fine, but for simple cases, eg: validation of argument methods and throw exception is too verbose.

Eg:

Symfony way

use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints\Type;

class Test {
    public function getByName($name)
    {
        $violations = Validation::createValidator()->validateValue(
            $name,
            new Type(array('type' => 'string'))
        );

        if (count($violations) != 0) {
          throw new \InvalidArgumentException((string) $violations);
        }
    }
}

EBTValidator way

use EBT\Validator\ValidatorBasicExtended;

class Test {
    public function getByName($name)
    {
        if (!ValidatorBasicExtended::isTypeString($name)) {
            throw new \InvalidArgumentException(ValidatorBasicExtended::getViolationsAsShortString());
        }
    }
}

Requirements

  • PHP >= 5.3.3

Installation

The recommended way to install is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "ebidtech/validator": "@stable"
    }
}

Tip: browse ebidtech/validator page to choose a stable version to use, avoid the @stable meta constraint.

And run these two commands to install it:

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

Now you can add the autoloader, and you will have access to the library:

<?php

require 'vendor/autoload.php';

Usage

The validators are divided according to the Symfony Validator:

  • ValidatorBasic
  • ValidatorString
  • ValidatorNumber
  • ValidatorDate
  • ValidatorCollection

For each one exists a Extended version (Eg: ValidatorBasicExtended), that adds convenience alias methods. It exists also a ValidatorExtended that mix validations.

Example of code

Contributing

See CONTRIBUTING file.

Credits

License

Validator library is released under the MIT License. See the bundled LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固