-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SmsSenderInterface Small fixes
- Loading branch information
Showing
19 changed files
with
303 additions
and
159 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace BikeShare\Sms; | ||
|
||
use BikeShare\Db\DbInterface; | ||
use BikeShare\SmsConnector\SmsConnectorInterface; | ||
|
||
class SmsSender implements SmsSenderInterface | ||
{ | ||
/** | ||
* @var SmsConnectorInterface | ||
*/ | ||
private $smsConnector; | ||
/** | ||
* @var DbInterface | ||
*/ | ||
private $db; | ||
|
||
public function __construct( | ||
SmsConnectorInterface $smsConnector, | ||
DbInterface $db | ||
) { | ||
$this->smsConnector = $smsConnector; | ||
$this->db = $db; | ||
} | ||
|
||
public function send($number, $message) | ||
{ | ||
if (strlen($message) > 160) { | ||
$messageParts = str_split($message, 160); | ||
foreach ($messageParts as $text) { | ||
$text = trim($text); | ||
if ($text) { | ||
$this->log($number, $text); | ||
$this->smsConnector->send($number, $text); | ||
} | ||
} | ||
} else { | ||
$this->log($number, $message); | ||
$this->smsConnector->send($number, $message); | ||
} | ||
} | ||
|
||
private function log($number, $message) | ||
{ | ||
$this->db->query("INSERT INTO sent SET number='$number', text='$message'"); | ||
$this->db->commit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace BikeShare\Sms; | ||
|
||
interface SmsSenderInterface | ||
{ | ||
public function send($number, $message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace BikeShare\SmsConnector; | ||
|
||
class DebugConnector extends AbstractConnector | ||
{ | ||
public function checkConfig(array $config) | ||
{ | ||
} | ||
|
||
public function respond() | ||
{ | ||
} | ||
|
||
public function send($number, $text) | ||
{ | ||
echo $number . ' -> ' . $text . PHP_EOL; | ||
} | ||
} |
Oops, something went wrong.