Skip to content

nowo-tech/AnonymizeBundle

Repository files navigation

Anonymize Bundle

CI Packagist Version Packagist Downloads License PHP Symfony GitHub stars Coverage

⭐ 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).

Table of contents

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 (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 AnonymizableTrait and anonymized column
  • βœ… 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)

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 dev or test environments.

Quick Start

  1. 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;
}
  1. Run the anonymization command:
php bin/console nowo:anonymize:run

You 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.

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.

⚠️ 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 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; use --entity to 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 for anonymized column (MySQL, PostgreSQL, SQLite)
  • nowo:anonymize:generate-mongo-field - Generate MongoDB script to add anonymized field to documents
  • nowo:anonymize:info - Display information about anonymizers

Note: MongoDB ODM support is planned for future releases. The nowo:anonymize:run command currently only processes Doctrine ORM connections. However, you can use nowo:anonymize:generate-mongo-field to prepare MongoDB documents with the anonymized field.

See COMMANDS.md for detailed command documentation and examples.

Faker Types

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.

Documentation

Additional documentation

Testing

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 symfony6

The script tests 26 command combinations (entries in scripts/test-commands.sh). See TESTING_COMMANDS.md for details.

Tests and coverage

  • Tests: PHPUnit (unit and integration; run make test or composer test)
  • PHP (Lines): 94.14% (see make test-coverage for the PHPUnit summary and HTML report)
  • TS/JS: N/A
  • Python: N/A

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 (1.0.17)

  • Phase 1 Progress: 100% complete (built-in faker types implemented via FakerType enum)
  • Total Fakers Available: 40 types in FakerType (including map, utm, service, and data-preservation fakers)
  • Test Coverage: Large PHPUnit suite (1100+ test methods; exact count changes as tests are added). Run composer test or make test for the current total. ~94.1% line coverage on src/ (PHPUnit Lines); target remains 100% β€” see make test-coverage for the report.
  • Some paths (e.g. parts of CLI commands and large services) may be exercised primarily via integration/command tests.
  • Run make test-coverage for 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 anonymized field 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

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

About

Symfony bundle for anonymizing database records using Doctrine attributes and Faker generators.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages