Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0863f6d

Browse filesBrowse files
author
Valentin Nazarov
committed
[Notifier] Add bridge for smsc.ru
1 parent 7df57da commit 0863f6d
Copy full SHA for 0863f6d

15 files changed

+354
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
141141
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
142142
use Symfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransportFactory;
143+
use Symfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
143144
use Symfony\Component\Notifier\Bridge\SpotHit\SpotHitTransportFactory;
144145
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
145146
use Symfony\Component\Notifier\Bridge\Telnyx\TelnyxTransportFactory;
@@ -2449,6 +2450,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
24492450
SlackTransportFactory::class => 'notifier.transport_factory.slack',
24502451
SmsapiTransportFactory::class => 'notifier.transport_factory.smsapi',
24512452
SmsBiurasTransportFactory::class => 'notifier.transport_factory.smsbiuras',
2453+
SmscTransportFactory::class => 'notifier.transport_factory.smsc',
24522454
SpotHitTransportFactory::class => 'notifier.transport_factory.spothit',
24532455
TelegramTransportFactory::class => 'notifier.transport_factory.telegram',
24542456
TelnyxTransportFactory::class => 'notifier.transport_factory.telnyx',

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
4343
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
4444
use Symfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransportFactory;
45+
use Symfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
4546
use Symfony\Component\Notifier\Bridge\SpotHit\SpotHitTransportFactory;
4647
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
4748
use Symfony\Component\Notifier\Bridge\Telnyx\TelnyxTransportFactory;
@@ -189,6 +190,10 @@
189190
->parent('notifier.transport_factory.abstract')
190191
->tag('texter.transport_factory')
191192

193+
->set('notifier.transport_factory.smsc', SmscTransportFactory::class)
194+
->parent('notifier.transport_factory.abstract')
195+
->tag('texter.transport_factory')
196+
192197
->set('notifier.transport_factory.messagebird', MessageBirdTransportFactory::class)
193198
->parent('notifier.transport_factory.abstract')
194199
->tag('texter.transport_factory')
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
5.4
5+
---
6+
7+
* Added the bridge
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
SMSC Notifier
2+
=============
3+
4+
Provides [SMSC](https://smsc.ru/) integration for Symfony Notifier.
5+
6+
DSN example
7+
-----------
8+
9+
```
10+
SMSC_DSN=smsc://LOGIN:PASSWORD@default?from=FROM
11+
```
12+
13+
where:
14+
- `LOGIN` is your login
15+
- `PASSWORD` is your API password
16+
- `FROM` is your sender (NB: text identity, not a phone number)
17+
18+
Resources
19+
---------
20+
21+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
22+
* [Report issues](https://github.com/symfony/symfony/issues) and
23+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
24+
in the [main Symfony repository](https://github.com/symfony/symfony)
+84Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsc;
13+
14+
use Symfony\Component\Notifier\Exception\TransportException;
15+
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
16+
use Symfony\Component\Notifier\Message\MessageInterface;
17+
use Symfony\Component\Notifier\Message\SentMessage;
18+
use Symfony\Component\Notifier\Message\SmsMessage;
19+
use Symfony\Component\Notifier\Transport\AbstractTransport;
20+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
22+
23+
class SmscTransport extends AbstractTransport
24+
{
25+
protected const HOST = 'smsc.ru';
26+
27+
private $login;
28+
private $password;
29+
private $from;
30+
31+
public function __construct($username, $password, $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
32+
{
33+
$this->login = $username;
34+
$this->password = $password;
35+
$this->from = $from;
36+
37+
parent::__construct($client, $dispatcher);
38+
}
39+
40+
public function __toString(): string
41+
{
42+
return sprintf('smsc://%s?from=%s', $this->getEndpoint(), (string) $this->from);
43+
}
44+
45+
public function supports(MessageInterface $message): bool
46+
{
47+
return $message instanceof SmsMessage;
48+
}
49+
50+
protected function doSend(MessageInterface $message): SentMessage
51+
{
52+
if (!$message instanceof SmsMessage) {
53+
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
54+
}
55+
56+
$query = [
57+
'login' => $this->login,
58+
'psw' => $this->password,
59+
'sender' => (string) $this->from,
60+
'phones' => $message->getPhone(),
61+
'mes' => $message->getSubject(),
62+
'fmt' => 3, // response as JSON
63+
'charset' => 'utf-8',
64+
'time' => '0-24',
65+
];
66+
67+
$endpoint = sprintf('https://%s/sys/send.php', $this->getEndpoint());
68+
$response = $this->client->request('GET', $endpoint, ['query' => $query]);
69+
70+
if (200 !== $response->getStatusCode()) {
71+
throw new TransportException('Unable to send the SMS.', $response);
72+
}
73+
74+
$result = $response->toArray(false);
75+
if (\array_key_exists('error', $result)) {
76+
throw new TransportException(sprintf('Unable to send the SMS: code = %d, message = "%s".', $result['error_code'], $result['error']), $response);
77+
}
78+
79+
$sentMessage = new SentMessage($message, (string) $this);
80+
$sentMessage->setMessageId((string) ($result['id'] ?? ''));
81+
82+
return $sentMessage;
83+
}
84+
}
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsc;
13+
14+
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
15+
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
16+
use Symfony\Component\Notifier\Transport\Dsn;
17+
use Symfony\Component\Notifier\Transport\TransportInterface;
18+
19+
class SmscTransportFactory extends AbstractTransportFactory
20+
{
21+
/**
22+
* @return SmscTransport
23+
*/
24+
public function create(Dsn $dsn): TransportInterface
25+
{
26+
$scheme = $dsn->getScheme();
27+
28+
if ('smsc' !== $scheme) {
29+
throw new UnsupportedSchemeException($dsn, 'smsc', $this->getSupportedSchemes());
30+
}
31+
32+
$login = $dsn->getUser();
33+
$password = $dsn->getPassword();
34+
$from = $dsn->getRequiredOption('from');
35+
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
36+
37+
return (new SmscTransport($login, $password, $from, $this->client, $this->dispatcher))->setHost($host);
38+
}
39+
40+
protected function getSupportedSchemes(): array
41+
{
42+
return ['smsc'];
43+
}
44+
}
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsc\Tests;
13+
14+
use Symfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
15+
use Symfony\Component\Notifier\Test\TransportFactoryTestCase;
16+
use Symfony\Component\Notifier\Transport\TransportFactoryInterface;
17+
18+
class SmscTransportFactoryTest extends TransportFactoryTestCase
19+
{
20+
/**
21+
* @return SmscTransportFactory
22+
*/
23+
public function createFactory(): TransportFactoryInterface
24+
{
25+
return new SmscTransportFactory();
26+
}
27+
28+
public function createProvider(): iterable
29+
{
30+
yield [
31+
'smsc://host.test?from=MyApp',
32+
'smsc://login:password@host.test?from=MyApp',
33+
];
34+
}
35+
36+
public function supportsProvider(): iterable
37+
{
38+
yield [true, 'smsc://login:password@default?from=MyApp'];
39+
yield [false, 'somethingElse://login:password@default?from=MyApp'];
40+
}
41+
42+
public function missingRequiredOptionProvider(): iterable
43+
{
44+
yield 'missing option: from' => ['smsc://login:password@default'];
45+
}
46+
47+
public function unsupportedSchemeProvider(): iterable
48+
{
49+
yield ['somethingElse://login:password@default?from=MyApp'];
50+
yield ['somethingElse://login:password@default']; // missing "from" option
51+
}
52+
}
+44Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Bridge\Smsc\Tests;
13+
14+
use Symfony\Component\Notifier\Bridge\Smsc\SmscTransport;
15+
use Symfony\Component\Notifier\Message\ChatMessage;
16+
use Symfony\Component\Notifier\Message\MessageInterface;
17+
use Symfony\Component\Notifier\Message\SmsMessage;
18+
use Symfony\Component\Notifier\Test\TransportTestCase;
19+
use Symfony\Component\Notifier\Transport\TransportInterface;
20+
use Symfony\Contracts\HttpClient\HttpClientInterface;
21+
22+
class SmscTransportTest extends TransportTestCase
23+
{
24+
public function createTransport(HttpClientInterface $client = null): TransportInterface
25+
{
26+
return new SmscTransport('login', 'password', 'MyApp', $client ?? $this->createMock(HttpClientInterface::class));
27+
}
28+
29+
public function toStringProvider(): iterable
30+
{
31+
yield ['smsc://smsc.ru?from=MyApp', $this->createTransport()];
32+
}
33+
34+
public function supportedMessagesProvider(): iterable
35+
{
36+
yield [new SmsMessage('0611223344', 'Hello!')];
37+
}
38+
39+
public function unsupportedMessagesProvider(): iterable
40+
{
41+
yield [new ChatMessage('Hello!')];
42+
yield [$this->createMock(MessageInterface::class)];
43+
}
44+
}
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "symfony/smsc-notifier",
3+
"type": "symfony-bridge",
4+
"description": "Symfony SMSC Notifier Bridge",
5+
"keywords": ["sms", "smsc", "notifier"],
6+
"homepage": "https://symfony.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Fabien Potencier",
11+
"email": "fabien@symfony.com"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": ">=7.2.5",
20+
"symfony/http-client": "^4.4|^5.2|^6.0",
21+
"symfony/notifier": "^5.3|^6.0"
22+
},
23+
"autoload": {
24+
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsc\\": "" },
25+
"exclude-from-classmap": [
26+
"/Tests/"
27+
]
28+
},
29+
"minimum-stability": "dev"
30+
}
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1" />
13+
</php>
14+
15+
<testsuites>
16+
<testsuite name="Symfony SMSC Notifier Bridge Test Suite">
17+
<directory>./Tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<filter>
22+
<whitelist>
23+
<directory>./</directory>
24+
<exclude>
25+
<directory>./Tests</directory>
26+
<directory>./vendor</directory>
27+
</exclude>
28+
</whitelist>
29+
</filter>
30+
</phpunit>

‎src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ class UnsupportedSchemeException extends LogicException
144144
'class' => Bridge\SmsBiuras\SmsBiurasTransportFactory::class,
145145
'package' => 'symfony/sms-biuras-notifier',
146146
],
147+
'smsc' => [
148+
'class' => Bridge\Smsc\SmscTransportFactory::class,
149+
'package' => 'symfony/smsc-notifier',
150+
],
147151
'spothit' => [
148152
'class' => Bridge\SpotHit\SpotHitTransportFactory::class,
149153
'package' => 'symfony/spot-hit-notifier',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.