Skip to content

Commit

Permalink
Choose bind mode ability in service layer
Browse files Browse the repository at this point in the history
  • Loading branch information
dglushkov committed Jun 30, 2020
1 parent 30e92ec commit 233c0a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/Service/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,33 @@
namespace PhpSmpp\Service;


use PhpSmpp\Client;

class Listener extends Service
{

public function bind()
{
$this->openConnection();
$this->client->bindReceiver($this->login, $this->pass);
if (Client::BIND_MODE_TRANSCEIVER == $this->bindMode) {
$this->client->bindTransceiver($this->login, $this->pass);
} else {
$this->client->bindReceiver($this->login, $this->pass);
}
}

/**
* @param callable $callback \PhpSmpp\Pdu\Pdu passed as a parameter
*/
public function listen(Callable $callback)
public function listen(callable $callback)
{
while (true) {
$this->listenOnce($callback);
usleep(10e4);
}
}

public function listenOnce(Callable $callback)
public function listenOnce(callable $callback)
{
$this->enshureConnection();
$this->client->listenSm($callback);
Expand Down
7 changes: 6 additions & 1 deletion src/Service/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace PhpSmpp\Service;


use PhpSmpp\Client;
use PhpSmpp\Helper;
use PhpSmpp\Logger;
use PhpSmpp\SMPP;
Expand All @@ -20,7 +21,11 @@ class Sender extends Service
public function bind()
{
$this->openConnection();
$this->client->bindTransmitter($this->login, $this->pass);
if (Client::BIND_MODE_TRANSCEIVER == $this->bindMode) {
$this->client->bindTransceiver($this->login, $this->pass);
} else {
$this->client->bindTransmitter($this->login, $this->pass);
}
}

public function send($phone, $message, $from)
Expand Down
12 changes: 11 additions & 1 deletion src/Service/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ abstract class Service
protected $hosts;
protected $login;
protected $pass;
protected $bindMode;
protected $debug = false;
protected $debugHandler = 'error_log';

/** @var Client */
public $client = null;

public function __construct($hosts, $login, $pass, $debug = false)
/**
* Service constructor.
* @param array $hosts example ['123.123.123.123:2777','124.124.124.124']
* @param string $login
* @param string $pass
* @param string $bindMode example PhpSmpp\Client::BIND_MODE_TRANSMITTER
* @param bool $debug
*/
public function __construct($hosts, $login, $pass, $bindMode, $debug = false)
{
$this->hosts = $hosts;
$this->login = $login;
$this->pass = $pass;
$this->bindMode = $bindMode;
$this->debug = $debug;
$this->initClient();
}
Expand Down

0 comments on commit 233c0a6

Please sign in to comment.