PHPackages                             gustavonecore/php-sanitizer - 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. gustavonecore/php-sanitizer

ActiveLibrary

gustavonecore/php-sanitizer
===========================

PHP data sanitizer

v1.0.1(2mo ago)5138↓100%[1 issues](https://github.com/gustavonecore/sanitizer/issues)[1 PRs](https://github.com/gustavonecore/sanitizer/pulls)MITPHPPHP &gt;=7.0CI failing

Since Aug 25Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/gustavonecore/sanitizer)[ Packagist](https://packagist.org/packages/gustavonecore/php-sanitizer)[ RSS](/packages/gustavonecore-php-sanitizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

GCore Sanitizer
===============

[](#gcore-sanitizer)

PHP sanitizer and validator
---------------------------

[](#php-sanitizer-and-validator)

This is a library to sanitize your input from any source, using a predefined template of native types.

**Why another sanitizer?**Well, this is because I really want to maintain my toolset pretty small, and not depending on big libraries/frameworks.

### Requirements

[](#requirements)

- PHP &gt;= v7.0

### Install it with composer

[](#install-it-with-composer)

```
composer require gustavonecore/php-sanitizer

```

### Example of usage

[](#example-of-usage)

**Template definition**First, you must define your template

```
    $filter = new Gcore\Sanitizer\Template\TemplateSanitizer([
    	'first_name' => 'string',
    	'dob' => 'int',
    	'numbers' => 'int[]',
    	'test' => 'int',
    	'email' => 'email',
    	'email_wrong' => 'email',
    	'double' => 'double',
    	'boolean' => 'bool',
    	'datetime' => 'datetime',
    	"persons[]" => [
    		'name' => 'string',
    		'eyes' => 'int',
    		'address' => 'string[]',
    		'commits[]' => [
    			'hash' => 'string',
    			'n_comments' => 'int',
    			'users' => 'string[]'
    		],
    	],
    ]);
```

**Required fields**You can force the sanitization process to require fields, you just need to include a `!` at the end of the rule, e.g:

```
    $filter = new Gcore\Sanitizer\Template\TemplateSanitizer([
    	'email' => 'email!',
    	'phone' => 'string!',
    	'first_name' => 'string',
    ]);
```

**If required fields is invalid**If the input have required fileds with invalid data (null) the library will throw a `Gcore\Sanitizer\Template\RequiredFieldsException`

**Sanitize!**After that, you are good to sanitize any input

```
    // This will be your inut body from an user
    $input = [
    	'first_name' => 'Gustavo',
    	'dob' => '10',
    	'numbers' => [1,2,3,'4','5'],
    	'foo' => [1,2,4],
    	'email' => 'gustavo.uach@gmail.com',
    	'email_wrong' => 'gustavo.uachgmail.com',
    	'double' => '7876',
    	'boolean' => true,
    	'datetime' => '2017-11-11 13:50:10',
    	'persons' => [
    		[
    			'name' => 'jhon',
    			'eyes' => 2,
    			'address' => ['foo', 'bar', 'text'],
    			'commits' => [
    				'hash' => '2221321n3kj12n3kj12n32j1',
    				'n_comments' => 900,
    				'users' => ['jhon', 'doe'],
    			],
    		],
    				[
    			'name' => 'albert',
    			'eyes' => 'wrong int here',
    			'address' => ['a', 'b', 1],
    			'commits' => null,
    		],
    	]
    ];

    // All your data is clean now! awesome!
    $cleanOutput = $filter->sanitize($input);

    print_r($cleanOutput);
```

**Clean Output**

Output of the previous call

```
    php examples/index.php
    Array
    (
        [first_name] => Gustavo
        [dob] => 10
        [numbers] => Array
            (
                [0] => 1
                [1] => 2
                [2] => 3
                [3] => 4
                [4] => 5
            )

        [test] =>
        [email] => gustavo.uach@gmail.com
        [email_wrong] =>
        [double] => 7876
        [boolean] => 1
        [datetime] => DateTimeImmutable Object
            (
                [date] => 2017-11-11 13:50:10.000000
                [timezone_type] => 3
                [timezone] => America/Santiago
            )

        [persons] => Array
            (
                [0] => Array
                    (
                        [name] => jhon
                        [eyes] => 2
                        [address] => Array
                            (
                                [0] => foo
                                [1] => bar
                                [2] => text
                            )

                        [commits] => Array
                            (
                                [hash] => 2221321n3kj12n3kj12n32j1
                                [n_comments] => 900
                                [users] => Array
                                    (
                                        [0] => jhon
                                        [1] => doe
                                    )

                            )

                    )

                [1] => Array
                    (
                        [name] => albert
                        [eyes] =>
                        [address] => Array
                            (
                                [0] => a
                                [1] => b
                                [2] => 1
                            )

                        [commits] =>
                    )

            )

    )
```

**Notes**

- Not defined keys in the template will be **ignored** by the sanitizer.
- If a value doesn't match the desired type, will be returned as **null**

**TODO**

- Add unit tests. #1 (In progress)
- Add required fields.
- Create a new template method to define **required** fields.
    - Improve this method to allow nested fields
- Modularize a bit more the Strategy selector to allow extending the library with new types of data.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance82

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~1285 days

Total

2

Last Release

69d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fe0fdd628cfd733a2934c9de54d79929880cfea849fe0df28b26b268ab13777?d=identicon)[gustavonecore](/maintainers/gustavonecore)

---

Top Contributors

[![gustavonecore](https://avatars.githubusercontent.com/u/6432827?v=4)](https://github.com/gustavonecore "gustavonecore (5 commits)")

---

Tags

libraryphpphp-sanitizersanitizer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gustavonecore-php-sanitizer/health.svg)

```
[![Health](https://phpackages.com/badges/gustavonecore-php-sanitizer/health.svg)](https://phpackages.com/packages/gustavonecore-php-sanitizer)
```

PHPackages © 2026

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