fabiang / xmpp
此包已被废弃,不再维护。没有建议的替代包。
XMPP协议(Jabber)连接库
0.7.0
2017-05-23 12:47 UTC
Requires
- php: ^5.6 || ^7.0
- psr/log: ^1.0
Requires (Dev)
- behat/behat: ^2.5.5
- monolog/monolog: ^1.22
- phpunit/phpunit: ^5.7.20
- satooshi/php-coveralls: ^1.0
- symfony/console: ^2.8
- symfony/dependency-injection: ^2.8
- symfony/finder: ^2.8
Suggests
- psr/log-implementation: Allows more advanced logging of the xmpp connection
README
PHP的XMPP协议(Jabber)连接库。
系统要求
- PHP最低版本5.6或7.0
- psr/log
- (可选) psr/log-implementation - 如monolog/monolog用于日志记录
安装
是Composer新手?请阅读介绍。将以下内容添加到您的composer文件中
composer require fabiang/xmpp
文档
此库使用一个对象来保存选项
use Fabiang\Xmpp\Options; $options = new Options($address); $options->setUsername($username) ->setPassword($password);
服务器地址必须为格式tcp://myjabber.com:5222
。
如果服务器支持TLS,连接将自动加密。
您还可以传递一个PSR-2兼容的对象到选项对象中
$options->setLogger($logger)
客户端管理到Jabber服务器的连接并需要选项对象
use Fabiang\Xmpp\Client; $client = new Client($options); // optional connect manually $client->connect();
发送数据时,您只需传递一个实现Fabiang\Xmpp\Protocol\ProtocolImplementationInterface
的对象
use Fabiang\Xmpp\Protocol\Roster; use Fabiang\Xmpp\Protocol\Presence; use Fabiang\Xmpp\Protocol\Message; // fetch roster list; users and their groups $client->send(new Roster); // set status to online $client->send(new Presence); // send a message to another user $message = new Message; $message->setMessage('test') ->setTo('nickname@myjabber.com') $client->send($message); // join a channel $channel = new Presence; $channel->setTo('channelname@conference.myjabber.com') ->setPassword('channelpassword') ->setNickName('mynick'); $client->send($channel); // send a message to the above channel $message = new Message; $message->setMessage('test') ->setTo('channelname@conference.myjabber.com') ->setType(Message::TYPE_GROUPCHAT); $client->send($message);
最后,您应该断开连接
$client->disconnect();
开发
如果您喜欢这个库并且想贡献,请确保单元测试和集成测试正在运行。Composer将帮助您安装正确的PHPUnit和Behat版本。
composer install
之后
./vendor/bin/phpunit
./vendor/bin/behat
新功能应该始终使用Behat进行测试。
许可证
BSD-2-Clause。请参阅许可证。
待办事项
- 更好地集成通道
- 服务器地址的工厂方法
- 改进文档