glebstar/sanitizer

用于JSON数据验证的Php7包

1.0.1 2020-11-04 14:17 UTC

This package is not auto-updated.

Last update: 2024-09-26 07:34:16 UTC


README

用于根据过滤器转换数据的包

安装

composer require glebstar/sanitizer

可用的过滤器

  • 字符串
  • 整数
  • 浮点数
  • 电话

示例

<?php

use Glebstar\Sanitizer\Sanitizer;

class Example
{
    public function testSanitize()
    {
        $sanitizer = new Sanitizer();
        $filters = [
            'foo' => 'integer',
            'bar' => 'string',
            'baz' => 'phone',
        ];
        $data = json_encode([
            'foo' => '123',
            'bar' => 'asd',
            'baz' => '8 (950) 288-56-23',
        ]);
    
        $result = $sanitizer->sanitize($filters, $data);
    }
}