1. Go to this page and download the library: Download leoboy/desensitization 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/ */
leoboy / desensitization example snippets
use Leoboy\Desensitization\Desensitizer;
// Instantiate a regular desensitizer
$localDesensitizer = new Desensitizer();
// Create or get a global singleton object
$globalDesensitizer = Desensitizer::global();
// Make the local object a global desensitizer object
$localDesensitizer->globalize();
class User implements Guard
{
public function getSecurityPolicy(): SecurityPolicyContract
{
return match (true) {
$this->isAdministrator() => new CustomHighLevelSecurityPolicy(),
default => new UnlimitedSecurityPolicy()
}
}
}
class CustomHighLevelSecurityPolicy implements SecurityPolicyContract
{
public function decide(AttributeContract $attribute): RuleContract|callable
{
return match ($attribute->getType()) {
'email' => 'replace:*',
'username' => new CustomRule(),
'password' => function ($username) {
return md5($username . mt_rand(100, 999));
},
default => Mask::create()->use('*')->repeat(3)->padding(2)
};
}
}