php-shark-tank / anonymizer
Library to anonymize class properties
1.1.1
2026-10-30 10:20 UTC
Requires
- php: >=8.2 <8.6
Requires (Dev)
- fakerphp/faker: ^1.24
- friendsofphp/php-cs-fixer: ^3.95
- jangregor/phpstan-prophecy: ^2.3
- kubawerlos/php-cs-fixer-custom-fixers: ^3.37
- phpspec/prophecy-phpunit: ^2.5
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^11.5 || ^12.5 || ^13.4
- psr/cache: ^3.0
- psr/event-dispatcher: ^1.0
- symfony/expression-language: ^6.4 || ^7.4 || ^8.1
- symfony/yaml: ^6.4 || ^7.4 || ^8.1
Suggests
- fakerphp/faker: Needed to use FakerHandler(Registry)
- psr/cache: Needed to use CachingLoader
- psr/event-dispatcher: Needed to use EventDispatcher in the default GraphNavigator
- symfony/expression-language: Needed to use ExpressionExclusionStrategy
- symfony/yaml: Needed to use YamlFileLoader
Provides
None
Conflicts
None
Replaces
None
README
The Anonymizer is a library for PHP applications to make it easy to modify data of any object using PHP Attributes or other structured configurations.
Installation
With composer run
composer require php-shark-tank/anonymizer:^1.0
Documentation
- Basics
- Loader
- Registry / Handler
- Events
- ExclusionStrategies
Quick Example
<?php declare(strict_types=1); namespace App; require_once __DIR__.'/../vendor/autoload.php'; use PHPSharkTank\Anonymizer\Anonymizer; use PHPSharkTank\Anonymizer\Handler\CallbackHandler; use PHPSharkTank\Anonymizer\Handler\NullHandler; use PHPSharkTank\Anonymizer\Loader\AttributeLoader; use PHPSharkTank\Anonymizer\Registry\HandlerRegistry; use PHPSharkTank\Anonymizer\Visitor\GraphNavigator; use PHPSharkTank\Anonymizer\Attribute\EnableAnonymize; use PHPSharkTank\Anonymizer\Attribute\Handler; #[EnableAnonymize] class Person { #[Handler(value: 'callback', options: ['method' => 'getNameDefault'])] public string $name = ''; #[Handler(value: 'null')] public ?string $nullable = ''; public function getNameDefault(): string { return 'name'; } } $anonymizer = new Anonymizer(new GraphNavigator( new AttributeLoader(), new HandlerRegistry([ new CallbackHandler(), new NullHandler() ]), )); $person = new Person(); $anonymizer->process($person); var_dump($person);
Result:
/var/web/app ยป php index.php
/var/web/app/index.php.php:42:
class App\Person#10 (2) {
public string $name =>
string(4) "name"
public ?string $nullable =>
NULL
}