8000 * LightSmsTransport.php - via mistake removed www which return (Closi… · symfony/symfony@9a832ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 9a832ef

Browse files
committed
* LightSmsTransport.php - via mistake removed www which return (Closing direction to the user). Removed additional isset which in reality not needed. Added new method which allow to return "unknown error" and throw exception if not successfully
1 parent 178d9c2 commit 9a832ef

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
final class LightSmsTransport extends AbstractTransport
2828
{
29-
protected const HOST = 'lightsms.com';
29+
protected const HOST = 'www.lightsms.com';
3030

3131
private $login;
3232
private $password;
@@ -72,6 +72,7 @@ final class LightSmsTransport extends AbstractTransport
7272
37 => 'Base Id is not set',
7373
38 => 'Phone number already exists in this database',
7474
39 => 'Phone number does not exist in this database',
75+
999 => 'Unknown Error',
7576
];
7677

7778
public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
@@ -119,25 +120,27 @@ protected function doSend(MessageInterface $message): SentMessage
119120
$content = $response->toArray(false);
120121

121122
// it happens if the host without www
122-
if (isset($content['']) && isset($content['']['error'])) {
123-
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response);
123+
if (isset($content['']['error'])) {
124+
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['']['error']), $response);
124125
}
125126

126127
if (isset($content['error'])) {
127-
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response);
128+
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['error']), $response);
128129
}
129130

130131
$phone = $this->escapePhoneNumber($message->getPhone());
131132
if (32 === $content[$phone]['error']) {
132-
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response);
133+
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content[$phone]['error']), $response);
133134
}
134135

135136
if (0 == $content[$phone]['error']) {
136137
$sentMessage = new SentMessage($message, (string) $this);
137138
$sentMessage->setMessageId($content[$phone]['id_sms']);
139+
140+
return $sentMessage;
138141
}
139142

140-
return $sentMessage;
143+
throw new TransportException('Unable to send the SMS: ', $response);
141144
}
142145

143146
private function generateSignature(array $data, int $timestamp): string
@@ -160,4 +163,9 @@ private function escapePhoneNumber(string $phoneNumber): string
160163
{
161164
return str_replace('+', '00', $phoneNumber);
162165
}
166+
167+
private function getErrorMsg(string $errorCode): string
168+
{
169+
return isset(self::ERROR_CODES[$errorCode]) ? self::ERROR_CODES[$errorCode] : self::ERROR_CODES[999];
170+
}
163171
}

0 commit comments

Comments
 (0)
0