waltertamboer/communicator

A PHP library that helps communicating by broadcasting your messages to one or multiple channels.

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

This package is auto-updated.

Last update: 2024-10-26 09:53:01 UTC


README

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

Communicator is a PHP library that helps you broadcast messages over multiple channels. This can be useful when you want to send notifcations to users via multiple transports such as e-mail, SMS or IRC.

Install

Via Composer

$ composer require waltertamboer/communicator

Usage

Since communicator doesn't know where to send messages to, you need to implement the Communicator\Recipient\RecipientInterface interface. Communicator will use it to determine the target addresses.

$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',
    ]
);

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Install the dependencies via 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

Run the unit tests:

Just make sure the unit tests are present :-)

Credits

License

The MIT License (MIT). Please see License File for more information.