清理/确保

数据校正和验证

3.0.0 2016-08-09 23:54 UTC

This package is auto-updated.

Last update: 2024-09-07 00:47:50 UTC


README

Build Status Code Climate Test Coverage Issue Count Latest Stable Version Total Downloads License

此包扩展全局命名空间,包含一个名为 ensure 的方法,可用于校正和验证混合数据类型。

主要用于支持函数参数中原始类型的鸭子类型,以简化接口使用,例如。

class Foo
{
    public function filterById($id)
    {
        assure($name, ['arrayOfIntegers']);
        // after assure we can trust that name is an array of integers
        // otherwise exception will be raised
    }
}

$foo = new Foo();
$foo->filterById(1)
$foo->filterById('1')
$foo->filterById(['1', 2])

安装

通过 Composer

用法示例

// if value is not integer and cannot be transform to integer assure with throw exception
// correct values: '1', 1, 1.3
// invalid values: 'a', NULL, false, array()
assure($value, 'integer');

// if not integer OR string with integers separated by commas assure will throw exception
// correct values: '1', '1,2,3,4,5';
// invalid values: 'a', '1,2,a,4,b';
assure($value, ['integer', 'commaSeparatedIntegers']); 

文档

http://cleanassure.readthedocs.org