PHPackages                             t-kuni/php-normalizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. t-kuni/php-normalizer

ActiveProject[Templating &amp; Views](/categories/templating)

t-kuni/php-normalizer
=====================

Boilerplate package for creating other packages.

v0.0.1(6y ago)0259[3 issues](https://github.com/t-kuni/php-normalizer/issues)MITPHPPHP &gt;=7.1

Since Aug 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/t-kuni/php-normalizer)[ Packagist](https://packagist.org/packages/t-kuni/php-normalizer)[ RSS](/packages/t-kuni-php-normalizer/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7baebb6c51180860a42875c8bd5cc615d6641ffd5c25ff52032220f1ebf5d70d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f742d6b756e692f7068702d6e6f726d616c697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/t-kuni/php-normalizer/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/062202d07cedc2ea5c927f7a5b0394dc80e1732e04192067eb7f7838c97a0714/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f742d6b756e692f7068702d6e6f726d616c697a65722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/t-kuni/php-normalizer/?branch=master)[![Build Status](https://camo.githubusercontent.com/4c143f418c39ded4f22e043616e11075f367fc7c2322dcad889b2aa1b5f24496/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f742d6b756e692f7068702d6e6f726d616c697a65722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/t-kuni/php-normalizer/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/a1bd0093dad60ac0eb5473aae17c086006b24d7ea369759bb59112c63a417541/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f742d6b756e692f7068702d6e6f726d616c697a65722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)

PHP Normalizer
==============

[](#php-normalizer)

In development...

Features
--------

[](#features)

### Single Normalize

[](#single-normalize)

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

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

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

### Multiple Normalize

[](#multiple-normalize)

#### Flat Array

[](#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

[](#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](docs/build_in_filters.md)

### Advanced Filtering

[](#advanced-filtering)

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

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

```

### Conditional Filtering

[](#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](docs/conditional_filters.md)

### Add Custom Filter

[](#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',
//         ],
//     ]
// ]
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2476d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7825234?v=4)[t-kuni](/maintainers/t-kuni)[@t-kuni](https://github.com/t-kuni)

---

Top Contributors

[![example123](https://avatars.githubusercontent.com/u/87628?v=4)](https://github.com/example123 "example123 (10 commits)")[![t-kuni](https://avatars.githubusercontent.com/u/7825234?v=4)](https://github.com/t-kuni "t-kuni (2 commits)")

---

Tags

composerpackagetemplate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/t-kuni-php-normalizer/health.svg)

```
[![Health](https://phpackages.com/badges/t-kuni-php-normalizer/health.svg)](https://phpackages.com/packages/t-kuni-php-normalizer)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
