- Prerequisites
- Step 1: Install the Bundle
- Step 2: Register the Bundle
- Step 3: Configure the Bundle (Optional)
- Step 4: Mark Your Entities
- Step 5: Generate Migration for Anonymized Column (Optional)
- Step 6: Run the Command
- Verification
- Troubleshooting
- Anonymization Tracking
- Next Steps
- PHP >= 8.2, < 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: Symfony 6.1+ is required because the bundle uses
#[Autowire]attribute for dependency injection, which is only available from Symfony 6.1 onwards.
⚠️ Important: This bundle is development-only. Always install it as a dev dependency.
Install the bundle using Composer with the --dev flag:
composer require nowo-tech/anonymize-bundle --dev
⚠️ Security: Register the bundle only for dev and test environments. Never enable it in production.
If you're using Symfony Flex, the bundle is automatically registered for dev/test environments. Otherwise, manually register it in config/bundles.php:
<?php
return [
// ...
Nowo\AnonymizeBundle\AnonymizeBundle::class => ['dev' => true, 'test' => true],
];
⚠️ Security Note: The bundle includes built-in protection that prevents execution in production environments. The command will automatically fail if run outside ofdevortestenvironments, even if the bundle is registered.
⚠️ Important: The configuration file is only automatically created when:
- The bundle is installed from Packagist
- Symfony Flex is enabled and can access the official Symfony recipes repository
- The recipe is published in the Symfony recipes-contrib repository (https://github.com/symfony/recipes-contrib)
Current Status: The recipe is not yet published in the official repository, so the configuration file will not be created automatically. You need to manually create it (see below).
If you're installing the bundle from a local path, Git repository, or private repository, you also need to manually create the configuration file.
If you installed the bundle from Packagist using Symfony Flex, the configuration file should be automatically created at config/packages/dev/nowo_anonymize.yaml.
If the file was not created automatically, you can manually create it (see below).
Manually create the configuration file config/packages/dev/nowo_anonymize.yaml:
nowo_anonymize:
locale: 'en_US'
connections: []
dry_run: false
batch_size: 100See CONFIGURATION.md for detailed configuration options.
Add the #[Anonymize] attribute to entities you want to anonymize:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Nowo\AnonymizeBundle\Attribute\Anonymize;
use Nowo\AnonymizeBundle\Attribute\AnonymizeProperty;
use Nowo\AnonymizeBundle\Trait\AnonymizableTrait;
#[ORM\Entity]
#[Anonymize]
class User
{
use AnonymizableTrait; // Optional: Track anonymization status
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[AnonymizeProperty(type: 'email', weight: 1)]
private ?string $email = null;
#[ORM\Column(length: 255)]
#[AnonymizeProperty(type: 'name', weight: 2)]
private ?string $firstName = null;
}Note: The
AnonymizableTraitis optional but recommended if you want to track which records have been anonymized. See Anonymization Tracking below.
If you're using AnonymizableTrait, generate a migration to add the anonymized column:
php bin/console nowo:anonymize:generate-column-migrationThis will generate SQL statements to add the anonymized boolean column to your tables. Review and apply the generated SQL to your database(s).
Test the installation with a dry-run:
php bin/console nowo:anonymize:run --dry-runIf everything looks good, run the actual anonymization:
php bin/console nowo:anonymize:runTo verify the installation:
-
Check that the command is available:
php bin/console list nowo:anonymize
-
Run a dry-run to see what would be anonymized:
php bin/console nowo:anonymize:run --dry-run
-
Check your entities have the correct attributes:
php bin/console debug:container --parameter=nowo_anonymize.locale
If the command is not found, clear the cache:
php bin/console cache:clearMake sure your entities have the #[Anonymize] attribute and at least one property has the #[AnonymizeProperty] attribute.
Verify your Doctrine connections are properly configured in config/packages/doctrine.yaml.
The bundle provides an optional AnonymizableTrait that adds an anonymized boolean field to track which records have been anonymized.
-
Add the trait to your entity:
use Nowo\AnonymizeBundle\Trait\AnonymizableTrait; #[ORM\Entity] #[Anonymize] class User { use AnonymizableTrait; // ... your properties }
-
Generate the migration:
php bin/console nowo:anonymize:generate-column-migration
-
Apply the generated SQL to your database(s)
-
Run anonymization - records will be automatically marked:
php bin/console nowo:anonymize:run
- Query anonymized records:
SELECT * FROM users WHERE anonymized = true; - Check programmatically:
if ($user->isAnonymized()) { ... } - Audit trail: Know exactly which records have been anonymized
- Validation: Easy to verify anonymization status
- Read the README.md for usage examples
- Check CONFIGURATION.md for configuration options
- Review the demo project in the
demo/directory