aternos/codex-minecraft

PHP 库,用于读取、解析、打印和分析 Minecraft 日志文件。


README

关于

Codex (拉丁语中意为“日志”) 是一个 PHP 库,用于读取、解析、打印和分析日志文件以查找问题并提出可能的解决方案。这是针对 Minecraft 日志的实现,包括检测器、解析器和分析器,用于处理不同类型的 Minecraft 日志文件。

安装

composer require aternos/codex-minecraft

用法

这仅是 Codex 在 Minecraft 中的实现的简介,更多详细信息请查看 Codex 仓库:aternosorg/codex

创建日志文件

[见 codex#logfile]

<?php

$logFile = new \Aternos\Codex\Log\File\StringLogFile("This is the log content");
$logFile = new \Aternos\Codex\Log\File\PathLogFile("/path/to/log");
$logFile = new \Aternos\Codex\Log\File\StreamLogFile(fopen("/path/to/log", "r"));

创建日志对象

[见 codex#log]

如果您知道日志类型,您可以直接创建一个新的日志对象。

<?php

$log = new \Aternos\Codex\Minecraft\Log\Minecraft\Vanilla\VanillaServerLog();
$log->setLogFile($logFile);

检测日志类型

[见 codex#detection]

如果您不知道日志类型,可以让 Detective 来决定并创建日志对象。

<?php

$detective = new \Aternos\Codex\Minecraft\Detective\Detective();
$detective->setLogFile($logFile);
$log = $detective->detect();

解析日志内容

[见 codex#parsing]

<?php

$log->parse();

分析日志

[见 codex#analysing]

<?php

$analysis = $log->analyse();

$analysis 对象包含问题和信息,您可以使用 $analysis->getProblems()$analysis->getInformation() 函数获取它们,或者使用 $analysis->getInsights() 获取所有洞察。问题包含解决方案,其中一些可以自动解决。它们实现了 \Aternos\Codex\Analysis\AutomatableSolutionInterface,例如 FileDeleteSolution

<?php

foreach ($analysis->getInformation() as $information) {
    echo $information->getLabel() . ": " . $information->getValue();
}

foreach ($analysis->getProblems() as $problem) {
    echo $problem->getMessage();
    foreach($problem->getSolutions() as $solution) {
        echo $solution->getMessage();
    }
}

翻译

输出消息,例如问题和解决方案,由 Translator 翻译。可用的翻译位于 lang 文件夹中。它们还不完整(尚不完整),您可以在此处帮助翻译它们:https://crowdin.com/project/aternos。您可以在使用任何 getMessage() 函数之前使用 setLanguage() 函数设置翻译语言。

在此处查看当前翻译状态:TRANSLATION.md

<?php

\Aternos\Codex\Minecraft\Translator\Translator::getInstance()->setLanguage("de");