PHP code example of acdphp / data-guard

1. Go to this page and download the library: Download acdphp/data-guard 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/ */

    

acdphp / data-guard example snippets


# Hide
(new DataGuard())
    ->hide(array $data, string $resource, string $search, string $operator, mixed $value);

# Mask
(new DataGuard())
    ->mask(array $data, string $resource, string $search, string $operator, mixed $value);

$protectedData = collect(['a' => 1, 'b' => 2])
    ->hide('a')
    ->mask('b');

print_r($protectedData->toArray());
# Result:
['b' => '###'];

new DataGuard(':', '|', '[]', '###')

use Cdinopol\DataGuard\DataGuard;

$data = [
    'hero' => [
        'name' => 'Thor',
        'profile' => [
            'address' => [
                'city' => 'Asgard',
                'country' => 'Asgard',
            ],
        ],

    ],
    'villain' => [
        'name' => 'Loki',
        'profile' => [
            'address' => [
                'city' => 'Asgard',
                'country' => 'Asgard',
            ],
        ],
    ],
    'others' => [
        [
            'name' => 'John',
            'profile' => [
                'address' => [
                    'city' => 'Asgard',
                    'country' => 'Asgard',
                ],
            ],
        ],
        [
            'name' => 'Doe',
            'profile' => [
                'address' => [
                    'city' => 'New York',
                    'country' => 'USA',
                ],
            ],
        ],
        [
            'name' => 'Carl',
            'profile' => [
                'address' => [
                    [
                        'city' => 'Chicago',
                        'country' => 'USA',
                    ],
                    [
                        'city' => 'Asgard',
                        'country' => 'Asgard',
                    ],
                ],
            ],
        ],
    ],
];

// Hides profile if city = Asgard
$protectedData = (new DataGuard())
    ->hide($data, 'heroes[]|hero|villain|others[]:profile', 'address|address[]:city', '=', 'Asgard');

print_r($protectedData);
# Result:
[
    'hero' => [
        'name' => 'Thor',
    ],
    'villain' => [
        'name' => 'Loki',
    ],
    'others' => [
        [
            'name' => 'John',
        ],
        [
            'name' => 'Doe',
            'profile' => [
                'address' => [
                    'city' => 'New York',
                    'country' => 'USA',
                ],
            ],
        ],
        [
            'name' => 'Carl',
        ],
    ],
];
sh
php artisan vendor:publish --tag=dataguard-config