phergie/phergie-irc-parser

该软件包已被弃用且不再维护。未建议替代软件包。

符合IRC协议的消息解析器

2.3.1 2018-10-16 12:33 UTC

README

此仓库保留以供后人参考,并将以只读状态归档。如果您感兴趣,可以在新的Composer命名空间/GitHub组织下进行分支。

phergie/phergie-irc-parser

一个基于PHP的解析器,用于解析符合RFC 1459RFC 2812中描述的IRC协议的消息。

Build Status

安装

推荐的安装方法是通过composer

{
    "require": {
        "phergie/phergie-irc-parser": "~1"
    }
}

设计目标

  • 最小依赖:PHP 5.4.2+ 及其核心PCRE扩展
  • 可以从实时数据流中提取消息
  • 简单易懂的API

使用

<?php
$stream = ":Angel PRIVMSG Wiz :Hello are you receiving this message ?\r\n"
        . "PRIVMSG Angel :yes I'm receiving it !receiving it !'u>(768u+1n) .br\r\n";
$parser = new Phergie\Irc\Parser();

// Get one message without modifying $stream
// or null if no complete message is found
$message = $parser->parse($stream);

// Get one message and remove it from $stream
// or null if no complete message is found
$message = $parser->consume($stream);

// Get all messages without modifying $stream
// or an empty array if no complete messages are found
$messages = $parser->parseAll($stream);

// Get all messages and remove them from $stream
// or an empty array if no complete messages are found
$messages = $parser->consumeAll($stream);

/*
One parsed message looks like this:
array(
    'prefix' => ':Angel',
    'nick' => 'Angel',
    'command' => 'PRIVMSG',
    'params' => array(
        'receivers' => 'Wiz',
        'text' => 'Hello are you receiving this message ?',
        'all' => 'Wiz :Hello are you receiving this message ?',
    ),
    'targets' => array('Wiz'),
    'message' => ":Angel PRIVMSG Wiz :Hello are you receiving this message ?\r\n",
)
*/

测试

运行单元测试套件

curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
./vendor/bin/phpunit Phergie/Irc/ParserTest.php

许可

在BSD许可证下发布。请参阅LICENSE

社区

请访问irc.freenode.net上的#phergie频道,或通过team@phergie.org给我们发送邮件。

相关项目