β Found this useful? Install from Packagist Β· Give it a star on GitHub so more developers can find it.
Symfony bundle for database anonymization, test data generation, and GDPR compliance. Anonymize database records using Doctrine attributes and Faker generators. Perfect for development environments, testing, data masking, and privacy compliance.
π Compatible with Symfony 6.1+, 7.x, and 8.x - This bundle requires Symfony 6.1 or higher (Symfony 6.0 is not supported).
- What is this?
- Quick Search Terms
- Features
- Installation
- Quick Start
- Requirements
- Configuration
- Commands
- Faker Types
- Documentation
- Testing
- License
- Contributing
- Roadmap
- Author
This bundle helps you anonymize sensitive data in your Symfony applications for:
- π§ͺ Test data generation - Create realistic anonymized test datasets
- π GDPR compliance - Anonymize personal data for development/testing
- π Data masking - Replace sensitive information with fake but realistic data
- π Development safety - Work with anonymized data instead of real user data
- π Database anonymization - Anonymize entire databases or specific entities
β οΈ Important: This bundle is development-only and should never be installed or used in production environments. The bundle includes built-in protection to prevent execution in production.
Looking for: database anonymization, test data generator, GDPR compliance, data masking, Symfony anonymize, Doctrine anonymization, Faker bundle, privacy tools, PII anonymization, data privacy, test fixtures, development tools? You've found the right bundle!
- β Attribute-based anonymization configuration
- β Support for multiple Doctrine connections
- β Multiple faker types (40 total: email, name, surname, age, phone, IBAN, credit card, address, date, username, url, company, masking, password, ip_address, mac_address, uuid, hash, coordinate, color, boolean, numeric, file, json, text, enum, country, language, hash_preserve, shuffle, constant, dni_cif, name_fallback, html, pattern_based, copy, null, utm, map, custom service)
- β FakerType enum for type-safe faker selection (recommended) - IDE autocompletion and compile-time validation
- β String-based faker types still supported (backward compatible)
- β Weight-based anonymization order
- β Pattern-based inclusion/exclusion filters
- β Support for MySQL and PostgreSQL (MongoDB infrastructure ready in demos, ODM support coming soon)
- β Batch processing for large datasets
- β Dry-run mode for testing
- β
Anonymization tracking with
AnonymizableTraitandanonymizedcolumn - β Pre-flight checks: Comprehensive validation before execution
- β Progress bars: Visual progress indicators with real-time updates
- β Enhanced environment protection: Multiple safety layers
- β Debug and verbose modes: Detailed output for debugging
- β Interactive mode: Step-by-step confirmations for safer anonymization
- β Enhanced reporting: Export statistics to JSON/CSV with success rates
- β Database export: Export databases to files with optional compression
- β Configurable output directories: Customize where statistics and exports are saved
- β Table truncation: Empty tables before anonymization with configurable execution order (for polymorphic entities, only rows of that discriminator are deleted)
- β
Custom entity anonymizer: Delegate anonymization to a service per entity via
anonymizeService(EntityAnonymizerServiceInterface) - β FrankenPHP β Compatible with FrankenPHP (including worker mode); demos run with FrankenPHP and Caddy (see demo/README.md)
β οΈ Important: This bundle is development-only. Always install it as a dev dependency.
composer require nowo-tech/anonymize-bundle --devThen, register the bundle in your config/bundles.php only for dev and test environments:
<?php
return [
// ...
Nowo\AnonymizeBundle\AnonymizeBundle::class => ['dev' => true, 'test' => true],
];
β οΈ Security: The bundle will automatically prevent execution in production environments. The command will fail if run outside ofdevortestenvironments.
- Mark an entity for anonymization with the
#[Anonymize]attribute:
use Nowo\AnonymizeBundle\Attribute\Anonymize;
use Nowo\AnonymizeBundle\Attribute\AnonymizeProperty;
#[ORM\Entity]
#[Anonymize]
class User
{
#[AnonymizeProperty(type: 'email', weight: 1)]
private ?string $email = null;
#[AnonymizeProperty(type: 'name', weight: 2)]
private ?string $firstName = null;
}- Run the anonymization command:
php bin/console nowo:anonymize:runYou can limit to specific connections (--connection) or entities (--entity, e.g. to test one entity or its anonymizeService). See COMMANDS.md for all options.
For detailed usage examples, see USAGE.md.
- PHP >= 8.1, < 8.6
- Symfony >= 6.1 || >= 7.0 || >= 8.0
- Doctrine ORM >= 2.13 || >= 3.0
- Doctrine Bundle >= 2.8 || >= 3.0 (3.0 required for Symfony 8)
Note: This bundle requires Symfony 6.1 or higher. Symfony 6.0 is not supported because the bundle uses the
#[Autowire]attribute for dependency injection, which is only available from Symfony 6.1 onwards.
The bundle works with default settings.
β οΈ Note: The configuration file is only automatically created when:
- Installing from Packagist with Symfony Flex
- AND the recipe is published in the Symfony recipes-contrib repository
Current Status: The recipe is not yet published, so you need to manually create the file (see below).
If the configuration file was not created automatically, create it manually at config/packages/dev/nowo_anonymize.yaml:
nowo_anonymize:
locale: 'en_US' # Locale for Faker generator
connections: [] # Specific connections to process (empty = all)
dry_run: false # Dry-run mode (default: false)
batch_size: 100 # Batch size for processing recordsSee CONFIGURATION.md for detailed configuration options.
The bundle provides six console commands:
nowo:anonymize:run- Main anonymization command (supports MySQL, PostgreSQL, SQLite; use--entityto process only specific entities)nowo:anonymize:history- View and manage anonymization history (list, view, compare runs)nowo:anonymize:export-db- Export databases to files with optional compression (MySQL, PostgreSQL, SQLite, MongoDB)nowo:anonymize:generate-column-migration- Generate SQL migrations foranonymizedcolumn (MySQL, PostgreSQL, SQLite)nowo:anonymize:generate-mongo-field- Generate MongoDB script to addanonymizedfield to documentsnowo:anonymize:info- Display information about anonymizers
Note: MongoDB ODM support is planned for future releases. The
nowo:anonymize:runcommand currently only processes Doctrine ORM connections. However, you can usenowo:anonymize:generate-mongo-fieldto prepare MongoDB documents with theanonymizedfield.
See COMMANDS.md for detailed command documentation and examples.
The bundle supports 40 faker types for anonymizing various data types, including:
- Basic: email, name, surname, age, phone, IBAN, credit_card
- Advanced: address, date, username, url, company, masking, password, ip_address, mac_address, uuid, hash, coordinate, color, boolean, numeric, file, json, text, enum, country, language
- Data Preservation: hash_preserve, shuffle, constant
- Specialized: dni_cif (Spanish DNI/CIF/NIF), name_fallback (handles nullable related name fields), html (HTML with lorem ipsum, perfect for email signatures)
- Custom: service (custom service faker)
See FAKERS.md for complete list and configuration options.
- Demo with FrankenPHP (development and production)
- Commands
- Faker Types
- Example: Polymorphism + anonymize service
- Testing commands
- Development
- Branching
The bundle includes a comprehensive testing script to verify all commands work correctly:
# Test all commands in all demos
./.scripts/test-commands.sh all
# Test in a specific demo
./.scripts/test-commands.sh symfony6The script tests 26 command combinations (entries in scripts/test-commands.sh). See TESTING_COMMANDS.md for details.
- Tests: PHPUnit (unit and integration; run
make testorcomposer test) - PHP (Lines): 94.14% (see
make test-coveragefor the PHPUnit summary and HTML report) - TS/JS: N/A
- Python: N/A
The MIT License (MIT). Please see LICENSE for more information.
We welcome contributions! Please see CONTRIBUTING.md for details on how to contribute to this project.
For information about our Git workflow and branching strategy, see BRANCHING.md.
We have an extensive roadmap for future enhancements. See ROADMAP.md for details on planned features including:
- Phase 1 Progress: 100% complete (built-in faker types implemented via
FakerTypeenum) - Total Fakers Available: 40 types in
FakerType(includingmap,utm,service, and data-preservation fakers) - Test Coverage: Large PHPUnit suite (1100+ test methods; exact count changes as tests are added). Run
composer testormake testfor the current total. ~94.1% line coverage onsrc/(PHPUnit Lines); target remains 100% β seemake test-coveragefor the report. - Some paths (e.g. parts of CLI commands and large services) may be exercised primarily via integration/command tests.
- Run
make test-coveragefor the full report. - Comprehensive tests for fakers, services, events, attributes, and helpers
- Pattern Matching: Enhanced with
|(OR) operator support for multiple value matching and relationship patterns (e.g.,'type.name' => '%HR') - MongoDB Support: Command to generate scripts for adding
anonymizedfield to MongoDB documents - Relationship Patterns: Support for patterns referencing related entities using dot notation with automatic SQL JOIN construction
- Recent Improvements: Enhanced test coverage, improved boolean/null handling in SQL queries, better error messages
- Phase 1 (v0.1.0): Enhanced fakers (100% complete - all fakers implemented)
- Phase 2 (v0.2.0): Advanced anonymization strategies (Hash Preserve, Shuffle, Relationship Preservation)
- Phase 3 (v0.3.0): MongoDB and SQLite support
- Phase 4 (v0.4.0): Enhanced developer experience (CLI improvements, reporting, testing tools)
- Phase 5 (v0.5.0): Enterprise features (GDPR compliance, audit logging, API integration)
- Phase 6 (v0.6.0): Performance and scalability improvements
- Phase 7 (v0.7.0): Security and compliance enhancements
- Phase 8 (v0.8.0): Advanced features (ML integration, workflow automation)
Check out the full roadmap for detailed information about upcoming features, priorities, and timelines.
Created by HΓ©ctor Franco Aceituno at Nowo.tech