PHP code example of php-shark-tank / anonymizer

1. Go to this page and download the library: Download php-shark-tank/anonymizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-shark-tank / anonymizer example snippets




declare(strict_types=1);

namespace App;

SharkTank\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);
bash
composer