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.
32 lines
1.1 KiB
PHP
32 lines
1.1 KiB
PHP
<?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));
|
|
}
|
|
}
|