2017 © Pedro Peláez
 

zf-module sms

ZF2 wrapper for various SMS providers.

image

pontifex/sms

ZF2 wrapper for various SMS providers.

  • Wednesday, May 20, 2015
  • by pontifex
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

ZF2 wrapper for various SMS providers., (*1)

SensioLabsInsight, (*2)

TODO: 1) Implement next adapters. (If you find this repository useful and would like to contribute new adapters, you are welcome!), (*3)

To add new SMS adapter implement \SMS\Model\Adapter\AdapterInterface (1 method - send())., (*4)

Tested on ZF 2.2.1 and PHP 5.3.3, (*5)

How to use example:, (*6)

Module is available via composer., (*7)

{
    "require": {
        "pontifex/sms": "dev-master"
    }
}

Before you start: - set credentials for chosen adapter (in our case SMSAPI) as shown in sms.config.global.php - be sure you added "SMS" module to application.config.php, (*8)

How to use example:, (*9)

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController,
    Zend\View\Model\ViewModel,
    SMS\Model\SMS,
    SMS\Model\Struct;

/**
 * Class IndexController
 * @package SMS\Controller
 */
class IndexController extends AbstractActionController implements CountryPrefixConstantsInterface
{
    /**
     * @return ViewModel
     */
    public function indexAction()
    {
        $item1 = new Struct\SMS();
        $item1->setTo(new Struct\NumberTo(self::POLAND, '123123123'));
        $item1->setMessage(new Struct\Message('Hello world #1!'));

        $item2 = new Struct\SMS();
        $item2->setTo(new Struct\NumberTo(self::GERMANY, '321321321'));
        $item2->setMessage(new Struct\Message('Hello world #2!'));

        $coll = new Struct\SMSCollection();
        $coll->attach($item1);
        $coll->attach($item2);

        /** @var SMS $sms */
        $sms = $this->getServiceLocator()->get('SMS\Factory\SMSAPITest');

        try {
            $sms->send($coll);
        } catch (\Exception $e) {
            //
        }

        return new ViewModel(array('result' => $sms->getResult()));
    }
}

If you would like to add eg. log sms feature, the best implement it using preSend, postSend and errorOnSend events (example from Module.php)., (*10)

/**
 * @param MvcEvent $e
 */
public function onBootstrap(\Zend\Mvc\MvcEvent $e)
{
    $e->getApplication()->getEventManager()->getSharedManager()->attach(
        'SMS\Model\Adapter\AdapterAbstract',
        'SMS.postSend',
        function(\Zend\EventManager\Event $event) {
            echo 'SMS to number: ' . $event->getParam('to')->getNumber() . ' is sent!<br />';
        }
    );
}

The Versions

20/05 2015

dev-master

9999999-dev https://github.com/pontifex/SMS

ZF2 wrapper for various SMS providers.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

zf2 sms module