waltertamboer/communicator

一个PHP库,通过广播消息到一个或多个频道来帮助进行通信。

dev-master / 1.0.x-dev 2020-01-25 23:00 UTC

This package is auto-updated.

Last update: 2024-08-26 09:27:51 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Communicator 是一个PHP库,可以帮助你通过多个频道广播消息。当你想要通过电子邮件、短信或IRC等多种传输方式向用户发送通知时,这非常有用。

安装

通过 Composer

$ composer require waltertamboer/communicator

用法

由于communicator不知道要将消息发送到何处,您需要实现 Communicator\Recipient\RecipientInterface 接口。Communicator 将使用它来确定目标地址。

$recipient = new ... // An implementation of Communicator\Recipient\RecipientInterface

$communicator = new Communicator\Communicator();

// Bind a transport. Of course this can be any transport you require.
// It's also possible to bind multiple transports to the same channel.
$communicator->bindTransport('my-channel', new Communicator\Transport\Noop\Transport());

// Now broadcast a message to all transports.
$communicator->broadcast(
    [
        $recipient,
    ],
    'my-channel', 
    [
        'my-param' => 'some param',
    ]
);

变更日志

有关最近变更的更多信息,请参阅 CHANGELOG

测试

$ composer test

贡献

通过 Docker 安装依赖项

docker run --rm --interactive --tty \
    --volume $PWD:/app \
    --volume $SSH_AUTH_SOCK:/ssh-auth.sock \
    --volume /etc/passwd:/etc/passwd:ro \
    --volume /etc/group:/etc/group:ro \
    --user $(id -u):$(id -g) \
    --env SSH_AUTH_SOCK=/ssh-auth.sock \
    composer install

运行单元测试

只需确保存在单元测试即可 :-)

鸣谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件