Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd46125a

Browse files
committed
feature#42180 [Notifier] Add bridge for smsc.ru (kozlice)
This PR was merged into the 5.4 branch.Discussion----------[Notifier] Add bridge for smsc.ru| Q | A| ------------- | ---| Branch? | 5.4| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets | -| License | MIT| Doc PR |symfony/symfony-docs#15536Hi,This is a notifier bridge for Russian SMS provider [smsc](https://smsc.ru).This PR contains the new bridge and updates to framework bundle in all the places where all the other notifiers are listed.Commits-------1c935ce [Notifier] Add bridge for smsc.ru
2 parentsb175ebd +1c935ce commitd46125a

File tree

16 files changed

+371
-0
lines changed

16 files changed

+371
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
useSymfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
141141
useSymfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
142142
useSymfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransportFactory;
143+
useSymfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
143144
useSymfony\Component\Notifier\Bridge\SpotHit\SpotHitTransportFactory;
144145
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
145146
useSymfony\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‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
useSymfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
4343
useSymfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
4444
useSymfony\Component\Notifier\Bridge\SmsBiuras\SmsBiurasTransportFactory;
45+
useSymfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
4546
useSymfony\Component\Notifier\Bridge\SpotHit\SpotHitTransportFactory;
4647
useSymfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
4748
useSymfony\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')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/Testsexport-ignore
2+
/phpunit.xml.distexport-ignore
3+
/.gitattributesexport-ignore
4+
/.gitignoreexport-ignore
Lines 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
Lines 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+
* Add the bridge
Lines 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.
Lines 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)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
namespaceSymfony\Component\Notifier\Bridge\Smsc;
13+
14+
useSymfony\Component\Notifier\Exception\TransportException;
15+
useSymfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
16+
useSymfony\Component\Notifier\Message\MessageInterface;
17+
useSymfony\Component\Notifier\Message\SentMessage;
18+
useSymfony\Component\Notifier\Message\SmsMessage;
19+
useSymfony\Component\Notifier\Transport\AbstractTransport;
20+
useSymfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
useSymfony\Contracts\HttpClient\Exception\DecodingExceptionInterfaceasHttpDecodingExceptionInterface;
22+
useSymfony\Contracts\HttpClient\Exception\ExceptionInterfaceasHttpExceptionInterface;
23+
useSymfony\Contracts\HttpClient\Exception\TransportExceptionInterfaceasHttpTransportExceptionInterface;
24+
useSymfony\Contracts\HttpClient\HttpClientInterface;
25+
26+
/**
27+
* @author Valentin Nazarov <i.kozlice@protonmail.com>
28+
*/
29+
finalclass SmscTransportextends AbstractTransport
30+
{
31+
protectedconstHOST ='smsc.ru';
32+
33+
private$login;
34+
private$password;
35+
private$from;
36+
37+
publicfunction__construct($username,$password,$from,HttpClientInterface$client =null,EventDispatcherInterface$dispatcher =null)
38+
{
39+
$this->login =$username;
40+
$this->password =$password;
41+
$this->from =$from;
42+
43+
parent::__construct($client,$dispatcher);
44+
}
45+
46+
publicfunction__toString():string
47+
{
48+
returnsprintf('smsc://%s?from=%s',$this->getEndpoint(), (string)$this->from);
49+
}
50+
51+
publicfunctionsupports(MessageInterface$message):bool
52+
{
53+
return$messageinstanceof SmsMessage;
54+
}
55+
56+
protectedfunctiondoSend(MessageInterface$message):SentMessage
57+
{
58+
if (!$messageinstanceof SmsMessage) {
59+
thrownewUnsupportedMessageTypeException(__CLASS__, SmsMessage::class,$message);
60+
}
61+
62+
$body = [
63+
'login' =>$this->login,
64+
'psw' =>$this->password,
65+
'sender' => (string)$this->from,
66+
'phones' =>$message->getPhone(),
67+
'mes' =>$message->getSubject(),
68+
'fmt' =>3,// response as JSON
69+
'charset' =>'utf-8',
70+
'time' =>'0-24',
71+
];
72+
73+
$endpoint =sprintf('https://%s/sys/send.php',$this->getEndpoint());
74+
$response =$this->client->request('POST',$endpoint, ['body' =>$body]);
75+
76+
try {
77+
$result =$response->toArray();
78+
}catch (HttpTransportExceptionInterface$e) {
79+
thrownewTransportException('Could not reach the remote smsc.ru server.',$response,0,$e);
80+
}catch (HttpDecodingExceptionInterface$e) {
81+
thrownewTransportException('Could not decode the response from remote smsc.ru server.',$response,0,$e);
82+
}catch (HttpExceptionInterface$e) {
83+
thrownewTransportException('Unexpected response from remote smsc.ru server.',$response,0,$e);
84+
}
85+
86+
if (\array_key_exists('error',$result)) {
87+
thrownewTransportException(sprintf('Unable to send the SMS: code = %d, message = "%s".',$result['error_code'],$result['error']),$response);
88+
}
89+
90+
$sentMessage =newSentMessage($message, (string)$this);
91+
$sentMessage->setMessageId((string) ($result['id'] ??''));
92+
93+
return$sentMessage;
94+
}
95+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
namespaceSymfony\Component\Notifier\Bridge\Smsc;
13+
14+
useSymfony\Component\Notifier\Exception\UnsupportedSchemeException;
15+
useSymfony\Component\Notifier\Transport\AbstractTransportFactory;
16+
useSymfony\Component\Notifier\Transport\Dsn;
17+
useSymfony\Component\Notifier\Transport\TransportInterface;
18+
19+
/**
20+
* @author Valentin Nazarov <i.kozlice@protonmail.com>
21+
*/
22+
finalclass SmscTransportFactoryextends AbstractTransportFactory
23+
{
24+
/**
25+
* @return SmscTransport
26+
*/
27+
publicfunctioncreate(Dsn$dsn):TransportInterface
28+
{
29+
$scheme =$dsn->getScheme();
30+
31+
if ('smsc' !==$scheme) {
32+
thrownewUnsupportedSchemeException($dsn,'smsc',$this->getSupportedSchemes());
33+
}
34+
35+
$login =$dsn->getUser();
36+
$password =$dsn->getPassword();
37+
$from =$dsn->getRequiredOption('from');
38+
$host ='default' ===$dsn->getHost() ?null :$dsn->getHost();
39+
40+
return (newSmscTransport($login,$password,$from,$this->client,$this->dispatcher))->setHost($host);
41+
}
42+
43+
protectedfunctiongetSupportedSchemes():array
44+
{
45+
return ['smsc'];
46+
}
47+
}
Lines 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+
namespaceSymfony\Component\Notifier\Bridge\Smsc\Tests;
13+
14+
useSymfony\Component\Notifier\Bridge\Smsc\SmscTransportFactory;
15+
useSymfony\Component\Notifier\Test\TransportFactoryTestCase;
16+
useSymfony\Component\Notifier\Transport\TransportFactoryInterface;
17+
18+
finalclass SmscTransportFactoryTestextends TransportFactoryTestCase
19+
{
20+
/**
21+
* @return SmscTransportFactory
22+
*/
23+
publicfunctioncreateFactory():TransportFactoryInterface
24+
{
25+
returnnewSmscTransportFactory();
26+
}
27+
28+
publicfunctioncreateProvider():iterable
29+
{
30+
yield [
31+
'smsc://host.test?from=MyApp',
32+
'smsc://login:password@host.test?from=MyApp',
33+
];
34+
}
35+
36+
publicfunctionsupportsProvider():iterable
37+
{
38+
yield [true,'smsc://login:password@default?from=MyApp'];
39+
yield [false,'somethingElse://login:password@default?from=MyApp'];
40+
}
41+
42+
publicfunctionmissingRequiredOptionProvider():iterable
43+
{
44+
yield'missing option: from' => ['smsc://login:password@default'];
45+
}
46+
47+
publicfunctionunsupportedSchemeProvider():iterable
48+
{
49+
yield ['somethingElse://login:password@default?from=MyApp'];
50+
yield ['somethingElse://login:password@default'];// missing "from" option
51+
}
52+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp