PHP code example of oihana / php-masking

1. Go to this page and download the library: Download oihana/php-masking 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/ */

    

oihana / php-masking example snippets




unction oihana\masking\maskDocument;

$document =
[
    '_key'  => '42',
    'name'  => 'Jane Doe',
    'email' => '[email protected]',
    'phone' => '+33 6 12 34 56 78',
    'profile' =>
    [
        'address' => '221B Baker Street',
        'zip'     => '75001',
    ],
];

$rules =
[
    [ 'path' => 'name'          , 'type' => 'xifyFront' , 'unmaskedLength' => 2 ],
    [ 'path' => 'email'         , 'type' => 'email' ],
    [ 'path' => 'phone'         , 'type' => 'phone' ],
    [ 'path' => 'profile.zip'   , 'type' => 'zip' ],
    [ 'path' => '.address'      , 'type' => 'randomString' ],
];

// The 3rd argument lists the attributes to keep, so `_key` survives.
// By default nothing is protected (the engine is data-store agnostic).
$masked = maskDocument( $document , $rules , [ '_key' ] );
// _key stays '42'; name -> "xxxx xxe", email -> "[email protected]", etc.

use function oihana\masking\maskValue;

maskValue( 'email' , '[email protected]' );                       // "[email protected]"
maskValue( 'xifyFront' , 'secret' , [ 'unmaskedLength' => 3 ] ); // "xxxret"
bash
composer