php-anonymizer / anonymizer
A predictable, array-oriented PHP data anonymizer
Requires
- php: ^8.5
- ext-mbstring: *
- thecodingmachine/safe: ^3.4
- webmozart/assert: ^2.5
Requires (Dev)
None
Suggests
- php-anonymizer/anonymizer-bundle: Add Symfony Bundle integration
- php-anonymizer/anonymizer-faker: Add Faker replacement strategies
- php-anonymizer/anonymizer-laravel: Add Laravel integration
- php-anonymizer/anonymizer-personas: Add fixed European persona strategies
- php-anonymizer/anonymizer-pseudonymization: Add keyed deterministic pseudonymisation
- php-anonymizer/anonymizer-symfony-serializer: Add object anonymization through Symfony Serializer
Provides
None
Conflicts
None
Replaces
None
- 2.x-dev
- 2.0.2
- 2.0.1
- 2.0.0
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.0
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/add-allowlist-processor
- dev-develop
- dev-release/0.5.x
- dev-release/0.4.x
- dev-main
- dev-feature/add-rule-provider-interface
- dev-feature_add-config-support-for-serializer-type
- dev-release/0.3.x
- dev-chore/add-anonymizer-interface
- dev-chore/increase-test-coverage-20251207
- dev-feature/add-license
- dev-feature/add-codecov
- dev-feature/add-symfony-bundle-configuration
- dev-feature/add-json-and-yaml-config-formats
- dev-release/0.2.x
- dev-release/0.1.x
- dev-feature/add-array-formatter
- dev-bugfix/fix-missing-interfaces
- dev-feature/add-more-data-encoders
- dev-bugfix/fix-github-actions
- dev-feature/add-github-actions
This package is auto-updated.
Last update: 2026-10-26 07:45:59 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
Project Info
Repo Status
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()andanonymizeNdjson()process records lazily.anonymizeWithReport()andanonymizeWithAudit()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:
php-anonymizer/anonymizer— framework-independent core library.php-anonymizer/anonymizer-bundle— Symfony Bundle integration.php-anonymizer/anonymizer-faker— Faker-powered replacement strategies.php-anonymizer/anonymizer-laravel— Laravel integration.php-anonymizer/anonymizer-personas— reusable persona data for anonymized fixtures.php-anonymizer/anonymizer-pseudonymization— pseudonymization strategies.php-anonymizer/anonymizer-symfony-serializer— optional Symfony Serializer object adapter.
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.