Skip to content

Commit

Permalink
Merge pull request #1 from devimteam/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Darkenery authored Oct 28, 2016
2 parents 3e752f7 + 8ac5829 commit d13e538
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/MttServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ public function register(Container $container)
{
$container['mtt.login'] = '';
$container['mtt.password'] = '';
$container['mtt.short_code'] = '';

$container['mtt.sender'] = function () use ($container) {
return new MttSmsSender($container['mtt.login'], $container['mtt.password'], $container['mtt.short_code']);
return new MttSmsSender($container['mtt.login'], $container['mtt.password']);
};
}
}
19 changes: 7 additions & 12 deletions src/Sender/MttSmsSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,33 @@ class MttSmsSender implements SmsSenderInterface
*/
private $password;

/**
* @var string
*/
private $shortCode;

/**
* MttSmsSender constructor.
*
* @param string $login
* @param string $password
* @param string $shortCode
*/
public function __construct(string $login, string $password, string $shortCode)
public function __construct(string $login, string $password)
{
$this->login = $login;
$this->password = $password;
$this->shortCode = $shortCode;
}

/**
* Send SMS.
*
* @param string $to
* @param string $message
* @param string $shortCode
*
* @return mixed
*
* @throws \Devim\Provider\MttServiceProvider\Sender\Exception\SmsErrorException
* @throws \Devim\Provider\MttServiceProvider\Sender\Exception\SmsSendException
*/
public function send(string $to, string $message)
public function send(string $to, string $message, string $shortCode)
{
$url = self::SMS_POOL_URL . '?' . $this->buildQuery($to, $message);
$url = self::SMS_POOL_URL . '?' . $this->buildQuery($to, $message, $shortCode);

$request = curl_init($url);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
Expand All @@ -75,17 +69,18 @@ public function send(string $to, string $message)
/**
* @param string $to
* @param string $message
* @param string $shortCode
*
* @return string
*/
final private function buildQuery(string $to, string $message) : string
final private function buildQuery(string $to, string $message, string $shortCode) : string
{
return http_build_query([
'login' => $this->login,
'password' => $this->password,
'msisdn' => $to,
'text' => $message,
'shortcode' => $this->shortCode,
'shortcode' => $shortCode,
'operation' => 'send',
]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Sender/NullSmsSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class NullSmsSender implements SmsSenderInterface
*
* @param string $to
* @param string $message
* @param string $shortCode
*
* @return void
*/
public function send(string $to, string $message)
public function send(string $to, string $message, string $shortCode)
{
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Sender/SmsSenderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ interface SmsSenderInterface
*
* @param string $to
* @param string $message
* @param string $shortCode
*
* @return mixed
*/
public function send(string $to, string $message);
public function send(string $to, string $message, string $shortCode);
}

0 comments on commit d13e538

Please sign in to comment.