From b075c0eae2efb46a903b15da949c95ba1f5a646e Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 12:28:03 +0300 Subject: [PATCH 01/62] * LightSms notifier --- .../Notifier/Bridge/LightSms/LICENSE | 19 +++ .../Bridge/LightSms/LightSmsTransport.php | 153 ++++++++++++++++++ .../LightSms/LightSmsTransportFactory.php | 49 ++++++ .../Notifier/Bridge/LightSms/README.md | 28 ++++ .../Notifier/Bridge/LightSms/composer.json | 30 ++++ .../Notifier/Bridge/LightSms/phpunit.xml.dist | 31 ++++ 6 files changed, 310 insertions(+) create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/README.md create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/composer.json create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/phpunit.xml.dist diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE b/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE new file mode 100644 index 0000000000000..ad85e1737485d --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2020-2021 Fabien Potencier + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php new file mode 100644 index 0000000000000..f49dafd6a234a --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -0,0 +1,153 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\LightSms; + +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Notifier\Exception\TransportException; +use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException; +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\SentMessage; +use Symfony\Component\Notifier\Message\SmsMessage; +use Symfony\Component\Notifier\Transport\AbstractTransport; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; + +/** + * @author Vasilij Duško + */ +final class LightSmsTransport extends AbstractTransport +{ + protected const HOST = 'www.lightsms.com/external/get/send.php'; + + private $login; + private $password; + private $phone; + /** + * @var MessageInterface + */ + private $message; + + private $errorCodes = [ + '000' => 'Service unavailable', + '1' => 'Signature not specified', + '2' => 'Login not specified', + '3' => 'Text not specified', + '4' => 'Phone number not specified', + '5' => 'Sender not specified', + '6' => 'Invalid signature', + '7' => 'Invalid login', + '8' => 'Invalid sender name', + '9' => 'Sender name not registered', + '10' => 'Sender name not approved', + '11' => 'There are forbidden words in the text', + '12' => 'Error in SMS sending', + '13' => 'Phone number is in the blackist. SMS sending to this number is forbidden.', + '14' => 'There are more than 50 numbers in the request', + '15' => 'List not specified', + '16' => 'Invalid phone number', + '17' => 'SMS ID not specified', + '18' => 'Status not obtained', + '19' => 'Empty response', + '20' => 'The number already exists', + '21' => 'No name', + '22' => 'Template already exists', + '23' => 'Month not specifies (Format: YYYY-MM)', + '24' => 'Timestamp not specified', + '25' =>'Error in access to the list', + '26' => 'There are no numbers in the list', + '27' => 'No valid numbers', + '28' => 'Date of start not specified (Format: YYYY-MM-DD)', + '29' => 'Date of end not specified (Format: YYYY-MM-DD)', + '30' => 'No date (format: YYYY-MM-DD)', + '31' => 'Closing direction to the user', + '32' => 'Not enough money', + '33' => 'Phone number is not set', + '34' => 'Phone is in stop list', + '35' => 'Not enough money', + '36' => 'Can not obtain information about phone', + '37' => 'Base Id is not set', + '38' => 'Phone number is already exist in this base', + '39' => 'Phone number is not exist in this base', + ]; + + public function __construct( + string $login, + string $password, + string $phone, + HttpClientInterface $client = null, + EventDispatcherInterface $dispatcher = null + ) { + $this->login = $login; + $this->password = $password; + $this->phone = $phone; + + parent::__construct($client, $dispatcher); + } + + public function __toString(): string + { + return sprintf('lightsms://%s?phone=%s', $this->getEndpoint(), $this->phone); + } + + public function supports(MessageInterface $message): bool + { + return $message instanceof SmsMessage && $this->phone === str_replace('+', '', $message->getPhone()); + } + + protected function doSend(MessageInterface $message): void + { + if (!$message instanceof SmsMessage) { + throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, \get_class($message))); + } + + $this->message = $message; + + $signature = $this->getSignature(); + + $endpoint = sprintf( + 'https://%s?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', + $this->getEndpoint(), + $this->login, + $signature, + str_replace('+', '', $message->getPhone()), + $message->getSubject(), + $this->phone, + time() + ); + + + $response = $this->client->request('GET', $endpoint); + + $content = $response->toArray(false); + + if (isset($content['error'])) { + throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); + } + } + + private function getSignature(): string + { + + $params = [ + 'timestamp' => time(), + 'login' => $this->login, + 'phone' => str_replace('+', '', $this->message->getPhone()), + 'sender' => $this->phone, + 'text' => $this->message->getSubject(), + ]; + + ksort($params); + reset($params); + + return md5(implode($params) . $this->password); + } +} diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php new file mode 100644 index 0000000000000..e364b20c257a7 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\LightSms; + +use Symfony\Component\Notifier\Exception\UnsupportedSchemeException; +use Symfony\Component\Notifier\Transport\AbstractTransportFactory; +use Symfony\Component\Notifier\Transport\Dsn; +use Symfony\Component\Notifier\Transport\TransportInterface; + +/** + * @author Vasilij Duško + */ +final class LightSmsTransportFactory extends AbstractTransportFactory +{ + /** + * @return LightSmsTransport + */ + public function create(Dsn $dsn): TransportInterface + { + $scheme = $dsn->getScheme(); + + if ('lightsms' !== $scheme) { + throw new UnsupportedSchemeException($dsn, 'lightsms', $this->getSupportedSchemes()); + } + + $login = $this->getUser($dsn); + $token = $this->getPassword($dsn); + $phone = $dsn->getOption('phone'); + + $host = 'default' === $dsn->getHost() ? null : $dsn->getHost(); + $port = $dsn->getPort(); + + return (new LightSmsTransport($login, $token, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port); + } + + protected function getSupportedSchemes(): array + { + return ['lightsms']; + } +} diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md new file mode 100644 index 0000000000000..cea0c5d4ecf00 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -0,0 +1,28 @@ +LightSms Notifier +==================== + +Provides [LightSms](https://www.lightsms.com/) integration for Symfony Notifier. + +This provider allows you to receive an SMS notification on your mobile number. + +DSN example +----------- + +``` +LIGHTSMS_DSN=lightsms://LOGIN:TOKEN@default?phone=PHONE +``` + +where: + - `LOGIN` is your LightSms login + - `TOKEN` is the token displayed in your account + - `PHONE` is your LightSms phone number + +See your account info at https://www.lightsms.com/external/client/api/ + +Resources +--------- + + * [Contributing](https://symfony.com/doc/current/contributing/index.html) + * [Report issues](https://github.com/symfony/symfony/issues) and + [send Pull Requests](https://github.com/symfony/symfony/pulls) + in the [main Symfony repository](https://github.com/symfony/symfony) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json new file mode 100644 index 0000000000000..56575559c823a --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -0,0 +1,30 @@ +{ + "name": "symfony/lightsms-notifier", + "type": "symfony-bridge", + "description": "Symfony LightSms Notifier Bridge", + "keywords": ["sms", "LightSms", "notifier"], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Vasilij Duško", + "email": "vasilij@d4d.lt" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=7.2.5", + "symfony/http-client": "^4.3|^5.0", + "symfony/notifier": "~5.0.0" + }, + "autoload": { + "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LightSms\\": "" }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev" +} diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/phpunit.xml.dist b/src/Symfony/Component/Notifier/Bridge/LightSms/phpunit.xml.dist new file mode 100644 index 0000000000000..6eddaf643af25 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/phpunit.xml.dist @@ -0,0 +1,31 @@ + + + + + + + + + + ./Tests/ + + + + + + ./ + + ./Resources + ./Tests + ./vendor + + + + From f2ba226b46e4eff8db6ed6a1933f2a9c800d505b Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 12:41:47 +0300 Subject: [PATCH 02/62] * LightSmsTransport.php - bug fix --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index f49dafd6a234a..48c6796f0ca34 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -103,10 +103,10 @@ public function supports(MessageInterface $message): bool return $message instanceof SmsMessage && $this->phone === str_replace('+', '', $message->getPhone()); } - protected function doSend(MessageInterface $message): void + protected function doSend(MessageInterface $message): SentMessage { if (!$message instanceof SmsMessage) { - throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, \get_class($message))); + throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message); } $this->message = $message; From be8f994fca70d1930cad44a67dfab41549066d21 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 12:50:41 +0300 Subject: [PATCH 03/62] * LightSmsTransport.php - return type --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 48c6796f0ca34..821aa5cde03be 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -132,6 +132,18 @@ protected function doSend(MessageInterface $message): SentMessage if (isset($content['error'])) { throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); } + + + $phone = preg_replace("/[^\d]/", "", $message->getPhone()); + + if ($content[$phone]['error'] == 32) { + throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); + } + + if ($content[$phone]['error'] == 0) { + $sentMessage = new SentMessage($message, (string) $this); + $sentMessage->setMessageId($content[$phone]['id_sms']); + } } private function getSignature(): string From 167f325f404475f181ced5591875fca3613d901b Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 14:01:54 +0300 Subject: [PATCH 04/62] * LightSmsTransport.php - logic error --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 821aa5cde03be..519b6a7c113a7 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -100,7 +100,8 @@ public function __toString(): string public function supports(MessageInterface $message): bool { - return $message instanceof SmsMessage && $this->phone === str_replace('+', '', $message->getPhone()); + return $message instanceof SmsMessage; + } protected function doSend(MessageInterface $message): SentMessage From 6792535a52481f2600d08023749f085348af7f38 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 14:02:35 +0300 Subject: [PATCH 05/62] * composer.json - requirements bug fix --- src/Symfony/Component/Notifier/Bridge/LightSms/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json index 56575559c823a..e57f96130c244 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=7.2.5", "symfony/http-client": "^4.3|^5.0", - "symfony/notifier": "~5.0.0" + "symfony/notifier": "^5.3" }, "autoload": { "psr-4": { "Symfony\\Component\\Notifier\\Bridge\\LightSms\\": "" }, From 2f65b92cbae240313ffa7dc49ba01f74a1e03d9d Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 14:20:10 +0300 Subject: [PATCH 06/62] * LightSmsTransport.php - Coding Standard --- .../Bridge/LightSms/LightSmsTransport.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 519b6a7c113a7..54d8ab6743387 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -62,7 +62,7 @@ final class LightSmsTransport extends AbstractTransport '22' => 'Template already exists', '23' => 'Month not specifies (Format: YYYY-MM)', '24' => 'Timestamp not specified', - '25' =>'Error in access to the list', + '25' => 'Error in access to the list', '26' => 'There are no numbers in the list', '27' => 'No valid numbers', '28' => 'Date of start not specified (Format: YYYY-MM-DD)', @@ -101,7 +101,6 @@ public function __toString(): string public function supports(MessageInterface $message): bool { return $message instanceof SmsMessage; - } protected function doSend(MessageInterface $message): SentMessage @@ -125,7 +124,6 @@ protected function doSend(MessageInterface $message): SentMessage time() ); - $response = $this->client->request('GET', $endpoint); $content = $response->toArray(false); @@ -134,22 +132,21 @@ protected function doSend(MessageInterface $message): SentMessage throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); } - $phone = preg_replace("/[^\d]/", "", $message->getPhone()); - - if ($content[$phone]['error'] == 32) { + if (32 == $content[$phone]['error']) { throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); } - if ($content[$phone]['error'] == 0) { + if (0 == $content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); $sentMessage->setMessageId($content[$phone]['id_sms']); } + + return $sentMessage; } private function getSignature(): string { - $params = [ 'timestamp' => time(), 'login' => $this->login, @@ -161,6 +158,6 @@ private function getSignature(): string ksort($params); reset($params); - return md5(implode($params) . $this->password); + return md5(implode('', $params).$this->password); } } From 15686c085142b7ab602b3426beca9554957a8aa9 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 14:24:02 +0300 Subject: [PATCH 07/62] * LightSmsTransport.php - Coding Standard --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 54d8ab6743387..79a008328047f 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Notifier\Bridge\LightSms; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException; use Symfony\Component\Notifier\Message\MessageInterface; @@ -132,7 +131,7 @@ protected function doSend(MessageInterface $message): SentMessage throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); } - $phone = preg_replace("/[^\d]/", "", $message->getPhone()); + $phone = preg_replace("/[^\d]/", '', $message->getPhone()); if (32 == $content[$phone]['error']) { throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); } From a0fae7dc4ab2801723cbe16b6db387dd5920b492 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 14:56:09 +0300 Subject: [PATCH 08/62] * tests --- .../Tests/LightSmsTransportFactoryTest.php | 47 +++++++++++++++++++ .../LightSms/Tests/LightSmsTransportTest.php | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php new file mode 100644 index 0000000000000..c85b7706c4e90 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\LightSms\Tests; + +use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory; +use Symfony\Component\Notifier\Test\TransportFactoryTestCase; +use Symfony\Component\Notifier\Transport\TransportFactoryInterface; + +final class LightSmsTransportFactoryTest extends TransportFactoryTestCase +{ + /** + * @return LightSmsTransportFactory + */ + public function createFactory(): TransportFactoryInterface + { + return new LightSmsTransportFactory(); + } + + public function createProvider(): iterable + { + yield [ + 'lightsms://host.test?phone=0611223344', + 'lightsms://accountSid:authToken@host.test?phone=0611223344', + ]; + } + + public function supportsProvider(): iterable + { + yield [true, 'lightsms://login:token@default?phone=37061234567']; + yield [false, 'somethingElse://login:token@default?phone=37061234567']; + } + + public function unsupportedSchemeProvider(): iterable + { + yield ['somethingElse://accountSid:authToken@default?from=37061234567']; + yield ['somethingElse://accountSid:authToken@default']; // missing "phone" option + } +} diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php new file mode 100644 index 0000000000000..2082458d3364a --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Bridge\LightSms\Tests; + +use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransport; +use Symfony\Component\Notifier\Message\ChatMessage; +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\SmsMessage; +use Symfony\Component\Notifier\Test\TransportTestCase; +use Symfony\Component\Notifier\Transport\TransportInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; + +final class LightSmsTransportTest extends TransportTestCase +{ + /** + * @return LightSmsTransport + */ + public function createTransport(?HttpClientInterface $client = null): TransportInterface + { + return new LightSmsTransport('accountSid', 'authToken', 'from', $client ?: $this->createMock(HttpClientInterface::class)); + } + + public function toStringProvider(): iterable + { + yield ['lightsms://www.lightsms.com/external/get/send.php?phone=from', $this->createTransport()]; + } + + public function supportedMessagesProvider(): iterable + { + yield [new SmsMessage('0611223344', 'Hello!')]; + } + + public function unsupportedMessagesProvider(): iterable + { + yield [new ChatMessage('Hello!')]; + yield [$this->createMock(MessageInterface::class)]; + } +} From d1ccd46e75b91ff23d8178257d29ef015e520bf4 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:07:44 +0300 Subject: [PATCH 09/62] * Attached file changes which are required to run the lightsms notifier --- .../FrameworkBundle/Resources/config/notifier_transports.php | 5 +++++ .../Notifier/Exception/UnsupportedSchemeException.php | 4 ++++ src/Symfony/Component/Notifier/Transport.php | 1 + 3 files changed, 10 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php index 23a9a47936df5..bc079cae10121 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php @@ -40,6 +40,7 @@ use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory; use Symfony\Component\Notifier\Transport\AbstractTransportFactory; use Symfony\Component\Notifier\Transport\NullTransportFactory; +use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory; return static function (ContainerConfigurator $container) { $container->services() @@ -159,5 +160,9 @@ ->parent('notifier.transport_factory.abstract') ->tag('chatter.transport_factory') ->tag('texter.transport_factory') + + ->set('notifier.transport_factory.lightsms', LightSmsTransportFactory::class) + ->parent('notifier.transport_factory.abstract') + ->tag('texter.transport_factory') ; }; diff --git a/src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php b/src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php index 06bb494d5f86c..3a28762bdda49 100644 --- a/src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php +++ b/src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php @@ -116,6 +116,10 @@ class UnsupportedSchemeException extends LogicException 'class' => Bridge\Clickatell\ClickatellTransportFactory::class, 'package' => 'symfony/clickatell-notifier', ], + 'lightsms' => [ + 'class' => Bridge\LightSms\LightSmsTransportFactory::class, + 'package' => 'symfony/lightsms-notifier', + ], ]; /** diff --git a/src/Symfony/Component/Notifier/Transport.php b/src/Symfony/Component/Notifier/Transport.php index b2430bbe9ac2d..72c7a8f8fe3d8 100644 --- a/src/Symfony/Component/Notifier/Transport.php +++ b/src/Symfony/Component/Notifier/Transport.php @@ -74,6 +74,7 @@ class Transport OctopushTransportFactory::class, GitterTransportFactory::class, ClickatellTransportFactory::class, + LightSmsTransportFactory::class, ]; private $factories; From ce41756a6c7a51e84fd2fe2406ead11f579c53d6 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:16:11 +0300 Subject: [PATCH 10/62] * notifier_transports.php - Coding Standard --- .../FrameworkBundle/Resources/config/notifier_transports.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php index bc079cae10121..724899d84c1ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php @@ -22,6 +22,7 @@ use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory; use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory; use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory; +use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory; use Symfony\Component\Notifier\Bridge\LinkedIn\LinkedInTransportFactory; use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory; use Symfony\Component\Notifier\Bridge\Mercure\MercureTransportFactory; @@ -40,7 +41,6 @@ use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory; use Symfony\Component\Notifier\Transport\AbstractTransportFactory; use Symfony\Component\Notifier\Transport\NullTransportFactory; -use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory; return static function (ContainerConfigurator $container) { $container->services() From 728a3e2450baa05a98d246b7f8ba5d128e6dde41 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:23:33 +0300 Subject: [PATCH 11/62] * Transport.php - missing use --- src/Symfony/Component/Notifier/Transport.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Notifier/Transport.php b/src/Symfony/Component/Notifier/Transport.php index 72c7a8f8fe3d8..76feae13a1b41 100644 --- a/src/Symfony/Component/Notifier/Transport.php +++ b/src/Symfony/Component/Notifier/Transport.php @@ -21,6 +21,7 @@ use Symfony\Component\Notifier\Bridge\Gitter\GitterTransportFactory; use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory; use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory; +use Symfony\Component\Notifier\Bridge\LightSms\LightSmsTransportFactory; use Symfony\Component\Notifier\Bridge\Mattermost\MattermostTransportFactory; use Symfony\Component\Notifier\Bridge\Mobyt\MobytTransportFactory; use Symfony\Component\Notifier\Bridge\Nexmo\NexmoTransportFactory; From 4a11b945a3958b184394edd8a7e870113cd018d2 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:45:24 +0300 Subject: [PATCH 12/62] * github account author --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- .../Notifier/Bridge/LightSms/LightSmsTransportFactory.php | 2 +- src/Symfony/Component/Notifier/Bridge/LightSms/composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 79a008328047f..4e92fefd35e23 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -21,7 +21,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; /** - * @author Vasilij Duško + * @author Vasilij Duško */ final class LightSmsTransport extends AbstractTransport { diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php index e364b20c257a7..2b2be663804ab 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php @@ -17,7 +17,7 @@ use Symfony\Component\Notifier\Transport\TransportInterface; /** - * @author Vasilij Duško + * @author Vasilij Duško */ final class LightSmsTransportFactory extends AbstractTransportFactory { diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json index e57f96130c244..2cf3bf9d1289b 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -8,7 +8,7 @@ "authors": [ { "name": "Vasilij Duško", - "email": "vasilij@d4d.lt" + "email": "vasilij@prado.lt" }, { "name": "Symfony Community", From febff4613d5ecd1f29c4c5e711dbb54bdbf998b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 15:44:50 +0300 Subject: [PATCH 13/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE Co-authored-by: Oskar Stark --- src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE b/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE index ad85e1737485d..efb17f98e7dd3 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2020-2021 Fabien Potencier +Copyright (c) 2021 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 9e1809e6ae4dd6ea5fa16b846612bd8a780ace34 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:49:43 +0300 Subject: [PATCH 14/62] * small changes --- .../FrameworkBundle/Resources/config/notifier_transports.php | 4 ++-- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- .../Notifier/Bridge/LightSms/LightSmsTransportFactory.php | 2 +- src/Symfony/Component/Notifier/Bridge/LightSms/composer.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php index 724899d84c1ce..93a441bf0d27e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php @@ -162,7 +162,7 @@ ->tag('texter.transport_factory') ->set('notifier.transport_factory.lightsms', LightSmsTransportFactory::class) - ->parent('notifier.transport_factory.abstract') - ->tag('texter.transport_factory') + ->parent('notifier.transport_factory.abstract') + ->tag('texter.transport_factory') ; }; diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 4e92fefd35e23..94d67448e6938 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -110,7 +110,7 @@ protected function doSend(MessageInterface $message): SentMessage $this->message = $message; - $signature = $this->getSignature(); + $signature = $this->generateSignature(); $endpoint = sprintf( 'https://%s?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', @@ -144,7 +144,7 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - private function getSignature(): string + private function generateSignature(): string { $params = [ 'timestamp' => time(), diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php index 2b2be663804ab..3aa40b8e39ac9 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php @@ -34,7 +34,7 @@ public function create(Dsn $dsn): TransportInterface $login = $this->getUser($dsn); $token = $this->getPassword($dsn); - $phone = $dsn->getOption('phone'); + $phone = $dsn->getRequiredOption('phone'); $host = 'default' === $dsn->getHost() ? null : $dsn->getHost(); $port = $dsn->getPort(); diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json index 2cf3bf9d1289b..b28e5ae58d0bb 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -2,7 +2,7 @@ "name": "symfony/lightsms-notifier", "type": "symfony-bridge", "description": "Symfony LightSms Notifier Bridge", - "keywords": ["sms", "LightSms", "notifier"], + "keywords": ["sms", "light-sms", "notifier"], "homepage": "https://symfony.com", "license": "MIT", "authors": [ From 3cbbc85e439ad5cdbea32a39078ac289771debcf Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 15:58:51 +0300 Subject: [PATCH 15/62] * HOST split into two parts --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 13 ++++--------- .../Component/Notifier/Bridge/LightSms/README.md | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 94d67448e6938..5d6a6f1b06325 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -25,7 +25,7 @@ */ final class LightSmsTransport extends AbstractTransport { - protected const HOST = 'www.lightsms.com/external/get/send.php'; + protected const HOST = 'www.lightsms.com'; private $login; private $password; @@ -78,13 +78,8 @@ final class LightSmsTransport extends AbstractTransport '39' => 'Phone number is not exist in this base', ]; - public function __construct( - string $login, - string $password, - string $phone, - HttpClientInterface $client = null, - EventDispatcherInterface $dispatcher = null - ) { + public function __construct(string $login, string $password, string $phone, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) + { $this->login = $login; $this->password = $password; $this->phone = $phone; @@ -113,7 +108,7 @@ protected function doSend(MessageInterface $message): SentMessage $signature = $this->generateSignature(); $endpoint = sprintf( - 'https://%s?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', + 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', $this->getEndpoint(), $this->login, $signature, diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index cea0c5d4ecf00..98c301ec8348d 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -1,5 +1,5 @@ LightSms Notifier -==================== +=============== Provides [LightSms](https://www.lightsms.com/) integration for Symfony Notifier. From 5e54dfe475cc62a80a7c0d6ec601c4f03c869128 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 28 Mar 2021 16:08:08 +0300 Subject: [PATCH 16/62] * LightSmsTransport.php - quick fix for private constant. --- .../Bridge/LightSms/LightSmsTransport.php | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 5d6a6f1b06325..ae8df10a48335 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -30,12 +30,8 @@ final class LightSmsTransport extends AbstractTransport private $login; private $password; private $phone; - /** - * @var MessageInterface - */ - private $message; - private $errorCodes = [ + private const ERROR_CODES = [ '000' => 'Service unavailable', '1' => 'Signature not specified', '2' => 'Login not specified', @@ -103,9 +99,7 @@ protected function doSend(MessageInterface $message): SentMessage throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message); } - $this->message = $message; - - $signature = $this->generateSignature(); + $signature = $this->generateSignature($message); $endpoint = sprintf( 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', @@ -123,12 +117,12 @@ protected function doSend(MessageInterface $message): SentMessage $content = $response->toArray(false); if (isset($content['error'])) { - throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); + throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } $phone = preg_replace("/[^\d]/", '', $message->getPhone()); if (32 == $content[$phone]['error']) { - throw new TransportException('Unable to send the SMS: '.$this->errorCodes[$content['error']], $response); + throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } if (0 == $content[$phone]['error']) { @@ -139,14 +133,14 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - private function generateSignature(): string + private function generateSignature(SmsMessage $message): string { $params = [ 'timestamp' => time(), 'login' => $this->login, - 'phone' => str_replace('+', '', $this->message->getPhone()), + 'phone' => str_replace('+', '', $message->getPhone()), 'sender' => $this->phone, - 'text' => $this->message->getSubject(), + 'text' => $message->getSubject(), ]; ksort($params); From 9f89014d9492058e6b41757da4232a9812dc0f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:56:35 +0300 Subject: [PATCH 17/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/README.md Co-authored-by: Oskar Stark --- src/Symfony/Component/Notifier/Bridge/LightSms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index 98c301ec8348d..6fe45133171a5 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -1,5 +1,5 @@ LightSms Notifier -=============== +================= Provides [LightSms](https://www.lightsms.com/) integration for Symfony Notifier. From c02dbbd9639f4787b696cb2cd487531b5ee2018c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:56:59 +0300 Subject: [PATCH 18/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/README.md Co-authored-by: Oskar Stark --- src/Symfony/Component/Notifier/Bridge/LightSms/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index 6fe45133171a5..de77e8c8152c4 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -15,7 +15,7 @@ LIGHTSMS_DSN=lightsms://LOGIN:TOKEN@default?phone=PHONE where: - `LOGIN` is your LightSms login - `TOKEN` is the token displayed in your account - - `PHONE` is your LightSms phone number + - `PHONE` is your LightSms sender phone number See your account info at https://www.lightsms.com/external/client/api/ From b2e46387b72a8b653745538746a44c0ae58f36b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:57:18 +0300 Subject: [PATCH 19/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index ae8df10a48335..95f89969e5bb7 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -70,7 +70,7 @@ final class LightSmsTransport extends AbstractTransport '35' => 'Not enough money', '36' => 'Can not obtain information about phone', '37' => 'Base Id is not set', - '38' => 'Phone number is already exist in this base', + '38' => 'Phone number already exists in this database', '39' => 'Phone number is not exist in this base', ]; From 49b4780f4062ab686084ad79410555197ea1d102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:57:39 +0300 Subject: [PATCH 20/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 95f89969e5bb7..15e9278cf4bcb 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -65,7 +65,7 @@ final class LightSmsTransport extends AbstractTransport '30' => 'No date (format: YYYY-MM-DD)', '31' => 'Closing direction to the user', '32' => 'Not enough money', - '33' => 'Phone number is not set', + '33' => 'Missing phone number', '34' => 'Phone is in stop list', '35' => 'Not enough money', '36' => 'Can not obtain information about phone', From b0891be0b2ef116803754f95abd078c46bb6d504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:58:21 +0300 Subject: [PATCH 21/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 15e9278cf4bcb..20bbe01bc26fb 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -33,7 +33,7 @@ final class LightSmsTransport extends AbstractTransport private const ERROR_CODES = [ '000' => 'Service unavailable', - '1' => 'Signature not specified', + '1' => 'Missing Signature', '2' => 'Login not specified', '3' => 'Text not specified', '4' => 'Phone number not specified', From 1b073c236620cfbfd0f28c707c047085e6d2bbfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:58:50 +0300 Subject: [PATCH 22/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 20bbe01bc26fb..956686a69583e 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -61,7 +61,7 @@ final class LightSmsTransport extends AbstractTransport '26' => 'There are no numbers in the list', '27' => 'No valid numbers', '28' => 'Date of start not specified (Format: YYYY-MM-DD)', - '29' => 'Date of end not specified (Format: YYYY-MM-DD)', + '29' => 'Missing end date (Format: YYYY-MM-DD)', '30' => 'No date (format: YYYY-MM-DD)', '31' => 'Closing direction to the user', '32' => 'Not enough money', From e0a68bd0aca00941d42f376bdcd209600388b1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:59:08 +0300 Subject: [PATCH 23/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 956686a69583e..58c66c11c11e9 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -60,7 +60,7 @@ final class LightSmsTransport extends AbstractTransport '25' => 'Error in access to the list', '26' => 'There are no numbers in the list', '27' => 'No valid numbers', - '28' => 'Date of start not specified (Format: YYYY-MM-DD)', + '28' => 'Missing start date (Format: YYYY-MM-DD)', '29' => 'Missing end date (Format: YYYY-MM-DD)', '30' => 'No date (format: YYYY-MM-DD)', '31' => 'Closing direction to the user', From 3d0d79cfe261439b6e567985642d23f73dbf4a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:59:27 +0300 Subject: [PATCH 24/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php Co-authored-by: Oskar Stark --- .../Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index c85b7706c4e90..d0904489a59bd 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -41,7 +41,7 @@ public function supportsProvider(): iterable public function unsupportedSchemeProvider(): iterable { - yield ['somethingElse://accountSid:authToken@default?from=37061234567']; + yield ['somethingElse://accountSid:authToken@default?phone=37061234567']; yield ['somethingElse://accountSid:authToken@default']; // missing "phone" option } } From 0e41bc9186cc08d4b675c954f72c8a962d6dc61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:59:37 +0300 Subject: [PATCH 25/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php Co-authored-by: Oskar Stark --- .../Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index d0904489a59bd..fe76d7a589bbb 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -29,7 +29,7 @@ public function createProvider(): iterable { yield [ 'lightsms://host.test?phone=0611223344', - 'lightsms://accountSid:authToken@host.test?phone=0611223344', + 'lightsms://login:token@host.test?phone=0611223344', ]; } From 079406ed3d1587cd12aaaea3ab15fa4b4bdcab0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 19:59:53 +0300 Subject: [PATCH 26/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 58c66c11c11e9..397ac9184735f 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -71,7 +71,7 @@ final class LightSmsTransport extends AbstractTransport '36' => 'Can not obtain information about phone', '37' => 'Base Id is not set', '38' => 'Phone number already exists in this database', - '39' => 'Phone number is not exist in this base', + '39' => 'Phone number does not exist in this database', ]; public function __construct(string $login, string $password, string $phone, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) From 7b51e0dd7ff6cae79e9c88d10cd90689365203de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 20:00:10 +0300 Subject: [PATCH 27/62] Update src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php Co-authored-by: Thibault RICHARD --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 397ac9184735f..520948d7ea907 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -55,7 +55,7 @@ final class LightSmsTransport extends AbstractTransport '20' => 'The number already exists', '21' => 'No name', '22' => 'Template already exists', - '23' => 'Month not specifies (Format: YYYY-MM)', + '23' => 'Missing Month (Format: YYYY-MM)', '24' => 'Timestamp not specified', '25' => 'Error in access to the list', '26' => 'There are no numbers in the list', From 2e0e1d733d2d24011e661a1b38acfe0a44a9294a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 20:03:58 +0300 Subject: [PATCH 28/62] Update README.md --- src/Symfony/Component/Notifier/Bridge/LightSms/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index de77e8c8152c4..df6975f2469c1 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -1,10 +1,6 @@ LightSms Notifier ================= -Provides [LightSms](https://www.lightsms.com/) integration for Symfony Notifier. - -This provider allows you to receive an SMS notification on your mobile number. - DSN example ----------- From 66c34baf03ecf5ab6a8dcf8c1a510de01c4fbf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Sun, 28 Mar 2021 21:00:49 +0300 Subject: [PATCH 29/62] Update README.md --- src/Symfony/Component/Notifier/Bridge/LightSms/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index df6975f2469c1..29ddb0d86a6ac 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -1,6 +1,8 @@ LightSms Notifier ================= +Provides [LightSms](https://www.lightsms.com/) integration for Symfony Notifier. + DSN example ----------- From 8620e828a7dd9b438851c1fcd2668c24d2ff7e2b Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 13:14:06 +0300 Subject: [PATCH 30/62] * LightSmsTransport.php - move timestamp --- .../Bridge/LightSms/LightSmsTransport.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 520948d7ea907..61f4c8c9c1454 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -99,7 +99,10 @@ protected function doSend(MessageInterface $message): SentMessage throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message); } - $signature = $this->generateSignature($message); + $signature = $this->generateSignature([ + 'message' => $message, + 'timestamp' => time(), + ]); $endpoint = sprintf( 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', @@ -121,7 +124,7 @@ protected function doSend(MessageInterface $message): SentMessage } $phone = preg_replace("/[^\d]/", '', $message->getPhone()); - if (32 == $content[$phone]['error']) { + if (32 === $content[$phone]['error']) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } @@ -133,14 +136,14 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - private function generateSignature(SmsMessage $message): string + private function generateSignature(array $params): string { $params = [ - 'timestamp' => time(), + 'timestamp' => $params['timestamp'], 'login' => $this->login, - 'phone' => str_replace('+', '', $message->getPhone()), + 'phone' => str_replace('+', '', $params['message']->getPhone()), 'sender' => $this->phone, - 'text' => $message->getSubject(), + 'text' => $params['message']->getSubject(), ]; ksort($params); From 5d2e6928f33c2f79faa96c988877c02833633062 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 13:29:53 +0300 Subject: [PATCH 31/62] * LightSmsTransport.php - escape phone number --- .../Bridge/LightSms/LightSmsTransport.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 61f4c8c9c1454..e6fa7f946e806 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -109,8 +109,8 @@ protected function doSend(MessageInterface $message): SentMessage $this->getEndpoint(), $this->login, $signature, - str_replace('+', '', $message->getPhone()), - $message->getSubject(), + $this->escapePhoneNumber($message->getPhone()), + $this->escapeSubject($message->getSubject()), $this->phone, time() ); @@ -141,9 +141,9 @@ private function generateSignature(array $params): string $params = [ 'timestamp' => $params['timestamp'], 'login' => $this->login, - 'phone' => str_replace('+', '', $params['message']->getPhone()), + 'phone' => $this->escapePhoneNumber($params['message']->getPhone()), 'sender' => $this->phone, - 'text' => $params['message']->getSubject(), + 'text' => $this->escapeSubject($params['message']->getSubject()), ]; ksort($params); @@ -151,4 +151,14 @@ private function generateSignature(array $params): string return md5(implode('', $params).$this->password); } + + private function escapeSubject($subject): string + { + return strip_tags($subject); + } + + private function escapePhoneNumber($phoneNumber): string + { + return str_replace('+', '', $phoneNumber); + } } From fc13bb27e2affac733306f4e0c6a3ed905d92ae1 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 13:34:15 +0300 Subject: [PATCH 32/62] * LightSmsTransport.php - changed login for validation (the same like we have all places) --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index e6fa7f946e806..a5b51c93f54e5 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -123,7 +123,7 @@ protected function doSend(MessageInterface $message): SentMessage throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } - $phone = preg_replace("/[^\d]/", '', $message->getPhone()); + $phone = $this->escapePhoneNumber($message->getPhone()); if (32 === $content[$phone]['error']) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } @@ -159,6 +159,6 @@ private function escapeSubject($subject): string private function escapePhoneNumber($phoneNumber): string { - return str_replace('+', '', $phoneNumber); + return preg_replace("/[^\d]/", '', $phoneNumber); } } From b0e64b92500b56965636d378a22fbbcd69828c74 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 13:51:17 +0300 Subject: [PATCH 33/62] * LightSmsTransport.php - not ok throw exception --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index a5b51c93f54e5..105efee5340b8 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Notifier\Bridge\LightSms; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException; use Symfony\Component\Notifier\Message\MessageInterface; @@ -99,9 +100,11 @@ protected function doSend(MessageInterface $message): SentMessage throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message); } + $timestamp = time(); + $signature = $this->generateSignature([ 'message' => $message, - 'timestamp' => time(), + 'timestamp' => $timestamp, ]); $endpoint = sprintf( @@ -112,11 +115,15 @@ protected function doSend(MessageInterface $message): SentMessage $this->escapePhoneNumber($message->getPhone()), $this->escapeSubject($message->getSubject()), $this->phone, - time() + $timestamp ); $response = $this->client->request('GET', $endpoint); + if (Response::HTTP_OK !== $response->getStatusCode()) { + throw new TransportException('Unable to send the SMS: ', $response); + } + $content = $response->toArray(false); if (isset($content['error'])) { From e20ef1ed35ab412eb4922981e50ba61fb06c21eb Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 14:16:34 +0300 Subject: [PATCH 34/62] * LightSmsTransport.php - change + to 00 --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 105efee5340b8..ca1438abde1c1 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -166,6 +166,6 @@ private function escapeSubject($subject): string private function escapePhoneNumber($phoneNumber): string { - return preg_replace("/[^\d]/", '', $phoneNumber); + return str_replace('+', '00', $phoneNumber); } } From 7f13dbf71164fd40a14c0a3a8270bc5b2b67debb Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 17:49:52 +0300 Subject: [PATCH 35/62] * sender changed to from --- .../Bridge/LightSms/LightSmsTransport.php | 25 ++++++++----------- .../LightSms/LightSmsTransportFactory.php | 4 +-- .../Tests/LightSmsTransportFactoryTest.php | 4 +-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index ca1438abde1c1..fa5b9df403755 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -26,7 +26,7 @@ */ final class LightSmsTransport extends AbstractTransport { - protected const HOST = 'www.lightsms.com'; + protected const HOST = 'lightsms.com'; private $login; private $password; @@ -75,11 +75,11 @@ final class LightSmsTransport extends AbstractTransport '39' => 'Phone number does not exist in this database', ]; - public function __construct(string $login, string $password, string $phone, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) + public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) { $this->login = $login; $this->password = $password; - $this->phone = $phone; + $this->from = $from; parent::__construct($client, $dispatcher); } @@ -102,19 +102,16 @@ protected function doSend(MessageInterface $message): SentMessage $timestamp = time(); - $signature = $this->generateSignature([ - 'message' => $message, - 'timestamp' => $timestamp, - ]); + $signature = $this->generateSignature($message, $timestamp); $endpoint = sprintf( - 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', + 'https://www.%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', $this->getEndpoint(), $this->login, $signature, $this->escapePhoneNumber($message->getPhone()), $this->escapeSubject($message->getSubject()), - $this->phone, + $this->from, $timestamp ); @@ -143,14 +140,14 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - private function generateSignature(array $params): string + private function generateSignature(SmsMessage $message, string $timestamp): string { $params = [ - 'timestamp' => $params['timestamp'], + 'timestamp' => $timestamp, 'login' => $this->login, - 'phone' => $this->escapePhoneNumber($params['message']->getPhone()), - 'sender' => $this->phone, - 'text' => $this->escapeSubject($params['message']->getSubject()), + 'phone' => $this->escapePhoneNumber($message->getPhone()), + 'sender' => $this->from, + 'text' => $this->escapeSubject($message->getSubject()), ]; ksort($params); diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php index 3aa40b8e39ac9..9a7d172ca8aab 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransportFactory.php @@ -34,12 +34,12 @@ public function create(Dsn $dsn): TransportInterface $login = $this->getUser($dsn); $token = $this->getPassword($dsn); - $phone = $dsn->getRequiredOption('phone'); + $from = $dsn->getRequiredOption('from'); $host = 'default' === $dsn->getHost() ? null : $dsn->getHost(); $port = $dsn->getPort(); - return (new LightSmsTransport($login, $token, $phone, $this->client, $this->dispatcher))->setHost($host)->setPort($port); + return (new LightSmsTransport($login, $token, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port); } protected function getSupportedSchemes(): array diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index fe76d7a589bbb..46eb3240ab4f8 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -41,7 +41,7 @@ public function supportsProvider(): iterable public function unsupportedSchemeProvider(): iterable { - yield ['somethingElse://accountSid:authToken@default?phone=37061234567']; - yield ['somethingElse://accountSid:authToken@default']; // missing "phone" option + yield ['somethingElse://login:token@default?phone=37061234567']; + yield ['somethingElse://login:token@default']; // missing "phone" option } } From f16b4d2aa2e636bbc60449a37585f42027462db5 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Mon, 29 Mar 2021 17:52:20 +0300 Subject: [PATCH 36/62] * phone changed to from --- .../Component/Notifier/Bridge/LightSms/README.md | 2 +- .../LightSms/Tests/LightSmsTransportFactoryTest.php | 12 ++++++------ .../Bridge/LightSms/Tests/LightSmsTransportTest.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md index 29ddb0d86a6ac..0414e5e1018b9 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/README.md +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/README.md @@ -7,7 +7,7 @@ DSN example ----------- ``` -LIGHTSMS_DSN=lightsms://LOGIN:TOKEN@default?phone=PHONE +LIGHTSMS_DSN=lightsms://LOGIN:TOKEN@default?from=PHONE ``` where: diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index 46eb3240ab4f8..01b206882f549 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -28,20 +28,20 @@ public function createFactory(): TransportFactoryInterface public function createProvider(): iterable { yield [ - 'lightsms://host.test?phone=0611223344', - 'lightsms://login:token@host.test?phone=0611223344', + 'lightsms://host.test?from=0611223344', + 'lightsms://login:token@host.test?from=0611223344', ]; } public function supportsProvider(): iterable { - yield [true, 'lightsms://login:token@default?phone=37061234567']; - yield [false, 'somethingElse://login:token@default?phone=37061234567']; + yield [true, 'lightsms://login:token@default?from=37061234567']; + yield [false, 'somethingElse://login:token@default?from=37061234567']; } public function unsupportedSchemeProvider(): iterable { - yield ['somethingElse://login:token@default?phone=37061234567']; - yield ['somethingElse://login:token@default']; // missing "phone" option + yield ['somethingElse://login:token@default?from=37061234567']; + yield ['somethingElse://login:token@default']; // missing "from" option } } diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php index 2082458d3364a..c11d22b862daf 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php @@ -31,7 +31,7 @@ public function createTransport(?HttpClientInterface $client = null): TransportI public function toStringProvider(): iterable { - yield ['lightsms://www.lightsms.com/external/get/send.php?phone=from', $this->createTransport()]; + yield ['lightsms://www.lightsms.com/external/get/send.php?from=from', $this->createTransport()]; } public function supportedMessagesProvider(): iterable From 7180c1f40053b0f298f8420842e410db0cff0533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Mon, 29 Mar 2021 19:26:20 +0300 Subject: [PATCH 37/62] Update LightSmsTransport.php --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index fa5b9df403755..0cc6262585507 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -30,7 +30,7 @@ final class LightSmsTransport extends AbstractTransport private $login; private $password; - private $phone; + private $from; private const ERROR_CODES = [ '000' => 'Service unavailable', From 08b0729751c9853128cf97b4677ee45c45254ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Mon, 29 Mar 2021 19:37:44 +0300 Subject: [PATCH 38/62] Update LightSmsTransport.php --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 0cc6262585507..130616134c934 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://%s?phone=%s', $this->getEndpoint(), $this->phone); + return sprintf('lightsms://%s?phone=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool From 80ef5ba56534917de1efbc1658667ba86f2b79b2 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 08:07:02 +0300 Subject: [PATCH 39/62] * LightSmsTransport.php - Unable to send the SMS: Closing direction to the user --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 130616134c934..7591d134ee207 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -123,7 +123,11 @@ protected function doSend(MessageInterface $message): SentMessage $content = $response->toArray(false); - if (isset($content['error'])) { + if (isset($content[''])) { + throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); + } + + if (isset($content['error']) || isset($content[''])) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } From 08235e5a3cb59f06d4bc81e35ce9892dc300e1cc Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 08:09:56 +0300 Subject: [PATCH 40/62] * LightSmsTransport.php - bug fix --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 7591d134ee207..9f3777bbf3440 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -127,7 +127,7 @@ protected function doSend(MessageInterface $message): SentMessage throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); } - if (isset($content['error']) || isset($content[''])) { + if (isset($content['error'])) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); } From 23a446a2e1da6ab18a9c6fbeb6ba3f6ebe84b5eb Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 09:14:59 +0300 Subject: [PATCH 41/62] * LightSmsTransport.php - issue with Symfony\Component\Notifier\Bridge\LightSms\Tests\LightSmsTransportTest --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 9f3777bbf3440..1432ab42ea359 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://%s?phone=%s', $this->getEndpoint(), $this->from); + return sprintf('lightsms://www.%sexternal/get/send.php?phone=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool From 265f776394eeb48761ac27ddfb74a610b77d6d04 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 09:15:57 +0300 Subject: [PATCH 42/62] * LightSmsTransport.php - issue with Symfony\Component\Notifier\Bridge\LightSms\Tests\LightSmsTransportTest --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 1432ab42ea359..cfb33a4baf206 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://www.%sexternal/get/send.php?phone=%s', $this->getEndpoint(), $this->from); + return sprintf('lightsms://www.%s/external/get/send.php?phone=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool From b9f9ff8c9485c8a7d4d66e6bbf958f9f553ce521 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 09:17:45 +0300 Subject: [PATCH 43/62] * LightSmsTransport.php - tests fail --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- .../Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index cfb33a4baf206..1619edd52c1d3 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://www.%s/external/get/send.php?phone=%s', $this->getEndpoint(), $this->from); + return sprintf('lightsms://www.%s/external/get/send.php?from=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index 01b206882f549..10ebfe1921e0f 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -28,7 +28,7 @@ public function createFactory(): TransportFactoryInterface public function createProvider(): iterable { yield [ - 'lightsms://host.test?from=0611223344', + 'lightsms://www.host.test/external/get/send.php?from=0611223344', 'lightsms://login:token@host.test?from=0611223344', ]; } From 58ac708d0fc8aafde1eaaa542038187dd4ac9dec Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 30 Mar 2021 13:18:00 +0300 Subject: [PATCH 44/62] * LightSmsTransport.php - return back www (without will not work). Now fail tests --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- .../Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 1619edd52c1d3..8bce170be8877 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -26,7 +26,7 @@ */ final class LightSmsTransport extends AbstractTransport { - protected const HOST = 'lightsms.com'; + protected const HOST = 'www.lightsms.com'; private $login; private $password; @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://www.%s/external/get/send.php?from=%s', $this->getEndpoint(), $this->from); + return sprintf('lightsms://%s/external/get/send.php?from=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index 10ebfe1921e0f..8306c6bdb0011 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -28,7 +28,7 @@ public function createFactory(): TransportFactoryInterface public function createProvider(): iterable { yield [ - 'lightsms://www.host.test/external/get/send.php?from=0611223344', + 'lightsms://host.test/external/get/send.php?from=0611223344', 'lightsms://login:token@host.test?from=0611223344', ]; } From 1b59a7d47e19355e031704b12c0ac517e9c3469f Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Thu, 1 Apr 2021 08:41:55 +0300 Subject: [PATCH 45/62] * LightSmsTransport.php - string param --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 8bce170be8877..0616b4b1f98d7 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -160,12 +160,12 @@ private function generateSignature(SmsMessage $message, string $timestamp): stri return md5(implode('', $params).$this->password); } - private function escapeSubject($subject): string + private function escapeSubject(string $subject): string { return strip_tags($subject); } - private function escapePhoneNumber($phoneNumber): string + private function escapePhoneNumber(string $phoneNumber): string { return str_replace('+', '00', $phoneNumber); } From 1c993b7224b24f1d5a3aec1201015e3c3d7208e3 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Thu, 1 Apr 2021 13:12:34 +0300 Subject: [PATCH 46/62] * ERROR_CODES -> int * www. - bug * isset validate ['error'] --- .../Bridge/LightSms/LightSmsTransport.php | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 0616b4b1f98d7..f6d56c13bf455 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -33,46 +33,46 @@ final class LightSmsTransport extends AbstractTransport private $from; private const ERROR_CODES = [ - '000' => 'Service unavailable', - '1' => 'Missing Signature', - '2' => 'Login not specified', - '3' => 'Text not specified', - '4' => 'Phone number not specified', - '5' => 'Sender not specified', - '6' => 'Invalid signature', - '7' => 'Invalid login', - '8' => 'Invalid sender name', - '9' => 'Sender name not registered', - '10' => 'Sender name not approved', - '11' => 'There are forbidden words in the text', - '12' => 'Error in SMS sending', - '13' => 'Phone number is in the blackist. SMS sending to this number is forbidden.', - '14' => 'There are more than 50 numbers in the request', - '15' => 'List not specified', - '16' => 'Invalid phone number', - '17' => 'SMS ID not specified', - '18' => 'Status not obtained', - '19' => 'Empty response', - '20' => 'The number already exists', - '21' => 'No name', - '22' => 'Template already exists', - '23' => 'Missing Month (Format: YYYY-MM)', - '24' => 'Timestamp not specified', - '25' => 'Error in access to the list', - '26' => 'There are no numbers in the list', - '27' => 'No valid numbers', - '28' => 'Missing start date (Format: YYYY-MM-DD)', - '29' => 'Missing end date (Format: YYYY-MM-DD)', - '30' => 'No date (format: YYYY-MM-DD)', - '31' => 'Closing direction to the user', - '32' => 'Not enough money', - '33' => 'Missing phone number', - '34' => 'Phone is in stop list', - '35' => 'Not enough money', - '36' => 'Can not obtain information about phone', - '37' => 'Base Id is not set', - '38' => 'Phone number already exists in this database', - '39' => 'Phone number does not exist in this database', + 000 => 'Service unavailable', + 1 => 'Missing Signature', + 2 => 'Login not specified', + 3 => 'Text not specified', + 4 => 'Phone number not specified', + 5 => 'Sender not specified', + 6 => 'Invalid signature', + 7 => 'Invalid login', + 8 => 'Invalid sender name', + 9 => 'Sender name not registered', + 10 => 'Sender name not approved', + 11 => 'There are forbidden words in the text', + 12 => 'Error in SMS sending', + 13 => 'Phone number is in the blackist. SMS sending to this number is forbidden.', + 14 => 'There are more than 50 numbers in the request', + 15 => 'List not specified', + 16 => 'Invalid phone number', + 17 => 'SMS ID not specified', + 18 => 'Status not obtained', + 19 => 'Empty response', + 20 => 'The number already exists', + 21 => 'No name', + 22 => 'Template already exists', + 23 => 'Missing Month (Format: YYYY-MM)', + 24 => 'Timestamp not specified', + 25 => 'Error in access to the list', + 26 => 'There are no numbers in the list', + 27 => 'No valid numbers', + 28 => 'Missing start date (Format: YYYY-MM-DD)', + 29 => 'Missing end date (Format: YYYY-MM-DD)', + 30 => 'No date (format: YYYY-MM-DD)', + 31 => 'Closing direction to the user', + 32 => 'Not enough money', + 33 => 'Missing phone number', + 34 => 'Phone is in stop list', + 35 => 'Not enough money', + 36 => 'Can not obtain information about phone', + 37 => 'Base Id is not set', + 38 => 'Phone number already exists in this database', + 39 => 'Phone number does not exist in this database', ]; public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) @@ -105,7 +105,7 @@ protected function doSend(MessageInterface $message): SentMessage $signature = $this->generateSignature($message, $timestamp); $endpoint = sprintf( - 'https://www.%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', + 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', $this->getEndpoint(), $this->login, $signature, @@ -123,7 +123,8 @@ protected function doSend(MessageInterface $message): SentMessage $content = $response->toArray(false); - if (isset($content[''])) { + // it happens if the host without www + if (isset($content['']) && isset($content['']['error'])) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); } From 1ff97e410a9346de346ede271ca5ee4ab1095b70 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Thu, 1 Apr 2021 13:33:34 +0300 Subject: [PATCH 47/62] * LightSmsTransport.php - build signature and use http_build_query, timestamp int --- .../Bridge/LightSms/LightSmsTransport.php | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index f6d56c13bf455..65ad7959ad2da 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -101,19 +101,15 @@ protected function doSend(MessageInterface $message): SentMessage } $timestamp = time(); - - $signature = $this->generateSignature($message, $timestamp); - - $endpoint = sprintf( - 'https://%s/external/get/send.php?login=%s&signature=%s&phone=%s&text=%s&sender=%s×tamp=%s', - $this->getEndpoint(), - $this->login, - $signature, - $this->escapePhoneNumber($message->getPhone()), - $this->escapeSubject($message->getSubject()), - $this->from, - $timestamp - ); + $data = [ + 'login' => $this->login, + 'phone' => $this->escapePhoneNumber($message->getPhone()), + 'text' => $message->getSubject(), + 'sender' => $this->from, + 'timestamp' => $timestamp + ]; + $data['signature'] = $this->generateSignature($data, $timestamp); + $endpoint = 'https://'.$this->getEndpoint().'/external/get/send.php?'.http_build_query($data); $response = $this->client->request('GET', $endpoint); @@ -145,14 +141,14 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - private function generateSignature(SmsMessage $message, string $timestamp): string + private function generateSignature(array $data, int $timestamp): string { $params = [ 'timestamp' => $timestamp, 'login' => $this->login, - 'phone' => $this->escapePhoneNumber($message->getPhone()), + 'phone' => $data['phone'], 'sender' => $this->from, - 'text' => $this->escapeSubject($message->getSubject()), + 'text' => $data['text'], ]; ksort($params); @@ -161,11 +157,6 @@ private function generateSignature(SmsMessage $message, string $timestamp): stri return md5(implode('', $params).$this->password); } - private function escapeSubject(string $subject): string - { - return strip_tags($subject); - } - private function escapePhoneNumber(string $phoneNumber): string { return str_replace('+', '00', $phoneNumber); From 83d259832b921f3f113c7cab6ac3897caaaf4b52 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Thu, 1 Apr 2021 13:35:26 +0300 Subject: [PATCH 48/62] * Coding Standard patch --- .../Bridge/LightSms/LightSmsTransport.php | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 65ad7959ad2da..0735acfd64fd8 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -33,46 +33,46 @@ final class LightSmsTransport extends AbstractTransport private $from; private const ERROR_CODES = [ - 000 => 'Service unavailable', - 1 => 'Missing Signature', - 2 => 'Login not specified', - 3 => 'Text not specified', - 4 => 'Phone number not specified', - 5 => 'Sender not specified', - 6 => 'Invalid signature', - 7 => 'Invalid login', - 8 => 'Invalid sender name', - 9 => 'Sender name not registered', - 10 => 'Sender name not approved', - 11 => 'There are forbidden words in the text', - 12 => 'Error in SMS sending', - 13 => 'Phone number is in the blackist. SMS sending to this number is forbidden.', - 14 => 'There are more than 50 numbers in the request', - 15 => 'List not specified', - 16 => 'Invalid phone number', - 17 => 'SMS ID not specified', - 18 => 'Status not obtained', - 19 => 'Empty response', - 20 => 'The number already exists', - 21 => 'No name', - 22 => 'Template already exists', - 23 => 'Missing Month (Format: YYYY-MM)', - 24 => 'Timestamp not specified', - 25 => 'Error in access to the list', - 26 => 'There are no numbers in the list', - 27 => 'No valid numbers', - 28 => 'Missing start date (Format: YYYY-MM-DD)', - 29 => 'Missing end date (Format: YYYY-MM-DD)', - 30 => 'No date (format: YYYY-MM-DD)', - 31 => 'Closing direction to the user', - 32 => 'Not enough money', - 33 => 'Missing phone number', - 34 => 'Phone is in stop list', - 35 => 'Not enough money', - 36 => 'Can not obtain information about phone', - 37 => 'Base Id is not set', - 38 => 'Phone number already exists in this database', - 39 => 'Phone number does not exist in this database', + 000 => 'Service unavailable', + 1 => 'Missing Signature', + 2 => 'Login not specified', + 3 => 'Text not specified', + 4 => 'Phone number not specified', + 5 => 'Sender not specified', + 6 => 'Invalid signature', + 7 => 'Invalid login', + 8 => 'Invalid sender name', + 9 => 'Sender name not registered', + 10 => 'Sender name not approved', + 11 => 'There are forbidden words in the text', + 12 => 'Error in SMS sending', + 13 => 'Phone number is in the blackist. SMS sending to this number is forbidden.', + 14 => 'There are more than 50 numbers in the request', + 15 => 'List not specified', + 16 => 'Invalid phone number', + 17 => 'SMS ID not specified', + 18 => 'Status not obtained', + 19 => 'Empty response', + 20 => 'The number already exists', + 21 => 'No name', + 22 => 'Template already exists', + 23 => 'Missing Month (Format: YYYY-MM)', + 24 => 'Timestamp not specified', + 25 => 'Error in access to the list', + 26 => 'There are no numbers in the list', + 27 => 'No valid numbers', + 28 => 'Missing start date (Format: YYYY-MM-DD)', + 29 => 'Missing end date (Format: YYYY-MM-DD)', + 30 => 'No date (format: YYYY-MM-DD)', + 31 => 'Closing direction to the user', + 32 => 'Not enough money', + 33 => 'Missing phone number', + 34 => 'Phone is in stop list', + 35 => 'Not enough money', + 36 => 'Can not obtain information about phone', + 37 => 'Base Id is not set', + 38 => 'Phone number already exists in this database', + 39 => 'Phone number does not exist in this database', ]; public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) @@ -102,11 +102,11 @@ protected function doSend(MessageInterface $message): SentMessage $timestamp = time(); $data = [ - 'login' => $this->login, - 'phone' => $this->escapePhoneNumber($message->getPhone()), - 'text' => $message->getSubject(), - 'sender' => $this->from, - 'timestamp' => $timestamp + 'login' => $this->login, + 'phone' => $this->escapePhoneNumber($message->getPhone()), + 'text' => $message->getSubject(), + 'sender' => $this->from, + 'timestamp' => $timestamp, ]; $data['signature'] = $this->generateSignature($data, $timestamp); $endpoint = 'https://'.$this->getEndpoint().'/external/get/send.php?'.http_build_query($data); From a197deeed17d27e248165993bd0f4b229bee7b46 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Thu, 1 Apr 2021 13:58:54 +0300 Subject: [PATCH 49/62] * LightSmsTransport.php - better to remove if we do not have it? --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 0735acfd64fd8..b751172418943 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -26,14 +26,13 @@ */ final class LightSmsTransport extends AbstractTransport { - protected const HOST = 'www.lightsms.com'; + protected const HOST = 'lightsms.com'; private $login; private $password; private $from; private const ERROR_CODES = [ - 000 => 'Service unavailable', 1 => 'Missing Signature', 2 => 'Login not specified', 3 => 'Text not specified', @@ -119,6 +118,8 @@ protected function doSend(MessageInterface $message): SentMessage $content = $response->toArray(false); + dump($content); die(); + // it happens if the host without www if (isset($content['']) && isset($content['']['error'])) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); From 95e82f6ef14f189ef084f196ff55e39c2214930a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vasilij=20Du=C5=A1ko?= Date: Fri, 2 Apr 2021 06:31:20 +0300 Subject: [PATCH 50/62] Update LightSmsTransport.php remove dump die --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index b751172418943..3a34756e3b9b6 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -118,8 +118,6 @@ protected function doSend(MessageInterface $message): SentMessage $content = $response->toArray(false); - dump($content); die(); - // it happens if the host without www if (isset($content['']) && isset($content['']['error'])) { throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); From 178d9c2a5a79c8875a76464bec48689508eb08e9 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:26:24 +0300 Subject: [PATCH 51/62] * pull request #40696 --- src/Symfony/Component/Notifier/Bridge/LightSms/.gitattributes | 4 ++++ src/Symfony/Component/Notifier/Bridge/LightSms/.gitignore | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/.gitattributes create mode 100644 src/Symfony/Component/Notifier/Bridge/LightSms/.gitignore diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/.gitattributes b/src/Symfony/Component/Notifier/Bridge/LightSms/.gitattributes new file mode 100644 index 0000000000000..84c7add058fb5 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/.gitattributes @@ -0,0 +1,4 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/.gitignore b/src/Symfony/Component/Notifier/Bridge/LightSms/.gitignore new file mode 100644 index 0000000000000..c49a5d8df5c65 --- /dev/null +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/.gitignore @@ -0,0 +1,3 @@ +vendor/ +composer.lock +phpunit.xml From 9a832ef5956f03ad45f27b26280874e5c4a1ecc2 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:48:58 +0300 Subject: [PATCH 52/62] * 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 --- .../Bridge/LightSms/LightSmsTransport.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 3a34756e3b9b6..3dac3d25e0c39 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -26,7 +26,7 @@ */ final class LightSmsTransport extends AbstractTransport { - protected const HOST = 'lightsms.com'; + protected const HOST = 'www.lightsms.com'; private $login; private $password; @@ -72,6 +72,7 @@ final class LightSmsTransport extends AbstractTransport 37 => 'Base Id is not set', 38 => 'Phone number already exists in this database', 39 => 'Phone number does not exist in this database', + 999 => 'Unknown Error', ]; 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 $content = $response->toArray(false); // it happens if the host without www - if (isset($content['']) && isset($content['']['error'])) { - throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response); + if (isset($content['']['error'])) { + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['']['error']), $response); } if (isset($content['error'])) { - throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['error']), $response); } $phone = $this->escapePhoneNumber($message->getPhone()); if (32 === $content[$phone]['error']) { - throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content[$phone]['error']), $response); } if (0 == $content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); $sentMessage->setMessageId($content[$phone]['id_sms']); + + return $sentMessage; } - return $sentMessage; + throw new TransportException('Unable to send the SMS: ', $response); } private function generateSignature(array $data, int $timestamp): string @@ -160,4 +163,9 @@ private function escapePhoneNumber(string $phoneNumber): string { return str_replace('+', '00', $phoneNumber); } + + private function getErrorMsg(string $errorCode): string + { + return isset(self::ERROR_CODES[$errorCode]) ? self::ERROR_CODES[$errorCode] : self::ERROR_CODES[999]; + } } From 0d7488b10aa4855ee7aaf82641ac27d9d4c83424 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:51:01 +0300 Subject: [PATCH 53/62] * type cast. On success lightsms return error code like string. On error return integer. --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 3dac3d25e0c39..33420217927dd 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -121,16 +121,16 @@ protected function doSend(MessageInterface $message): SentMessage // it happens if the host without www if (isset($content['']['error'])) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['']['error']), $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content['']['error']), $response); } if (isset($content['error'])) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['error']), $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content['error']), $response); } $phone = $this->escapePhoneNumber($message->getPhone()); if (32 === $content[$phone]['error']) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content[$phone]['error']), $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content[$phone]['error']), $response); } if (0 == $content[$phone]['error']) { @@ -164,7 +164,7 @@ private function escapePhoneNumber(string $phoneNumber): string return str_replace('+', '00', $phoneNumber); } - private function getErrorMsg(string $errorCode): string + private function getErrorMsg(int $errorCode): string { return isset(self::ERROR_CODES[$errorCode]) ? self::ERROR_CODES[$errorCode] : self::ERROR_CODES[999]; } From 9b2e2d0b4af522554bd92df70da524ebb15e2b61 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:52:47 +0300 Subject: [PATCH 54/62] * type cast. On success lightsms return error code like string. On error return integer. --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 33420217927dd..ca037d1103f46 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -129,11 +129,11 @@ protected function doSend(MessageInterface $message): SentMessage } $phone = $this->escapePhoneNumber($message->getPhone()); - if (32 === $content[$phone]['error']) { + if (32 === (int)$content[$phone]['error']) { throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content[$phone]['error']), $response); } - if (0 == $content[$phone]['error']) { + if (0 == (int)$content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); $sentMessage->setMessageId($content[$phone]['id_sms']); From bea5256cc228280cb3ff74d631d119a5c4a2821e Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:53:00 +0300 Subject: [PATCH 55/62] * type cast. On success lightsms return error code like string. On error return integer. --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index ca037d1103f46..3a4eb00458acf 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -133,7 +133,7 @@ protected function doSend(MessageInterface $message): SentMessage throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content[$phone]['error']), $response); } - if (0 == (int)$content[$phone]['error']) { + if (0 === (int)$content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); $sentMessage->setMessageId($content[$phone]['id_sms']); From 21e972a69e421ce947469702a1d711fcb8745f7d Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Sun, 4 Apr 2021 10:54:22 +0300 Subject: [PATCH 56/62] * coding standard --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 3a4eb00458acf..cb46a8a83f8ea 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -121,19 +121,19 @@ protected function doSend(MessageInterface $message): SentMessage // it happens if the host without www if (isset($content['']['error'])) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content['']['error']), $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int) $content['']['error']), $response); } if (isset($content['error'])) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content['error']), $response); + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int) $content['error']), $response); } $phone = $this->escapePhoneNumber($message->getPhone()); - if (32 === (int)$content[$phone]['error']) { - throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int)$content[$phone]['error']), $response); + if (32 === (int) $content[$phone]['error']) { + throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg((int) $content[$phone]['error']), $response); } - if (0 === (int)$content[$phone]['error']) { + if (0 === (int) $content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); $sentMessage->setMessageId($content[$phone]['id_sms']); @@ -166,6 +166,6 @@ private function escapePhoneNumber(string $phoneNumber): string private function getErrorMsg(int $errorCode): string { - return isset(self::ERROR_CODES[$errorCode]) ? self::ERROR_CODES[$errorCode] : self::ERROR_CODES[999]; + return self::ERROR_CODES[$errorCode] ?? self::ERROR_CODES[999]; } } From 4213564be1cd1c1c1f9657fa03f0e78489c46317 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko Date: Mon, 5 Apr 2021 15:00:41 +0300 Subject: [PATCH 57/62] * composer.json - fix Fabien comment from another pull request #40646 --- src/Symfony/Component/Notifier/Bridge/LightSms/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json index b28e5ae58d0bb..5faaa6f0ffc07 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": ">=7.2.5", - "symfony/http-client": "^4.3|^5.0", + "symfony/http-client": "^4.4|^5.2", "symfony/notifier": "^5.3" }, "autoload": { From 2a9ac2d92a2909d7697bd59ddc5911770a926139 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 6 Apr 2021 13:06:59 +0300 Subject: [PATCH 58/62] * LightSmsTransport.php - fix --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index cb46a8a83f8ea..4d6f882a3f925 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -114,7 +114,7 @@ protected function doSend(MessageInterface $message): SentMessage $response = $this->client->request('GET', $endpoint); if (Response::HTTP_OK !== $response->getStatusCode()) { - throw new TransportException('Unable to send the SMS: ', $response); + throw new TransportException('Unable to send the SMS', $response); } $content = $response->toArray(false); @@ -140,7 +140,7 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - throw new TransportException('Unable to send the SMS: ', $response); + throw new TransportException('Unable to send the SMS', $response); } private function generateSignature(array $data, int $timestamp): string From 026dcd97a96b758771bbf8962076ae6a15743fb9 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 6 Apr 2021 13:09:30 +0300 Subject: [PATCH 59/62] * LightSmsTransport.php - isset --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 4d6f882a3f925..9cb318cf295d0 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -135,7 +135,9 @@ protected function doSend(MessageInterface $message): SentMessage if (0 === (int) $content[$phone]['error']) { $sentMessage = new SentMessage($message, (string) $this); - $sentMessage->setMessageId($content[$phone]['id_sms']); + if (isset($content[$phone]['id_sms'])) { + $sentMessage->setMessageId($content[$phone]['id_sms']); + } return $sentMessage; } From f1f83b9e5ccc19dc97e17de2cf0b76ee48ae7352 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 6 Apr 2021 13:12:05 +0300 Subject: [PATCH 60/62] * LightSmsTransport.php - use query string parameters --- .../Notifier/Bridge/LightSms/LightSmsTransport.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 9cb318cf295d0..205a7f1f7e7ae 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -86,7 +86,7 @@ public function __construct(string $login, string $password, string $from, HttpC public function __toString(): string { - return sprintf('lightsms://%s/external/get/send.php?from=%s', $this->getEndpoint(), $this->from); + return sprintf('lightsms://%s?from=%s', $this->getEndpoint(), $this->from); } public function supports(MessageInterface $message): bool @@ -109,9 +109,15 @@ protected function doSend(MessageInterface $message): SentMessage 'timestamp' => $timestamp, ]; $data['signature'] = $this->generateSignature($data, $timestamp); - $endpoint = 'https://'.$this->getEndpoint().'/external/get/send.php?'.http_build_query($data); - $response = $this->client->request('GET', $endpoint); + $endpoint = sprintf('https://%s/external/get/send.php', $this->getEndpoint()); + $response = $this->client->request( + 'GET', + $endpoint, + [ + 'query' => $data, + ] + ); if (Response::HTTP_OK !== $response->getStatusCode()) { throw new TransportException('Unable to send the SMS', $response); From 68a12fa4f4394d1c776c48e992503fb3bcdc7af2 Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 6 Apr 2021 13:18:17 +0300 Subject: [PATCH 61/62] * fix tests --- .../Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php | 2 +- .../Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php index 8306c6bdb0011..01b206882f549 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportFactoryTest.php @@ -28,7 +28,7 @@ public function createFactory(): TransportFactoryInterface public function createProvider(): iterable { yield [ - 'lightsms://host.test/external/get/send.php?from=0611223344', + 'lightsms://host.test?from=0611223344', 'lightsms://login:token@host.test?from=0611223344', ]; } diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php index c11d22b862daf..86230a9eb8789 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/Tests/LightSmsTransportTest.php @@ -31,7 +31,7 @@ public function createTransport(?HttpClientInterface $client = null): TransportI public function toStringProvider(): iterable { - yield ['lightsms://www.lightsms.com/external/get/send.php?from=from', $this->createTransport()]; + yield ['lightsms://www.lightsms.com?from=from', $this->createTransport()]; } public function supportedMessagesProvider(): iterable From 37c665eb5c2e5d1420636116b0e5f29c6438b2af Mon Sep 17 00:00:00 2001 From: Vasilij Dusko | CREATION Date: Tue, 6 Apr 2021 13:22:50 +0300 Subject: [PATCH 62/62] * LightSmsTransport.php - make fabbot happy --- .../Component/Notifier/Bridge/LightSms/LightSmsTransport.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php index 205a7f1f7e7ae..e2d2d60dacd8e 100644 --- a/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/LightSms/LightSmsTransport.php @@ -120,7 +120,7 @@ protected function doSend(MessageInterface $message): SentMessage ); if (Response::HTTP_OK !== $response->getStatusCode()) { - throw new TransportException('Unable to send the SMS', $response); + throw new TransportException('Unable to send the SMS.', $response); } $content = $response->toArray(false); @@ -148,7 +148,7 @@ protected function doSend(MessageInterface $message): SentMessage return $sentMessage; } - throw new TransportException('Unable to send the SMS', $response); + throw new TransportException('Unable to send the SMS.', $response); } private function generateSignature(array $data, int $timestamp): string