dev-lancer/minecraft-motd-parser
Composer 安装命令:
composer require dev-lancer/minecraft-motd-parser
包简介
PHP library to parse minecraft server motd
README 文档
README
PHP library to parse minecraft server motd
Installation
This library can be installed by issuing the following command:
composer require dev-lancer/minecraft-motd-parser
Documentation
| Lang |
|---|
| EN |
| PL |
Parsing
Usage TextParser
To parse a text-based MOTD using custom formatting and colors:
$formatCollection = \DevLancer\MinecraftMotdParser\Collection\FormatCollection::generate(); $colorCollection = \DevLancer\MinecraftMotdParser\Collection\ColorCollection::generate(true); //When set to true, colors from BE are added $parser = new \DevLancer\MinecraftMotdParser\Parser\TextParser($formatCollection, $colorCollection, '&'); $motd = "A &l&fMine&4craft &rServer"; $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\Collection\MotdItemCollection());
Usage ArrayParser
To parse a structured array-based MOTD:
$formatCollection = \DevLancer\MinecraftMotdParser\Collection\FormatCollection::generate(); $colorCollection = \DevLancer\MinecraftMotdParser\Collection\ColorCollection::generate(); $parser = new \DevLancer\MinecraftMotdParser\Parser\ArrayParser($formatCollection, $colorCollection); $motd = [ [ "text" => "A "], [ "bold" => true, "extra" => [ [ "color" => "white", "text" => "Mine" ], [ "color" => "dark_red", "text" => "craft " ], ] ], [ "text" => "Server" ] ]; $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\Collection\MotdItemCollection());
Merging Similar Items
The mergeSimilarItem() method in the MotdItemCollection class merges adjacent MotdItem objects with the same formatting and color. This optimization helps to reduce redundancy in the formatting and color codes, making the MOTD more concise.
$motd = "A &l&fMine&f&lcraft &rServer"; $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\Collection\MotdItemCollection()); //Output before [ ['text': "A "], ['bold': true, 'color': "white", 'text': "Mine"], ['bold': true, 'color': "white", 'text': "craft "], ['reset': true, 'text': "Server"], ] $motdItemCollection->mergeSimilarItem(); //Output after [ ['text': "A "], ['bold': true, 'color': "white", 'text': "Minecraft "], ['reset': true, 'text': "Server"], ]
Generation
MotdItemCollection
Example of creating a MotdItemCollection:
$parser = new \DevLancer\MinecraftMotdParser\Parser\TextParser(); $motd = "A §l§fMine§4craft §rServer"; $motdItemCollection = $parser->parse($motd, new \DevLancer\MinecraftMotdParser\Collection\MotdItemCollection());
Usage HtmlGenerator
To generate HTML from a parsed MOTD:
$generator = new \DevLancer\MinecraftMotdParser\Generator\HtmlGenerator(); // Generate HTML from the MOTD item collection echo $generator->generate($motdItemCollection);
Output
The output will be:
A <span style="font-weight: bold; color: #FFFFFF;">Mine</span> <span style="font-weight: bold; color: #AA0000;">craft </span> Server
Usage RawGenerator
To generate raw text from a parsed MOTD:
$generator = new \DevLancer\MinecraftMotdParser\Generator\RawGenerator("§"); // Generate raw text from the MOTD item collection echo $generator->generate($motdItemCollection); //output: A §f§lMine§4craft §rServer
Usage TextGenerator
To generate plain text from a parsed MOTD:
$generator = new \DevLancer\MinecraftMotdParser\Generator\TextGenerator(); // Generate plain text from the MOTD item collection echo $generator->generate($motdItemCollection); //output: A Minecraft Server
Custom formatter
Define new class formatter
Example of creating a custom bold formatter:
class CustomBoldFormatter implements FormatterInterface { public function getKey(): string { return 'l'; } public function getName(): string { return 'bold'; } public function getFormat(): string { return '<b class="CustomBoldFormatter">%s</b>'; } }
Usage
To use the custom formatter:
// Create a new format collection $formatCollection = \DevLancer\MinecraftMotdParser\Collection\FormatCollection::generate(); // and override the default formatter for bold $formatCollection->add(new CustomBoldFormatter()); // Create a new MOTD item $motdItem = new \DevLancer\MinecraftMotdParser\MotdItem(); $motdItem->setBold(true); $motdItem->setText("Hello World"); // Create a new MOTD item collection and add the MOTD item $motdItemCollection = new \DevLancer\MinecraftMotdParser\Collection\MotdItemCollection(); $motdItemCollection->add($motdItem); // Generate HTML using the custom formatter $generator = new \DevLancer\MinecraftMotdParser\Generator\HtmlGenerator($formatCollection); echo $generator->generate($motdItemCollection);
Output
The output will be:
<b class="CustomBoldFormatter">Hello World</b>
License
This library is licensed under the MIT License.
dev-lancer/minecraft-motd-parser 适用场景与选型建议
dev-lancer/minecraft-motd-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.74k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「php」 「parser」 「server」 「minecraft」 「motd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dev-lancer/minecraft-motd-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dev-lancer/minecraft-motd-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dev-lancer/minecraft-motd-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
An MT940 bank statement parser for PHP
Laravel integration for the jsonapi.org parser
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
JPOPHP (JSON Parser Object PHP) is a library for parsing the data in JSON format.
统计信息
- 总下载量: 4.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-18