feat: scaffold RedactorInterface and ProjectZomboidRedactor with toggles

This commit is contained in:
2026-05-01 14:34:34 +00:00
parent 409de16003
commit 7755d8385c
2 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
<?php
namespace IndifferentKetchup\Codex\Util\ProjectZomboid;
use IndifferentKetchup\Codex\Util\RedactorInterface;
/**
* Render-time PII filter for Project Zomboid log content.
*
* Applies up to three sequential regex passes over the raw log string,
* each controlled by a boolean toggle (all enabled by default):
*
* 1. Steam ID pass — replaces 17-digit Steam IDs with a placeholder token.
* 2. Player name pass — replaces player display names with a placeholder
* token. This pass anchors on the already-redacted Steam ID token, so
* the ordering Steam ID -> name -> coordinates is mandatory.
* 3. Coordinates pass — replaces world coordinate triplets with a placeholder
* token.
*
* All regex passes use the /u flag for Unicode safety.
*
* Replacements are not reversible; do not apply to content that must later be
* restored to its original form.
*/
class ProjectZomboidRedactor implements RedactorInterface
{
private bool $redactSteamIds = true;
private bool $redactPlayerNames = true;
private bool $redactCoordinates = true;
/**
* Enable or disable the Steam ID redaction pass.
*
* @param bool $on Pass true to enable, false to disable.
* @return static
*/
public function redactSteamIds(bool $on): static
{
$this->redactSteamIds = $on;
return $this;
}
/**
* Enable or disable the player-name redaction pass.
*
* @param bool $on Pass true to enable, false to disable.
* @return static
*/
public function redactPlayerNames(bool $on): static
{
$this->redactPlayerNames = $on;
return $this;
}
/**
* Enable or disable the coordinates redaction pass.
*
* @param bool $on Pass true to enable, false to disable.
* @return static
*/
public function redactCoordinates(bool $on): static
{
$this->redactCoordinates = $on;
return $this;
}
/**
* Redact PII from the given Project Zomboid log content.
*
* Passes are applied in the mandatory order: Steam ID -> player name ->
* coordinates. See class docblock for rationale.
*
* @param string $content Raw log content that may contain PII.
* @return string Content with enabled PII categories replaced by tokens.
*/
public function redact(string $content): string
{
if ($this->redactSteamIds) {
// Steam ID pass added in Task 2
}
if ($this->redactPlayerNames) {
// Player name pass added in Task 3
}
if ($this->redactCoordinates) {
// Coordinates pass added in Task 4
}
return $content;
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace IndifferentKetchup\Codex\Util;
interface RedactorInterface
{
/**
* Redact PII from the given content string and return the result.
*
* The method is stateless from the caller's perspective: the same instance
* may be called repeatedly and each call operates independently on its
* input. Configuration (which passes are enabled, replacement tokens, etc.)
* is applied once via implementation-specific setters before the first call
* to redact().
*
* @param string $content Raw log content that may contain PII.
* @return string Content with PII replaced by redaction tokens.
*/
public function redact(string $content): string;
}