Add ProjectZomboid log base classes

ProjectZomboidLog (abstract): extends AnalysableLog, implements
DetectableLogInterface. Centralises the PZ timestamp format
('d-m-y H:i:s.v') and UTC default timezone, plus a makePatternParser()
helper so concrete subclasses only specify their line regex and capture
group names. ProjectZomboidEventLog (abstract): marker base for the ten
single-line structured PZ logs, distinct from the multi-line
ProjectZomboidServerLog. Concrete subclasses follow.
This commit is contained in:
2026-04-30 20:31:12 +00:00
parent ada3c7875d
commit c032fd34b8
3 changed files with 45 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
/**
* Marker base for ProjectZomboid logs whose entries are strictly one line
* each (the ten structured event files: admin, BurdJournals, chat,
* ClientActionLog, cmd, item, map, PerkLog, pvp, user). Distinct from
* ProjectZomboidServerLog, which permits multi-line entries
* (DebugLog-server stack traces).
*/
abstract class ProjectZomboidEventLog extends ProjectZomboidLog
{
}

View File

@@ -0,0 +1,31 @@
<?php
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
use DateTimeZone;
use IndifferentKetchup\Codex\Log\AnalysableLog;
use IndifferentKetchup\Codex\Log\DetectableLogInterface;
use IndifferentKetchup\Codex\Parser\PatternParser;
abstract class ProjectZomboidLog extends AnalysableLog implements DetectableLogInterface
{
public const string TIME_FORMAT = 'd-m-y H:i:s.v';
public const string DEFAULT_TIMEZONE = 'UTC';
/**
* Build a PatternParser preconfigured with the shared PZ time format
* and timezone. Subclasses pass their line regex and the names of the
* capture groups by index.
*
* @param string $pattern PCRE regex anchored at line start, with named groups
* @param array<int, string> $matches Match-type constants in capture-group order
*/
protected static function makePatternParser(string $pattern, array $matches): PatternParser
{
return (new PatternParser())
->setPattern($pattern)
->setMatches($matches)
->setTimeFormat(static::TIME_FORMAT)
->setTimezone(new DateTimeZone(static::DEFAULT_TIMEZONE));
}
}