Search by

php-anonymizer / anonymizer

tliesche

A predictable, array-oriented PHP data anonymizer

Package info

github.com/toniliesche/php-anonymizer

pkg:composer/php-anonymizer/anonymizer

Statistics

Installs: 30 199

Dependents: 6

Suggesters: 0

Stars: 6

Open Issues: 4

2.0.2 2026-10-26 06:38 UTC

README

Pure PHP array anonymization with reusable profiles. The core supports nested map and list traversal, conditional rules, named replacement strategies, encoded documents, batches, and safe reports and audits. It requires PHP 8.5 and ext-mbstring.

Project Status

Tests Code Coverage Mutation testing badge Downloads Stars

Project Info

PHP Version Latest Version License

Repo Status

Last Commit Issues

License

This project is released under the MIT license.

See the LICENSE for more information.

Install

composer require php-anonymizer/anonymizer

Quick start

Profiles are registered with an immutable builder. The returned façade can be reused for independent inputs:

use PhpAnonymizer\Anonymizer\Application\Anonymization\AnonymizerBuilder;
use PhpAnonymizer\Anonymizer\Domain\Profile\ProfileDefinition;

$profile = ProfileDefinition::fromArray('customer', [
    'mode' => 'redact',
    'rules' => [['field' => 'email']],
]);
$anonymizer = AnonymizerBuilder::create()->withProfile($profile)->build();
$safe = $anonymizer->anonymize('customer', ['email' => 'ada@example.test']);

if ($safe !== ['email' => '[REDACTED]']) {
    throw new RuntimeException('The core quick-start example failed.');
}

In preserve mode, selected strings remain unchanged and other strings in the input tree are redacted. See the user guide for the complete walkthrough and the profile schema for rule syntax, matching behavior, and validation.

Core capabilities

  • anonymize() transforms associative arrays without changing their shape.
  • anonymizePayload() handles encoded maps; anonymizeDocument() also supports explicitly declared list roots.
  • anonymizeRecords() and anonymizeNdjson() process records lazily.
  • anonymizeWithReport() and anonymizeWithAudit() return paths or aggregate operational metadata without source or replacement values.
  • Strategies, codecs, transformations, and profile providers use the public, framework-free extension interfaces.

Packages

The PHP Anonymizer project is split into packages for core anonymization and optional integrations:

The builder does not scan for profiles or extensions. Register each profile, provider, or extension explicitly. For framework setup, install the Symfony Bundle or Laravel integration. Object anonymization is available through the optional Symfony Serializer adapter.

Read the extension author guide to implement custom ports. For changes from the previous API, see the 2.0 migration guide.