PHP code example of alkinbg / masked-bundle

1. Go to this page and download the library: Download alkinbg/masked-bundle 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/ */

    

alkinbg / masked-bundle example snippets




return [
    Masked\Bundle\MaskedBundle::class => ['all' => true],
];

use Masked\Bundle\SensitiveDataMasker;

final class PaymentService
{
    public function __construct(
        private readonly SensitiveDataMasker $masker,
    ) {
    }

    public function example(): string
    {
        return $this->masker->mask(
            'Card: 4111111111111111',
        );
    }
}

$token = 'secret-access-token';

$masked = $sensitiveDataMasker->mask(
    'Authentication failed for token ' . $token,
    sensitiveValues: [$token],
);

use Masked\Bundle\StructuredDataMasker;

$masked = $structuredDataMasker->mask([
    'customer' => [
        'card' => '4111111111111111',
    ],
]);

$token = 'secret-access-token';

$masked = $structuredDataMasker->mask(
    [
        'authentication' => [
            'token' => $token,
        ],
    ],
    sensitiveValues: [$token],
);

use Masked\Bundle\Logging\SensitiveLogger;
use Psr\Log\LoggerInterface;

final class AuthenticationService
{
    public function __construct(
        private readonly LoggerInterface $logger,
        private readonly SensitiveLogger $sensitiveLogger,
    ) {
    }

    public function reportFailure(
        string $token,
        string $username,
    ): void {
        $this->sensitiveLogger->log(
            $this->logger,
            'warning',
            'Authentication failed for token ' . $token,
            [
                'token' => $token,
                'user' => $username,
            ],
            sensitiveValues: [$token],
        );
    }
}

$logger->info(
    'Processing card 4111111111111111',
    [
        'backup_card' => '5555555555554444',
    ],
);
bash
composer analyse