nowo-tech / anonymize-bundle
Symfony bundle for anonymizing database records using Doctrine attributes and Faker generators. Perfect for test data generation, GDPR compliance, and data masking in development environments.
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Type:symfony-bundle
pkg:composer/nowo-tech/anonymize-bundle
Requires
- php: >=8.1 <8.6
- doctrine/doctrine-bundle: ^2.8 || ^3.0
- doctrine/orm: ^2.13 || ^3.0
- fakerphp/faker: ^1.23
- symfony/config: ^6.0 || ^7.0 || ^8.0
- symfony/console: ^6.0 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.0 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.0 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.0 || ^7.0 || ^8.0
- symfony/yaml: ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
README
β Found this project useful? Give it a star on GitHub! It helps us maintain and improve the project.
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?
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.
Quick Search Terms
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!
Features
- β Attribute-based anonymization configuration
- β Support for multiple Doctrine connections
- β Multiple faker types (32 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, custom service)
- β 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
Installation
β οΈ Important: This bundle is development-only. Always install it as a dev dependency.
composer require nowo-tech/anonymize-bundle --dev
Then, 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 of
devortestenvironments.
Quick Start
- 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:run
For detailed usage examples, see USAGE.md.
Requirements
- 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.
Configuration
The bundle works with default settings. If you're using Symfony Flex, the configuration file is automatically created at config/packages/dev/nowo_anonymize.yaml. Otherwise, you can configure it manually in 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 records
See CONFIGURATION.md for detailed configuration options.
Commands
The bundle provides six console commands:
nowo:anonymize:run- Main anonymization command (supports MySQL, PostgreSQL, SQLite)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.
Faker Types
The bundle supports 32 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
- Custom: service (custom service faker)
See FAKERS.md for complete list and configuration options.
Documentation
- Usage Guide - Complete usage examples and patterns
- Commands - Detailed command documentation
- Faker Types - Complete list of all 32 faker types
- Configuration Guide - Detailed configuration options
- Installation Guide - Step-by-step installation instructions
- Upgrade Guide - Instructions for upgrading between versions
- Development Guide - Development setup, testing, and code quality
- Changelog - Complete version history and changes
- Roadmap - Planned features and future enhancements
- Branching Strategy - Git workflow and branching guidelines
- Contributing Guide - How to contribute to this project
License
The MIT License (MIT). Please see LICENSE for more information.
Contributing
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.
Roadmap
We have an extensive roadmap for future enhancements. See ROADMAP.md for details on planned features including:
Current Status (v0.0.18)
- Phase 1 Progress: 100% complete (all 21 fakers implemented)
- Total Fakers Available: 32 fakers (all fakers from Phase 1 + Phase 2 data preservation fakers)
- Test Coverage: 216 tests, 512 assertions, 45.80% line coverage
- 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
Planned Phases
- 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.
Author
Created by HΓ©ctor Franco Aceituno at Nowo.tech