定制 t-kuni/php-normalizer 二次开发

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

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

t-kuni/php-normalizer

Composer 安装命令:

composer create-project t-kuni/php-normalizer

包简介

Boilerplate package for creating other packages.

README 文档

README

Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status

PHP Normalizer

In development...

Features

Single Normalize

$input   = '   hoge  fuga ';
$filters = ['trim', 'empty_to_null'];

$result = Normalizer::normalize($input, $filters);

// $result is...
// 'hoge  fuga'

Multiple Normalize

Flat Array

$n = new Normalizer([
    'name'   => ['trim', 'empty_to_null'],
    'age'    => ['trim', 'empty_to_null', 'integer'],
    'gender' => ['trim', 'empty_to_null', 'integer'],
]);

$result = $n->normalize([
    'name'   => '    hoge  fuga ',
    'age'    => ' 20 ',
]);

// $result is...
// [
//   'name'   => 'hoge  fuga',
//   'age'    => 20,
//   'gender' => null,
// ]

Nested Array

$n = new Normalizer([
    'users.*.name'   => ['trim', 'empty_to_null'],
    'users.*.age'    => ['trim', 'empty_to_null', 'integer'],
]);

$result = $n->normalize([
    'users' => [
        [
            'name'   => '    hoge  fuga ',
            'age'    => ' 20 ',
        ],
        [
            'name'   => '',
            'age'    => ' 20 ',
        ],
    ]
);

// $result is...
// [
//   'users' => [
//     [
//         'name'   => 'hoge  fuga',
//         'age'    => 20,
//     ],
//     [
//         'name'   => null,
//         'age'    => 20,
//     ],
//   ]
// ]

More details

Advanced Filtering

You can use Filter facade when you want to specify arguments.

Filter::replace('aaa', 'bbb')

Conditional Filtering

(TBD)

use ...\Condition as Cond;
Cond::is(0)->to(1);
Cond::is(null)->to(1);
Cond::isEmpty()->to(null);
Cond::toInt();
Cond::isNotNull()->toInt();
Cond::isEmpty()->to(new CustomFilter());
$n = new Normalizer([
    'name'   => ['trim', Cond::isEmpty()->toNull()],
    'age'    => ['trim', Cond::isEmpty()->toNull(), Cond::isNotEmpty()->toInt()],
    'gender' => ['trim', Cond::isEmpty()->toNull(), Cond::isNotEmpty()->toInt()],
]);

$result = $n->normalize([
    'name'   => '    hoge  fuga ',
    'age'    => ' 20 ',
]);

// $result is...
// [
//   'name'   => 'hoge  fuga',
//   'age'    => 20,
//   'gender' => null,
// ]

More details

Add Custom Filter

$customFilter = new class implements FilterContract
{
    public function apply($input)
    {
        return $input . '-suffix';
    }
}

Container::container()->get(FilterProviderContract::class)
    ->addFilter('custom_filter_name', $customFilter);

$n = new Normalizer([
    'users.*.name' => ['trim', 'custom_filter_name'],
]);

$result = $n->normalize([
    'users' => [
        [
            'name' => 'john',
        ],
        [
            'name' => 'eric',
        ],
    ]
]);

// $result is...
// [
//     'users' => [
//         [
//             'name' => 'john-suffix',
//         ],
//         [
//             'name' => 'eric-suffix',
//         ],
//     ]
// ]

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固