Symfony bundle to integrate the Anonymizer library into a Symfony application.
composer require php-shark-tank/anonymizer-bundleRegister the bundle in config/bundles.php (Symfony Flex does this automatically):
return [
// ...
PHPSharkTank\AnonymizerBundle\AnonymizerBundle::class => ['all' => true],
];Inject PHPSharkTank\Anonymizer\AnonymizerInterface (or the anonymizer service) and pass the objects to anonymize:
use PHPSharkTank\Anonymizer\AnonymizerInterface;
final class AnonymizeUserHandler
{
public function __construct(
private readonly AnonymizerInterface $anonymizer,
) {}
public function __invoke(User $user): void
{
$this->anonymizer->process($user);
}
}How to mark classes and properties for anonymization is described in the library documentation.
Services implementing PHPSharkTank\Anonymizer\Handler\HandlerInterface or PHPSharkTank\Anonymizer\Registry\HandlerRegistryInterface are registered automatically when autoconfiguration is enabled.
# config/packages/sharktank_anonymizer.yaml
sharktank_anonymizer:
# register the public "anonymizer" service alias
enable_alias: true
exclusion_strategy:
# skip objects/properties via #[Skip] expressions, requires symfony/expression-language
expression:
enabled: false
# cache the mapping metadata in the cache.<pool> service
cache:
enabled: false
pool: system
# enable the faker handlers, requires fakerphp/faker
faker:
enabled: false
# service id of a Faker\Generator
id: faker
# YAML mapping files, in addition to the PHP attributes
yaml_config: []