Skip to content
Snippets Groups Projects
Select Git revision
  • 7b7c5c22e6ca9b56d2ef1c87d9c213f973c1f97c
  • master default protected
  • feat/message-handling
  • feat/request-id
  • 1.13.2
  • 1.13.1
  • 1.13.0
  • 1.12.1
  • 1.12.0
  • 1.11.0
  • 1.11.0-beta2
  • 1.11.0-beta1
  • 1.10.2
  • 1.10.1
  • 1.10.0
  • 1.9.0
  • 1.8.0
  • 1.7.4
  • 1.7.3
  • 1.7.2
  • 1.7.1
  • 1.7.0
  • 1.6.2
  • 1.6.2-beta2
24 results

SensitiveDataProcessor.php

Blame
  • SensitiveDataProcessor.php 981 B
    <?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;
    	}
    
    }