php-shark-tank / anonymizer
Library to anonymize class properties
1.1.0
2023-05-13 21:24 UTC
Requires
- php: ^8.2
Requires (Dev)
- fakerphp/faker: ^1.13
- friendsofphp/php-cs-fixer: ^3.14
- kubawerlos/php-cs-fixer-custom-fixers: ^3.13
- phpspec/prophecy-phpunit: ^2.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9
- psr/cache: ^1.0 || ^2.0 || ^3.0
- psr/event-dispatcher: ^1.0
- symfony/expression-language: ^4.4 || ^5.4 || ^6.2
- symfony/yaml: ^4.4 || ^5.4 || ^6.2
Suggests
- fakerphp/faker: Needed to use FakerHandler(Registry)
- psr-event-dispatcher: Needed to use EventDispatcher in the default GraphNavigator
- psr/cache: Needed to use CachingLoader
- symfony/expression-language: Needed to use ExpressionExclusionStrategy
- symfony/yaml: Needed to use YamlFileLoader
This package is auto-updated.
Last update: 2024-10-11 05:04:37 UTC
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
}