PHP code example of adt / log-sanitizer

1. Go to this page and download the library: Download adt/log-sanitizer 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/ */

    

adt / log-sanitizer example snippets


$sanitizer = new SensitiveDataSanitizer();

// pole i vnořená struktura
$sanitizer->sanitize(['email' => '[email protected]', 'password' => 'Tajne123']);
// => ['email' => '[email protected]', 'password' => '***']

// surové tělo requestu: JSON dovnitř, JSON zpátky
$sanitizer->sanitizeJson($httpRequest->getRawBody());

// hlavičky: nositele přístupu vyhodí úplně
$sanitizer->sanitizeHeaders($headers);

$sanitizer->addSensitiveKeys('rodneCislo', 'iban');

// escape hatch, když porovnání podle slov nestačí
new SensitiveDataSanitizer(sensitivePatterns: ['/^x-internal-/i']);

$token = $this->tokenService->create(...);
$sanitizer->hideValue($token);
$this->sendJsonResponse(['token' => $token]);

$sanitizer->sanitize('platba kartou 4111 1111 1111 1111');
// => 'platba kartou ************1111'

['PAN'       => '4111111111111111']  =>  ['PAN'       => '************1111']
['MaskedPAN' => '************3035']  =>  ['MaskedPAN' => '************3035']

$sanitizer->onCardNumberDetected(function (string $scheme, int $length, string $path): void {
    $this->logger->warning("V payloadu byl nemaskovaný PAN ($scheme, $length cifer) v klíči $path.");
});

SensitiveDataSanitizer::detectCardScheme('4111111111111111');   // 'Visa'
SensitiveDataSanitizer::detectCardScheme('20260831054055');     // null