tapbuy/data-scrubber

A tool to help with scrubbing sensitive data

0.7.1 2025-02-03 16:37 UTC

This package is auto-updated.

Last update: 2025-07-15 16:57:30 UTC


README

PHP library for anonymizing sensitive data in objects and arrays.

Installation

composer require tapbuy/data-scrubber

Usage

use Tapbuy\DataScrubber\Anonymizer;

$anonymizer = new Anonymizer('https://your-api-url.com/keys');

$data = [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'phonenumber' => [
        'ssn' => '123-45-6789'
    ]
];

$anonymized = $anonymizer->anonymizeObject($data);

API

Anonymizer Class

class Anonymizer {
    public function __construct(string $url);
    public function updateKeys(): void;
    public function anonymizeObject(object|array $data): object|array;
}

Keys Class

class Keys {
    public function __construct(string $url);
    public function fetchKeys(): void;
    public function getKeys(): array;
}

Keys Format

Your API endpoint must return:

{
    "success": true,
    "data": ["name", "email", "ssn", "numbers[]"]
}

Keys with [] suffix indicate array fields that should have all elements anonymized.

Anonymization Rules

  • Strings: Replaced with * of same length

    "John Doe" → "********"
  • Numbers: Random number of same length/type

    1234598765
    123.45987.65
  • Arrays: If key marked with [], all elements anonymized

    'numbers' => [123, 456] → [789, 012]

CLI

Update keys via command line:

php bin/updateKeys.php https://your-api-url.com/keys

Directory Structure

data-scrubber/
├── src/
│   ├── Anonymizer.php
│   └── Keys.php
├── bin/
│   └── updateKeys.php
└── composer.json