Skip to content
Snippets Groups Projects

feature(processor): sensitive data processor

Merged Grzegorz Rola requested to merge feature/sensitive-data into master
5 files
+ 131
4
Compare changes
  • Side-by-side
  • Inline

Files

 
<?php
 
 
namespace WPDesk\Logger\Processor;
 
 
use Monolog\Processor\ProcessorInterface;
 
 
/**
 
* Can replace data in log.
 
* Ie. sensitive data.
 
*
 
* @package WPDesk\Logger\Processor
 
*/
 
class SensitiveDataProcessor implements ProcessorInterface {
 
 
/**
 
* Replace array.
 
*
 
* @var array
 
*/
 
private array $replace;
 
 
public function __construct( array $replace ) {
 
$this->replace = $replace;
 
}
 
 
public function __invoke( array $record ): array {
 
return $this->replace_array( $record );
 
}
 
 
private function replace_array( array $value ): array {
 
foreach ( $value as $key => $item ) {
 
if ( is_array( $item ) ) {
 
$value[ $key ] = $this->replace_array( $item );
 
}
 
if ( is_string( $item ) ) {
 
$value[ $key ] = $this->replace( $item );
 
}
 
}
 
 
return $value;
 
}
 
 
private function replace( string $value ): string {
 
foreach ( $this->replace as $search => $replace ) {
 
$value = str_replace( $search, $replace, $value );
 
}
 
 
return $value;
 
}
 
 
}
Loading