log( $level, $line, array( 'source' => self::SOURCE ) ); } /** * Redacts personal data in a context array, recursively. * * @param array $context Context. * @return array */ public static function redact( array $context ) { foreach ( $context as $key => $value ) { if ( is_string( $key ) && in_array( strtolower( $key ), self::PII_KEYS, true ) ) { $context[ $key ] = '[redacted]'; } elseif ( is_array( $value ) ) { $context[ $key ] = self::redact( $value ); } elseif ( is_string( $value ) ) { $context[ $key ] = self::redact_text( $value ); } } return $context; } /** * Redacts API keys, email addresses and phone numbers inside free text. * Phone matching is limited to international (+/00) and Egyptian mobile formats * so AWB numbers and IDs stay readable. * * @param string $text Text. * @return string */ public static function redact_text( $text ) { $text = preg_replace( '/\babs_[A-Za-z0-9]{8,}\b/', 'abs_[redacted]', (string) $text ); $text = preg_replace( '/[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}/', '[email]', $text ); return preg_replace( '/(?:\+|\b00)\d{10,14}\b|\b01[0125]\d{8}\b/', '[phone]', $text ); } }