sms-gate/sms-gate

The library for work with SMS gates.

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.0.0 2017-10-02 11:41 UTC

This package is not auto-updated.

Last update: 2020-07-05 10:56:08 UTC


README

Build Status SensioLabsInsight Scrutinizer Code Quality Code Coverage

Add functionality for sending SMS to users.

Attention: this library is abstract and only declare the contract for sending SMS to users. You should install adapter for sending SMS.

Requirements

Installation

Add SmsGate package in your composer.json:

{
    "require": {
        "sms-gate/sms-gate": "~1.0"
    }
}

Now tell composer to download the library by running the command:

$ php composer.phar update sms-gate/sms-gate

Usage

By first step you should create the adapter for sending SMS. This library does not support any adapters. You should install adapter for sending SMS.

<?php

use SmsGate\Adapter\Stub\StubAdapter;
use SmsGate\Sender\Sender;
use SmsGate\Phone;
use SmsGate\Message;

$adapter = new StubAdapter(); // Or create custom adapter.
$sender = new Sender($adapter);

$phone = new Phone('123456789');
$message = new Message('Register on http://site.com You verification code is 123456', 'MySite');

$results = $sender->send($message, $phone);

// Get the result by phone
$result = $results->findByPhone($phone);

if ($result->isSuccessfully()) {
    print 'Success send SMS'.PHP_EOL;
} else {
    print sprintf(
        'Fail send SMS: %s - %s',
        $result->getError()->getReason(),
        $result->getError()->getMessage()
    );
}

You can send the message to multiple receivers:

<?php

use SmsGate\Adapter\Stub\StubAdapter;
use SmsGate\Sender\Sender;
use SmsGate\Phone;
use SmsGate\Message;

$adapter = new StubAdapter(); // Or create custom adapter
$sender = new Sender($adapter);

$message = new Message('Hi! New products on http://site.com');

$results = $sender->send($message, new Phone('111'), new Phone('222'), new Phone('333'));

// After, you can get the result for each phone
$result1 = $results->findByPhone(new Phone('111'));
$result2 = $results->findByPhone(new Phone('222'));
$result3 = $results->findByPhone(new Phone('333'));

Note: You can use directly adapter, but we recommend using the sender instance because many systems can decorate default sender for add custom functionality (logging as an example).

<?php

use SmsGate\Adapter\Stub\StubAdapter;
use SmsGate\Sender\Sender;
use SmsGate\Sender\LoggingSenderDecorator;
use SmsGate\Phone;
use SmsGate\Message;

$logger = new \Psr\Log\NullLogger(); // Or create custom logger instance
$adapter = new StubAdapter(); // Or create custom adapter
$originSender = new Sender($adapter);
$sender = new LoggingSenderDecorator($originSender, $logger);

$message = new Message('Hi! New products on http://site.com');
$sender->send($message, new Phone('111'));

License

This library is under the MIT license. See the complete license in library

LICENSE

Reporting an issue or a feature request

Issues and feature requests are tracked in the Github issue tracker.

Contributors:

Thanks to everyone participating in the development of this SmsGate library!