PHPackages                             brunogab/inputhelper - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. brunogab/inputhelper

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

brunogab/inputhelper
====================

simple helper for sanitize and auto type-casting input data for php

v1.1(6y ago)013MITPHPPHP ^7.0

Since Mar 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/brunogab/inputhelper)[ Packagist](https://packagist.org/packages/brunogab/inputhelper)[ RSS](/packages/brunogab-inputhelper/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Simple Input Sanitizer with auto Type-Casting
=============================================

[](#simple-input-sanitizer-with-auto-type-casting)

Sanitizer, Filter, Custom Filter, Hepler, Type-Casting for Inputs

- Apply Filter on your Inputs-data.
- If no Filter was found/defined, automatic Type-Casting will be apply on Inputs-data.
- You can defined Keys, witch will returns from Inputs-data.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Inputs](#inputs)
- [Filters](#filters)
- [Keys](#keys)
- [Example](#example)
- [Custom Rule](#custom-rule)

Installation
------------

[](#installation)

Run `composer command`:

```
composer require brunogab/inputhelper

```

or add to your composer.json and run `composer update`:

```
{
	"require": {
		"brunogab/inputhelper": "^1.0"
	}
}
```

NOTICE:
-------

[](#notice)

> Some value cannot be decided between bool-type and integer/string type ("1", 1, 0, on, off..)
> Bool value check has a higher priority `by automatic type-casting:`
>
> - `1 is bool-true (not integer)`
> - `'1' is bool-true (not string)`
> - `'true' is bool-true (not string)`
> - `'on' is bool-true (not string)`
> - `'yes' is bool-true (not string)`

> - `0 is bool-false (not integer)`
> - `'0' is bool-false (not string)`
> - `'false' is bool-false (not string)`
> - `'off' is bool-false (not string)`
> - `'no' is bool-false (not string)`

> - `null is bool-false (not null)`
> - `'' is bool-false (not empty)`

Usage
-----

[](#usage)

```
use Brunogab\InputHelper\InputHelper;

$inputhelper = new InputHelper;
$result = $inputhelper->run($inputs, $filters, $keys);
```

Inputs
------

[](#inputs)

Inputs must be an Array:

```
$inputs = [
	'key_a' => 'Value_A',
	'key_b' => 'value_B',
	'key_c' => 'Value_c',
];
```

Filters
-------

[](#filters)

Filter can be Empty:

```
$filters = ''; //automatic type-casting will be applied for ALL input value
```

Filter can be String:

```
$filters = 'trim'; //trim will be applied for ALL input value
```

Filter can be String with Pipe:

```
$filters = 'trim|upper'; //trim and upper will be applied for ALL input value
```

Filter can be Sequential Array:

```
$filters = ['trim','upper']; //trim and upper will be applied for ALL input value
```

Filter can be Associative Array:

```
$filters = [
	'key_a' => 'trim',
	'key_b' => 'trim|upper',
	'key_c' => ['trim'],
	'key_d' => ['trim', 'upper'],
	'key_e' => ['trim', 'upper', function ($val) {
		return $val.' + closure';
	}],
	'key_f' => function ($val) {
		return $val.' + closure';
	}
];
```

> Notice:
> For Inputs where no Filter was found: `automatic type-casting` will be applied

Keys
----

[](#keys)

Keys can be Empty:

```
$keys = ''; //Result: (array) Inputs
```

Keys can be String:

```
$keys = 'key_a'; //key_a value will be returned, Result: inputs['key_a']
```

> Notice:
> If the requested key was not found, Result will be: NULL

Keys can be String with Pipe:

```
$keys = 'key_a|key_b'; //key_a and key_b value will be returned, Result: array (inputs['key_a'], inputs['key_b'])
```

> Notice:
> If none of the requested keys were found, Result will be: NULL

Keys can be Sequential Array:

```
$keys = [
	'key_a',
	'key_b',
	'key_invalid', //not valid key -> will be ignored
];
//Result: array (inputs['key_a'], inputs['key_b'])
```

> Notice:
> If none of the requested keys were found, result will be: NULL

Example
-------

[](#example)

> see in example.php

```
/** Automatic Type-Casting for Boolean Values */
$inputs = [
	'col_bool_1' => '1',
	'col_bool_1_1' => 1,
	'col_bool_true' => 'true',
	'col_bool_on' => 'on',
	'col_bool_yes' => 'yes',

	'col_bool_0' => '0',
	'col_bool_0_0' => 0,
	'col_bool_false' => 'false',
	'col_bool_off' => 'off',
	'col_bool_no' => 'no',

	'col_bool_null' => null,
	'col_bool_empty' => '',
];

/* Result:
array (size=12)
	'col_bool_1' => boolean true
	'col_bool_1_1' => boolean true
	'col_bool_true' => boolean true
	'col_bool_on' => boolean true
	'col_bool_yes' => boolean true

	'col_bool_0' => boolean false
	'col_bool_0_0' => boolean false
	'col_bool_false' => boolean false
	'col_bool_off' => boolean false
	'col_bool_no' => boolean false

	'col_bool_null' => boolean false
	'col_bool_empty' => boolean false
*/
```

Custom Rule
-----------

[](#custom-rule)

You can write your custom Code and save into src/Filters/`Yourcodename`Filter.php

```
namespace Brunogab\InputHelper\Filters;

class YourcodenameFilter
{
	public function do($val)
	{
		//custom logic
		return is_bool($val) ? 'Y' : 'N';
	}
}
//then simply use your custom filter
$filters = [
	'col_a' => 'yourcodename'
];
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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 ~3 days

Total

2

Last Release

2257d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e35172ec48b356554ce62f0a4280592fe9551da0cdec301d32efa5ced244a14?d=identicon)[brunogab](/maintainers/brunogab)

---

Top Contributors

[![brunogab](https://avatars.githubusercontent.com/u/55801234?v=4)](https://github.com/brunogab "brunogab (8 commits)")

---

Tags

inputsanitizesanitizertype-castingvalidatevalidatorsanitationinput filtercustom input filterauto type-casting

### Embed Badge

![Health badge](/badges/brunogab-inputhelper/health.svg)

```
[![Health](https://phpackages.com/badges/brunogab-inputhelper/health.svg)](https://phpackages.com/packages/brunogab-inputhelper)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[elegantweb/sanitizer

Sanitization library for PHP and the Laravel framework.

115950.4k2](/packages/elegantweb-sanitizer)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[waavi/sanitizer

Data sanitizer and Laravel 7 form requests with input sanitation.

433589.2k5](/packages/waavi-sanitizer)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)

PHPackages © 2026

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