PHPackages                             acdphp/data-guard - 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. acdphp/data-guard

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

acdphp/data-guard
=================

Hides or masks array or collection elements on specific levels from a given specifications and conditions.

2.0.0(2y ago)141MITPHPPHP ^7.4 || ^8.0

Since Jul 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/acdphp/data-guard)[ Packagist](https://packagist.org/packages/acdphp/data-guard)[ RSS](/packages/acdphp-data-guard/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

Data Guard
==========

[](#data-guard)

[![Latest Stable Version](https://camo.githubusercontent.com/56755a40cb3242ff92478a9c5fc9c13bfcea3db1a21609705b955d4676d1f700/687474703a2f2f706f7365722e707567782e6f72672f6163647068702f646174612d67756172642f76)](https://packagist.org/packages/acdphp/data-guard)[![License](https://camo.githubusercontent.com/d4862f9f2580141c0119cb48af7ed8a48230ff9807a54681b5d79559f1462ef3/687474703a2f2f706f7365722e707567782e6f72672f6163647068702f646174612d67756172642f6c6963656e7365)](https://packagist.org/packages/acdphp/data-guard)

Hides or masks array or collection elements on specific levels from a given specifications and conditions.

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

[](#installation)

```
composer require acdphp/data-guard
```

Usage
-----

[](#usage)

```
# Hide
(new DataGuard())
    ->hide(array $data, string $resource, string $search, string $operator, mixed $value);

# Mask
(new DataGuard())
    ->mask(array $data, string $resource, string $search, string $operator, mixed $value);
```

Collection support
------------------

[](#collection-support)

- This can also be used directly with illuminate collection.

```
$protectedData = collect(['a' => 1, 'b' => 2])
    ->hide('a')
    ->mask('b');

print_r($protectedData->toArray());
# Result:
['b' => '###'];
```

---

Resource and Search Indicators
------------------------------

[](#resource-and-search-indicators)

- `|` - key split, keys to match on the same level.
- `:` - key separator, hierarchy of keys to match from root to child.
- `[]` - array indicator, DataGuard will look inside each of the values instead of directly looking for the next key.
- `###` - mask with, when calling `mask()`, data will be replaced with a string instead of removing it.

#### You may modify the indicators by passing it as a constructor argument.

[](#you-may-modify-the-indicators-by-passing-it-as-a-constructor-argument)

```
new DataGuard(':', '|', '[]', '###')
```

#### When used in a framework like laravel, you may publish the config to change the indicators.

[](#when-used-in-a-framework-like-laravel-you-may-publish-the-config-to-change-the-indicators)

```
php artisan vendor:publish --tag=dataguard-config
```

Data (array)
------------

[](#data-array)

- your data array (preferably an associative array)

Resource (string)
-----------------

[](#resource-string)

- string (example format: `'orders[]|order:line_items[]:sku'`)
- this is the key point of data to be processed.

Search (string, optional)
-------------------------

[](#search-string-optional)

- instead of matching the given resource directly, you can pass another resource (same formatting as resource) as the first index of condition to match against the operator+value. search\_resource will be searched through and matched, but the process point will still be on the given resource.
- if not provided, last node of resource will be matched.

Operator (string, optional)
---------------------------

[](#operator-string-optional)

```
1. =     : equals
2. !=    : not equals
3. in    : in array
4. !in   : not in array
5. >     : greater than
6. <     : less than
7. =    : greater than or equal
9. regex : Regular Expression; condition value must be a proper expression

```

- if not provided, `=` (equals) will be used

Value (mixed, optional)
-----------------------

[](#value-mixed-optional)

- matches the search or resource with the given operator.

---

Example
-------

[](#example)

```
use Cdinopol\DataGuard\DataGuard;

$data = [
    'hero' => [
        'name' => 'Thor',
        'profile' => [
            'address' => [
                'city' => 'Asgard',
                'country' => 'Asgard',
            ],
        ],

    ],
    'villain' => [
        'name' => 'Loki',
        'profile' => [
            'address' => [
                'city' => 'Asgard',
                'country' => 'Asgard',
            ],
        ],
    ],
    'others' => [
        [
            'name' => 'John',
            'profile' => [
                'address' => [
                    'city' => 'Asgard',
                    'country' => 'Asgard',
                ],
            ],
        ],
        [
            'name' => 'Doe',
            'profile' => [
                'address' => [
                    'city' => 'New York',
                    'country' => 'USA',
                ],
            ],
        ],
        [
            'name' => 'Carl',
            'profile' => [
                'address' => [
                    [
                        'city' => 'Chicago',
                        'country' => 'USA',
                    ],
                    [
                        'city' => 'Asgard',
                        'country' => 'Asgard',
                    ],
                ],
            ],
        ],
    ],
];

// Hides profile if city = Asgard
$protectedData = (new DataGuard())
    ->hide($data, 'heroes[]|hero|villain|others[]:profile', 'address|address[]:city', '=', 'Asgard');

print_r($protectedData);
# Result:
[
    'hero' => [
        'name' => 'Thor',
    ],
    'villain' => [
        'name' => 'Loki',
    ],
    'others' => [
        [
            'name' => 'John',
        ],
        [
            'name' => 'Doe',
            'profile' => [
                'address' => [
                    'city' => 'New York',
                    'country' => 'USA',
                ],
            ],
        ],
        [
            'name' => 'Carl',
        ],
    ],
];
```

Please check the [unit test](tests/DataGuardTest.php) for more usage examples.

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

948d ago

Major Versions

1.0.0 → 2.0.02023-10-12

PHP version history (2 changes)1.0.0PHP ^7.3 || ^8.0

2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/145334055?v=4)[Acdphp](/maintainers/acdphp)[@acdphp](https://github.com/acdphp)

---

Top Contributors

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

---

Tags

arraycollectionMaskinghiding

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/acdphp-data-guard/health.svg)

```
[![Health](https://phpackages.com/badges/acdphp-data-guard/health.svg)](https://phpackages.com/packages/acdphp-data-guard)
```

###  Alternatives

[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[yansongda/supports

common components

211.4M31](/packages/yansongda-supports)[armincms/json

A Laravel Nova field.

25149.4k3](/packages/armincms-json)[graze/sort

A collection of array sorting transforms and functions

12289.6k2](/packages/graze-sort)[graze/data-structure

Data collections and containers

12287.4k8](/packages/graze-data-structure)

PHPackages © 2026

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