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

Commit89b2981

Browse files
franckranaivoFranck Rodolphe RANAIVO-HARISOA
authored and
Franck Rodolphe RANAIVO-HARISOA
committed
[Notifier] Add Contact Everyone Bridge
1 parent123b165 commit89b2981

File tree

16 files changed

+405
-0
lines changed

16 files changed

+405
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
useSymfony\Component\Notifier\Bridge\AllMySms\AllMySmsTransportFactory;
124124
useSymfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransportFactory;
125125
useSymfony\Component\Notifier\Bridge\Clickatell\ClickatellTransportFactory;
126+
useSymfony\Component\Notifier\Bridge\ContactEveryone\ContactEveryoneTransportFactory;
126127
useSymfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
127128
useSymfony\Component\Notifier\Bridge\Engagespot\EngagespotTransportFactory;
128129
useSymfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
@@ -2523,6 +2524,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
25232524
AllMySmsTransportFactory::class =>'notifier.transport_factory.all-my-sms',
25242525
AmazonSnsTransportFactory::class =>'notifier.transport_factory.amazon-sns',
25252526
ClickatellTransportFactory::class =>'notifier.transport_factory.clickatell',
2527+
ContactEveryoneTransportFactory::class =>'notifier.transport_factory.contact-everyone',
25262528
DiscordTransportFactory::class =>'notifier.transport_factory.discord',
25272529
EngagespotTransportFactory::class =>'notifier.transport_factory.engagespot',
25282530
EsendexTransportFactory::class =>'notifier.transport_factory.esendex',

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useSymfony\Component\Notifier\Bridge\AllMySms\AllMySmsTransportFactory;
1515
useSymfony\Component\Notifier\Bridge\AmazonSns\AmazonSnsTransportFactory;
1616
useSymfony\Component\Notifier\Bridge\Clickatell\ClickatellTransportFactory;
17+
useSymfony\Component\Notifier\Bridge\ContactEveryone\ContactEveryoneTransportFactory;
1718
useSymfony\Component\Notifier\Bridge\Discord\DiscordTransportFactory;
1819
useSymfony\Component\Notifier\Bridge\Engagespot\EngagespotTransportFactory;
1920
useSymfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
@@ -197,6 +198,10 @@
197198
->parent('notifier.transport_factory.abstract')
198199
->tag('texter.transport_factory')
199200

201+
->set('notifier.transport_factory.contact-everyone', ContactEveryoneTransportFactory::class)
202+
->parent('notifier.transport_factory.abstract')
203+
->tag('texter.transport_factory')
204+
200205
->set('notifier.transport_factory.amazon-sns', AmazonSnsTransportFactory::class)
201206
->parent('notifier.transport_factory.abstract')
202207
->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+
6.2
5+
---
6+
7+
* Add the bridge
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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\ContactEveryone;
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\TransportExceptionInterface;
22+
useSymfony\Contracts\HttpClient\HttpClientInterface;
23+
24+
/**
25+
* @author Franck Ranaivo-Harisoa <franckranaivo@gmail.com>
26+
*/
27+
finalclass ContactEveryoneTransportextends AbstractTransport
28+
{
29+
protectedconstHOST ='contact-everyone.orange-business.com';
30+
31+
privatestring$token;
32+
private ?string$diffusionName;
33+
private ?string$category;
34+
35+
publicfunction__construct(string$token, ?string$diffusionName, ?string$category,HttpClientInterface$client =null,EventDispatcherInterface$dispatcher =null)
36+
{
37+
$this->token =$token;
38+
$this->diffusionName =$diffusionName;
39+
$this->category =$category;
40+
41+
parent::__construct($client,$dispatcher);
42+
}
43+
44+
publicfunction__toString():string
45+
{
46+
$dsn =sprintf('contact-everyone://%s',$this->getEndpoint());
47+
48+
if (null !==$this->diffusionName) {
49+
$dsn .=sprintf('?diffusionname=%s',$this->diffusionName);
50+
}
51+
52+
if (null !==$this->category) {
53+
$dsn .=sprintf('%scategory=%s', (null ===$this->diffusionName) ?'?' :'&',$this->category);
54+
}
55+
56+
return$dsn;
57+
}
58+
59+
publicfunctionsupports(MessageInterface$message):bool
60+
{
61+
return$messageinstanceof SmsMessage;
62+
}
63+
64+
protectedfunctiondoSend(MessageInterface$message):SentMessage
65+
{
66+
if (!$messageinstanceof SmsMessage) {
67+
thrownewUnsupportedMessageTypeException(__CLASS__, SmsMessage::class,$message);
68+
}
69+
70+
$endpoint =sprintf('https://%s/api/light/diffusions/sms',self::HOST);
71+
$response =$this->client->request('POST',$endpoint, [
72+
'query' => [
73+
'xcharset' =>'true',
74+
'token' =>$this->token,
75+
'to' =>$message->getPhone(),
76+
'msg' =>$message->getSubject(),
77+
],
78+
]);
79+
80+
try {
81+
$statusCode =$response->getStatusCode();
82+
}catch (TransportExceptionInterface$e) {
83+
thrownewTransportException('Could not reach the remote Contact Everyone server.',$response,0,$e);
84+
}
85+
86+
if (200 !==$statusCode) {
87+
$error =$response->toArray(false);
88+
thrownewTransportException(sprintf('Unable to send the Contact Everyone message with following error: "%s". For further details, please check this logId: "%s".',$error['message'],$error['logId']),$response);
89+
}
90+
91+
$result =$response->getContent(false);
92+
93+
$sentMessage =newSentMessage($message, (string)$this);
94+
$sentMessage->setMessageId($result ??'');
95+
96+
return$sentMessage;
97+
}
98+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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\ContactEveryone;
13+
14+
useSymfony\Component\Notifier\Exception\UnsupportedSchemeException;
15+
useSymfony\Component\Notifier\Transport\AbstractTransportFactory;
16+
useSymfony\Component\Notifier\Transport\Dsn;
17+
18+
/**
19+
* @author Franck Ranaivo-Harisoa <franckranaivo@gmail.com>
20+
*/
21+
finalclass ContactEveryoneTransportFactoryextends AbstractTransportFactory
22+
{
23+
publicfunctioncreate(Dsn$dsn):ContactEveryoneTransport
24+
{
25+
if ('contact-everyone' !==$dsn->getScheme()) {
26+
thrownewUnsupportedSchemeException($dsn,'contact-everyone',$this->getSupportedSchemes());
27+
}
28+
29+
$token =$this->getUser($dsn);
30+
$host ='default' ===$dsn->getHost() ?null :$dsn->getHost();
31+
$diffusionName =$dsn->getOption('diffusionname');
32+
$category =$dsn->getOption('category');
33+
34+
return (newContactEveryoneTransport($token,$diffusionName,$category,$this->client,$this->dispatcher))->setHost($host)->setPort($dsn->getPort());
35+
}
36+
37+
protectedfunctiongetSupportedSchemes():array
38+
{
39+
return ['contact-everyone'];
40+
}
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2022 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Contact Everyone Notifier
2+
=========================
3+
4+
Provides[Contact everyone](https://www.orange-business.com/fr/produits/contact-everyone) integration for Symfony Notifier.
5+
6+
DSN example
7+
-----------
8+
9+
```
10+
CONTACT_EVERYONE_DSN=contact-everyone://TOKEN@default?&diffusionname=DIFFUSION_NAME&category=CATEGORY
11+
```
12+
13+
where:
14+
-`TOKEN` is your Contact Everyone api token
15+
-`DIFFUSION_NAME` (optional) allows you to define the label of the diffusion that will be displayed in the event logs.
16+
-`CATEGORY` (optional) allows you to define the label of the category that will be displayed in the event logs.
17+
18+
This bridge uses the light version of Contact Everyone api.
19+
20+
See your account info athttps://contact-everyone.orange-business.com/#/login
21+
22+
Resources
23+
---------
24+
25+
*[Contributing](https://symfony.com/doc/current/contributing/index.html)
26+
*[Report issues](https://github.com/symfony/symfony/issues) and
27+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
28+
in the[main Symfony repository](https://github.com/symfony/symfony)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\ContactEveryone\Tests;
13+
14+
useSymfony\Component\Notifier\Bridge\ContactEveryone\ContactEveryoneTransportFactory;
15+
useSymfony\Component\Notifier\Test\TransportFactoryTestCase;
16+
17+
finalclass ContactEveryoneTransportFactoryTestextends TransportFactoryTestCase
18+
{
19+
publicfunctioncreateFactory():ContactEveryoneTransportFactory
20+
{
21+
returnnewContactEveryoneTransportFactory();
22+
}
23+
24+
publicfunctioncreateProvider():iterable
25+
{
26+
yield [
27+
'contact-everyone://host.test',
28+
'contact-everyone://token@host.test',
29+
];
30+
31+
yield [
32+
'contact-everyone://host.test?diffusionname=Symfony',
33+
'contact-everyone://token@host.test?diffusionname=Symfony',
34+
];
35+
36+
yield [
37+
'contact-everyone://host.test?category=Symfony',
38+
'contact-everyone://token@host.test?category=Symfony',
39+
];
40+
41+
yield [
42+
'contact-everyone://host.test?diffusionname=Symfony&category=Symfony',
43+
'contact-everyone://token@host.test?diffusionname=Symfony&category=Symfony',
44+
];
45+
}
46+
47+
publicfunctionsupportsProvider():iterable
48+
{
49+
yield [true,'contact-everyone://token@default'];
50+
yield [false,'somethingElse://token@default'];
51+
}
52+
53+
publicfunctionincompleteDsnProvider():iterable
54+
{
55+
yield'missing token' => ['contact-everyone://default'];
56+
}
57+
58+
publicfunctionunsupportedSchemeProvider():iterable
59+
{
60+
yield ['somethingElse://token@default'];
61+
}
62+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp