Add Ovh Soap Support

This commit is contained in:
Leny Bernard 2012-12-26 15:07:44 +01:00
parent fdde9b5bfa
commit 8503e34961
5 changed files with 72 additions and 2 deletions

View File

@ -33,12 +33,18 @@ class Configuration implements ConfigurationInterface
->booleanNode('verbose_curl') ->booleanNode('verbose_curl')
->defaultFalse() ->defaultFalse()
->end() ->end()
->scalarNode('sms_account_id')
->defaultFalse()
->end()
->scalarNode('username') ->scalarNode('username')
->isRequired() ->isRequired()
->end() ->end()
->scalarNode('password') ->scalarNode('password')
->isRequired() ->isRequired()
->end() ->end()
->scalarNode('from')
->isRequired()
->end()
->end(); ->end();
return $treeBuilder; return $treeBuilder;

View File

@ -28,5 +28,7 @@ class GergelyPolonkaiSmsSenderExtension extends Extension
$container->setParameter('verbose_curl', $config['verbose_curl']); $container->setParameter('verbose_curl', $config['verbose_curl']);
$container->setParameter('username', $config['username']); $container->setParameter('username', $config['username']);
$container->setParameter('password', $config['password']); $container->setParameter('password', $config['password']);
$container->setParameter('sms_account_id', $config['sms_account_id']);
$container->setParameter('from', $config['from']);
} }
} }

View File

@ -6,11 +6,15 @@
<parameters> <parameters>
<parameter key="gergely_polonkai_sms_sender.sender.class">GergelyPolonkai\SmsSenderBundle\Service\Sender</parameter> <parameter key="gergely_polonkai_sms_sender.sender.class">GergelyPolonkai\SmsSenderBundle\Service\Sender</parameter>
<parameter key="gergely_polonkai_sms_sender.ovhSoapSender.class">GergelyPolonkai\SmsSenderBundle\Service\OvhSoapSender</parameter>
</parameters> </parameters>
<services> <services>
<service id="gergely_polonkai_sms_sender.sender" class="%gergely_polonkai_sms_sender.sender.class%"> <service id="gergely_polonkai_sms_sender.sender" class="%gergely_polonkai_sms_sender.sender.class%">
<argument type="service" id="service_container" /> <argument type="service" id="service_container" />
</service> </service>
<service id="gergely_polonkai_sms_sender.ovhSoapSender" class="%gergely_polonkai_sms_sender.ovhSoapSender.class%">
<argument type="service" id="service_container" />
</service>
</services> </services>
</container> </container>

58
Service/OvhSoapSender.php Normal file
View File

@ -0,0 +1,58 @@
<?php
namespace GergelyPolonkai\SmsSenderBundle\Service;
use Symfony\Component\DependencyInjection\ContainerInterface;
use RuntimeException;
use GergelyPolonkai\SmsSender\OvhSoapSender as BaseSender;
/**
* @author Gergely Polonkai
*
* SMS Sending service for OVH Soap based SMS Sender server
*/
class OvhSoapSender
{
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('sms_account_id'),
$this->container->getParameter('from'));
}
public function login()
{
if ($this->sender->login($this->container->getParameter('username'), $this->container->getParameter('password'))){
$this->loggedIn = true;
} else {
throw new \RuntimeException('Unable to login to gateway!');
}
}
public function sendMessage($recipient, $message, array $passwordLocations)
{
if (!$this->loggedIn) {
return false;
}
$this->sender->sendMessage($recipient, $message, $passwordLocations);
}
public function logout()
{
if (!$this->loggedIn) {
return false;
}
$this->sender->logout();
}
}

View File

@ -3,12 +3,12 @@ namespace GergelyPolonkai\SmsSenderBundle\Service;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use RuntimeException; use RuntimeException;
use GergelyPolonkai\SmsSender\Sender as BaseSender; use GergelyPolonkai\SmsSender\OvhSoapSender as BaseSender;
/** /**
* @author Gergely Polonkai * @author Gergely Polonkai
* *
* SMS Sending service for JSON-RPC based SMS Sender server * SMS Sending service for OVH Soap based SMS Sender server
*/ */
class Sender class Sender
{ {