flatphp/sanitization

轻量级清洗器

v1.1.0 2020-05-10 03:35 UTC

This package is auto-updated.

Last update: 2024-09-10 13:04:33 UTC


README

轻量级清洗器

安装

composer require flatphp/sanitization

用法

use \Flatphp\sanitization\sanitizer;

// sanitize one
$value = Sanitizer::sanitizeOne(' hello ', 'trim|upper');


// sanitize all
$data = [
    'v1' => '10.0',
    'v2' => ['a', 'b', 'c'],
    'v3' => ' hello '
];
$data = Sanitizer::sanitize($data, array(
    'v1' => 'int',
    'v2' => 'string:,|upper',
    'v3' => function($value){
        return strtoupper(trim($value));
    }
));


// just use single
$value = Sanitizer::toArray('1,2,3', ',');

加入定制自己的验证方法

  • 使用匿名函数,例如
  • 只需扩展清洗器类并添加自己的方法(继承)
  • 或者直接编写全局函数(写全局函数)

方法和规则