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

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

influx/sanitizer
================

JSON sanitizer

01PHP

Since Nov 12Pushed 5y ago1 watchersCompare

[ Source](https://github.com/InfluxOW/Sanitizer)[ Packagist](https://packagist.org/packages/influx/sanitizer)[ RSS](/packages/influx-sanitizer/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Sanitizer
=========

[](#sanitizer)

[![codecov](https://camo.githubusercontent.com/30a9c3c1b4dcd34de9355781c7398a45e4b4ac662a0fdb6e17215a964c8e6831/68747470733a2f2f636f6465636f762e696f2f67682f496e666c75784f572f73616e6974697a65722f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d65555865744242414c35)](https://codecov.io/gh/InfluxOW/sanitizer)[![Main workflow](https://github.com/InfluxOW/Sanitizer/workflows/Main%20workflow/badge.svg)](https://github.com/InfluxOW/Sanitizer/workflows/Main%20workflow/badge.svg)

Description
-----------

[](#description)

A simple app that allows you to sanitize input with some specified data types.

It gives you 6 default data types out of the box:

- String
- Integer
- Float
- One Type Elements Array
- Russian Federal Phone Number
- Structure

It also supports 2 default input types out of the box:

- Array
- Json

You can extend these lists by adding custom data types and parsers.

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

[](#installation)

`composer require influx/sanitizer`

Usage
-----

[](#usage)

> ##### 1. Instantiating sanitizer
>
> [](#1-instantiating-sanitizer)

`$sanitizer = new Sanitizer($customDataTypes = [CustomDataType::class], $customParsers = [CustomParser::class])`

*Notices*:

- **Custom data types must implement `Influx\Sanitizer\DataTypes\Contracts\Validatable` interface**
- If your data type could be prepared for validation it should implement `Influx\Sanitizer\DataTypes\Contracts\PreparesForValidation` interface
- If your data type could be prepared for transmission after it has been validated it should implement `Influx\Sanitizer\DataTypes\Contracts\PreparesForTransmission` interface
- **Custom parsers must implement `Influx\Sanitizer\Services\DataParsers\Contracts\Invokable` interface**

> ##### 2. Preparing rules
>
> [](#2-preparing-rules)

You can pass any data and options to the rules array.

*Notices*:

- Every rule requires `sanitizer_data_type` field where you should put type of data there should be
- Other fields passed to the rule will come to the exact data type in the `array $options` variable

**Example**

```
$rules = [
    'some_integer_field' => ['sanitizer_data_type' => 'integer'],
    'some_string_field' => ['sanitizer_data_type] => 'string'],
    'some_structure_field' => ['sanitizer_data_type' => 'structure', ['structure' = ['*' => ['key']]],
    'some_one_type_elements_array_field' => ['sanitizer_data_type => 'one_type_elements_array', 'elements_type' => 'integer'],
]

```

> ##### 3. Preparing data
>
> [](#3-preparing-data)

`$data = ['some_integer_field' => '123test']`

or

```
$data = '{
  "some_integer_field": "123test",
  "some_string_field": "123test",
  "some_float_field": "123456.45",
  "some_russian_federal_phone_number_field": "0500"
}'

```

> ##### 4. Sanitizing
>
> [](#4-sanitizing)

`$result = $sanitizer->sanitize($data, $dataFormat, $rules)`\\

**Notices:**

- You can also pass data as `$value` =&gt; `$rule` in the first argument without specifying field names.
- If you are passing an array as the first argument it won't be parsed and will be processed as is, otherwise it will be parsed using specified data format parser.

`$result`:

- If something 'globally' went wrong (e.g. invalid rules has been provided, data couldn't be parsed) it will consist of error within 'global\_errors' field.
- If any validation failed it will consist of array of errors within 'sanitation\_errors' field.
- If data passed sanitation it will consist of array of sanitized data withing 'sanitized\_data' field.

Data Types Information
----------------------

[](#data-types-information)

Different data types requires different information.
Every data type needs at least value to handle. It will come from the input.
But some data types requires options. They will come from the rule data.

- One Type Elements Array requires `elements_type` option

Which means you should interact with it like this:

```
$rules = [
    'some_one_type_elements_array_field' => ['data_type => 'one_type_elements_array', 'elements_type' => 'integer'],
]

```

- Structure requires 'structure' option

Which means you should interact with it like this:

```
$rules = [
    'some_structure_field' => ['data_type' => 'structure', ['structure' = ['*' => ['key']]],
]

```

Other data types needs nothing but the `sanitizer_data_type` field as was mentioned before.

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/601923?v=4)[Influx](/maintainers/Influx)[@influx](https://github.com/influx)

---

Top Contributors

[![InfluxOW](https://avatars.githubusercontent.com/u/57688681?v=4)](https://github.com/InfluxOW "InfluxOW (38 commits)")

### Embed Badge

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

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

PHPackages © 2026

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