PHPackages                             reliv/white-rat - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. reliv/white-rat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

reliv/white-rat
===============

A whitelisting library for PHP that supports deep arrays

0.2.0(7y ago)11.3k12ISCPHPPHP &gt;=7.1

Since May 1Pushed 7y ago6 watchersCompare

[ Source](https://github.com/reliv/white-rat)[ Packagist](https://packagist.org/packages/reliv/white-rat)[ Docs](https://github.com/reliv/white-rat)[ RSS](/packages/reliv-white-rat/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (2)

white-rat
=========

[](#white-rat)

A whitelisting library for PHP that supports deep arrays

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

[](#installation)

```
composer require reliv/white-rat
```

Use
---

[](#use)

To use as a stateless service:

```
use Reliv\WhiteRat\Filter;

$filter = new Filter();

$rules = /* White-list rules go here; see further explanation below */;

// Optional safety check; throws an exception if $rules is not valid
$filter->validate($rules);

$subject = [/* Data to be filtered */];

$filteredSubject = $filter($subject, $rules);
```

To pre-compile a reusable filter as an invokable whitelist:

```
use Reliv\WhiteRat\Whitelist;

$whitelist = new Whitelist([
    /* White-list rules go here; see further explanation below */
    /* The rules will be validated upon construction */
]);

$subject = [/* Data to be filtered */];

$filteredSubject = $whitelist($subject);
```

Whitelist Rules
---------------

[](#whitelist-rules)

Whitelist rule sets are designed to closely mirror the structure of the data they are applied to. A rule set takes the form of an array that is a mix of associative and indexed values, although the order of indexed values is irrelevant. When a value is indexed, it must be a string. When it is associative, it must be either an array or a boolean. Each string, whether it is a key or a value, correlates with a key in the data.

If a string appears as an indexed value, the correlating key in the data, including all fields below it, are whitelisted.

If a string appears as a key, and the value is a boolean, it indicates whether the associated data is whitelisted or not.

If a string appears as a key, and the value is an array, this indicates a more specific whitelist rule for sub-keys of the associated data. Whitelisting rules then proceed recursively.

It is also possible to whitelist indexed arrays. To do this, create an array within in array, where the sub-array is the only child of its parent and is an indexed child. This looks like a set of double brackets, and we refer to it as the "double-array."

Whitelist rules are validated upon construction of the whitelist. An exception of type Reliv\\WhiteRat\\WhitelistValidationException will be thrown if there are any problems detected in the rules given, and the path to the rule and an explanation of the error will be provided.

By default, no fields are whitelisted and all data will be filtered out, leaving you with an empty array. However, any fields present in the whitelist but absent in the data being filtered are ignored in the whitelist. This means its safe to whitelist optional data.

Examples
--------

[](#examples)

```
$whitelist = new Whitelist([
    'foo',
    'bar' => true,
    'bob' => false,
    'baz' => [
        'flip' => true,
        'flop' => [ ['flummox'] ],
        'quux',
    ]
]);

$data = [
    'foo' => 'FOO!',
    'bar' => 'BAR!',
    'bob' => 'BOB!',
    'baz' => [
        'flip' => 'FLIP!',
        'flop' => [
            ['flimsy' => 111, 'flummox' => 222],
            ['flummox' => 333, 'flopsy' => 444]
        ]
    ]
]

$result = $whitelist($data);

var_dump($result);
```

Output:

```
array(3) {
    ["foo"] => "FOO!"
    ["bar"] => "BAR!"
    ["baz"] => array(2) {
        ["flip"] => "FLIP!"
        ["flop"] => array(2) => {
            array(1) => {
                ["flummox"] => int(222)
            }
            array(1) => {
                ["flummox"] => int(333)
            }
        }
    }
}

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80.8% 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 ~32 days

Total

3

Last Release

2864d ago

PHP version history (2 changes)0.1.0PHP &gt;=7

0.2.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d89ed9b1fb36217e63fbabed855b75ccbca9a740b8662ed44aa982d5d7c98f7?d=identicon)[reliv](/maintainers/reliv)

---

Top Contributors

[![bradharms](https://avatars.githubusercontent.com/u/1239044?v=4)](https://github.com/bradharms "bradharms (21 commits)")[![rodmcnew](https://avatars.githubusercontent.com/u/1828506?v=4)](https://github.com/rodmcnew "rodmcnew (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/reliv-white-rat/health.svg)

```
[![Health](https://phpackages.com/badges/reliv-white-rat/health.svg)](https://phpackages.com/packages/reliv-white-rat)
```

###  Alternatives

[froiden/laravel-installer

Laravel web installer

10883.9k](/packages/froiden-laravel-installer)

PHPackages © 2026

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