2012-10-06 23:35:20 +00:00
|
|
|
<?php
|
2012-10-08 18:45:50 +00:00
|
|
|
namespace GergelyPolonkai\SmsSenderBundle\Service;
|
2012-10-06 23:35:20 +00:00
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
|
|
use RuntimeException;
|
|
|
|
use GergelyPolonkai\SmsSender\Sender as BaseSender;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Gergely Polonkai
|
|
|
|
*
|
|
|
|
* SMS Sending service for JSON-RPC based SMS Sender server
|
|
|
|
*/
|
|
|
|
class Sender
|
|
|
|
{
|
|
|
|
private $loggedIn;
|
|
|
|
|
|
|
|
private $sender;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Symfony\Component\DependencyInjection\ContainerInterface $container
|
|
|
|
*/
|
|
|
|
private $container;
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
|
|
|
|
$this->sender = new BaseSender(
|
|
|
|
$this->container->getParameter('sender_url'),
|
|
|
|
$this->container->getParameter('content_type'),
|
|
|
|
$this->container->getParameter('content_encoding'),
|
|
|
|
$this->container->getParameter('verify_ssl'),
|
|
|
|
$this->container->getParameter('verbose_curl')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-11-04 14:14:27 +00:00
|
|
|
public function login()
|
2012-10-06 23:35:20 +00:00
|
|
|
{
|
2012-11-04 14:14:27 +00:00
|
|
|
if ($this->sender->login($this->container->getParameter('username'), $this->container->getParameter('password')) === true) {
|
2012-10-06 23:49:25 +00:00
|
|
|
$this->loggedIn = true;
|
|
|
|
}
|
2012-10-06 23:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function sendMessage($recipient, $message, array $passwordLocations)
|
|
|
|
{
|
2012-10-06 23:49:25 +00:00
|
|
|
if (!$this->loggedIn) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->sender->sendMessage($recipient, $message, $passwordLocations);
|
2012-10-06 23:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function logout()
|
|
|
|
{
|
2012-10-06 23:49:25 +00:00
|
|
|
if (!$this->loggedIn) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->sender->logout();
|
2012-10-06 23:35:20 +00:00
|
|
|
}
|
|
|
|
}
|