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

Commit61f27ac

Browse files
gnito-orgnicolas-grekas
authored andcommitted
[Notifier] Add SMS options to MessageBird notifier
1 parent912aca4 commit61f27ac

File tree

5 files changed

+299
-6
lines changed

5 files changed

+299
-6
lines changed

‎src/Symfony/Component/Notifier/Bridge/MessageBird/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.3
5+
---
6+
7+
* Add`MessageBirdOptions` class
8+
49
6.2
510
---
611

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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\MessageBird;
13+
14+
useSymfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
/**
17+
* @author gnito-org <https://github.com/gnito-org>
18+
*/
19+
finalclass MessageBirdOptionsimplements MessageOptionsInterface
20+
{
21+
privatearray$options;
22+
23+
publicfunction__construct(array$options = [])
24+
{
25+
$this->options =$options;
26+
}
27+
28+
publicfunctiongetCreatedDatetime(): ?string
29+
{
30+
return$this->options['created_datetime'] ??null;
31+
}
32+
33+
publicfunctiongetDataCoding(): ?string
34+
{
35+
return$this->options['data_coding'] ??null;
36+
}
37+
38+
publicfunctiongetFrom(): ?string
39+
{
40+
return$this->options['from'] ??null;
41+
}
42+
43+
publicfunctiongetGateway(): ?int
44+
{
45+
return$this->options['gateway'] ??null;
46+
}
47+
48+
publicfunctiongetGroupIds(): ?array
49+
{
50+
return$this->options['group_ids'] ??null;
51+
}
52+
53+
publicfunctiongetMClass(): ?int
54+
{
55+
return$this->options['m_class'] ??null;
56+
}
57+
58+
publicfunctiongetRecipientId(): ?string
59+
{
60+
return$this->options['recipient_id'] ??null;
61+
}
62+
63+
publicfunctiongetReference(): ?string
64+
{
65+
return$this->options['reference'] ??null;
66+
}
67+
68+
publicfunctiongetReportUrl(): ?string
69+
{
70+
return$this->options['report_url'] ??null;
71+
}
72+
73+
publicfunctiongetScheduledDatetime(): ?string
74+
{
75+
return$this->options['scheduled_datetime'] ??null;
76+
}
77+
78+
publicfunctiongetShortenUrls(): ?bool
79+
{
80+
return$this->options['shorten_urls'] ??null;
81+
}
82+
83+
publicfunctiongetType(): ?string
84+
{
85+
return$this->options['type'] ??null;
86+
}
87+
88+
publicfunctiongetTypeDetails(): ?string
89+
{
90+
return$this->options['type_details'] ??null;
91+
}
92+
93+
publicfunctiongetValidity(): ?int
94+
{
95+
return$this->options['validity'] ??null;
96+
}
97+
98+
publicfunctionsetCreatedDatetime(string$createdDatetime):self
99+
{
100+
$this->options['created_datetime'] =$createdDatetime;
101+
102+
return$this;
103+
}
104+
105+
publicfunctionsetDataCoding(string$dataCoding):self
106+
{
107+
$this->options['data_coding'] =$dataCoding;
108+
109+
return$this;
110+
}
111+
112+
publicfunctionsetFrom(string$from):self
113+
{
114+
$this->options['from'] =$from;
115+
116+
return$this;
117+
}
118+
119+
publicfunctionsetGateway(int$gateway):self
120+
{
121+
$this->options['gateway'] =$gateway;
122+
123+
return$this;
124+
}
125+
126+
publicfunctionsetGroupIds(array$groupIds):self
127+
{
128+
$this->options['group_ids'] =$groupIds;
129+
130+
return$this;
131+
}
132+
133+
publicfunctionsetMClass(int$mClass):self
134+
{
135+
$this->options['m_class'] =$mClass;
136+
137+
return$this;
138+
}
139+
140+
publicfunctionsetRecipientId(string$id):self
141+
{
142+
$this->options['recipient_id'] =$id;
143+
144+
return$this;
145+
}
146+
147+
publicfunctionsetReference(string$reference):self
148+
{
149+
$this->options['reference'] =$reference;
150+
151+
return$this;
152+
}
153+
154+
publicfunctionsetReportUrl(string$reportUrl):self
155+
{
156+
$this->options['report_url'] =$reportUrl;
157+
158+
return$this;
159+
}
160+
161+
publicfunctionsetScheduledDatetime(string$scheduledDatetime):self
162+
{
163+
$this->options['scheduled_datetime'] =$scheduledDatetime;
164+
165+
return$this;
166+
}
167+
168+
publicfunctionsetShortenUrls(bool$shortenUrls):self
169+
{
170+
$this->options['shorten_urls'] =$shortenUrls;
171+
172+
return$this;
173+
}
174+
175+
publicfunctionsetType(string$type):self
176+
{
177+
$this->options['type'] =$type;
178+
179+
return$this;
180+
}
181+
182+
publicfunctionsetTypeDetails(string$typeDetails):self
183+
{
184+
$this->options['type_details'] =$typeDetails;
185+
186+
return$this;
187+
}
188+
189+
publicfunctionsetValidity(int$validity):self
190+
{
191+
$this->options['validity'] =$validity;
192+
193+
return$this;
194+
}
195+
196+
publicfunctiontoArray():array
197+
{
198+
$options =$this->options;
199+
if (isset($options['recipient_id'])) {
200+
unset($options['recipient_id']);
201+
}
202+
203+
return$options;
204+
}
205+
}

‎src/Symfony/Component/Notifier/Bridge/MessageBird/MessageBirdTransport.php‎

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __toString(): string
4646

4747
publicfunctionsupports(MessageInterface$message):bool
4848
{
49-
return$messageinstanceof SmsMessage;
49+
return$messageinstanceof SmsMessage && (null ===$message->getOptions() ||$message->getOptions()instanceof MessageBirdOptions);
5050
}
5151

5252
protectedfunctiondoSend(MessageInterface$message):SentMessage
@@ -57,14 +57,56 @@ protected function doSend(MessageInterface $message): SentMessage
5757

5858
$from =$message->getFrom() ?:$this->from;
5959

60+
$opts =$message->getOptions();
61+
$options =$opts ?$opts->toArray() : [];
62+
$options['originator'] =$options['from'] ??$from;
63+
$options['recipients'] = [$message->getPhone()];
64+
$options['body'] =$message->getSubject();
65+
66+
if (isset($options['group_ids'])) {
67+
$options['groupIds'] =$options['group_ids'];
68+
unset($options['group_ids']);
69+
}
70+
71+
if (isset($options['report_url'])) {
72+
$options['reportUrl'] =$options['report_url'];
73+
unset($options['report_url']);
74+
}
75+
76+
if (isset($options['type_details'])) {
77+
$options['typeDetails'] =$options['type_details'];
78+
unset($options['type_details']);
79+
}
80+
81+
if (isset($options['data_coding'])) {
82+
$options['datacoding'] =$options['data_coding'];
83+
unset($options['data_coding']);
84+
}
85+
86+
if (isset($options['m_class'])) {
87+
$options['mclass'] =$options['m_class'];
88+
unset($options['m_class']);
89+
}
90+
91+
if (isset($options['shorten_urls'])) {
92+
$options['shortenUrls'] =$options['shorten_urls'];
93+
unset($options['shorten_urls']);
94+
}
95+
96+
if (isset($options['scheduled_datetime'])) {
97+
$options['scheduledDatetime'] =$options['scheduled_datetime'];
98+
unset($options['scheduled_datetime']);
99+
}
100+
101+
if (isset($options['created_datetime'])) {
102+
$options['createdDatetime'] =$options['created_datetime'];
103+
unset($options['created_datetime']);
104+
}
105+
60106
$endpoint =sprintf('https://%s/messages',$this->getEndpoint());
61107
$response =$this->client->request('POST',$endpoint, [
62108
'auth_basic' =>'AccessKey:'.$this->token,
63-
'body' => [
64-
'originator' =>$from,
65-
'recipients' =>$message->getPhone(),
66-
'body' =>$message->getSubject(),
67-
],
109+
'body' =>array_filter($options),
68110
]);
69111

70112
try {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\MessageBird\Tests;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Notifier\Bridge\MessageBird\MessageBirdOptions;
16+
17+
class MessageBirdOptionsTestextends TestCase
18+
{
19+
publicfunctiontestMessageBirdOptions()
20+
{
21+
$messageBirdOptions = (newMessageBirdOptions())->setFrom('test_from')->setType('test_type')->setScheduledDatetime('test_scheduled_datetime')->setCreatedDatetime('test_created_datetime')->setRecipientId('test_recipient')->setDataCoding('test_data_coding')->setGateway(999)->setGroupIds(['test_group_ids'])->setMClass(888)->setReference('test_reference')->setReportUrl('test_report_url')->setShortenUrls(true)->setTypeDetails('test_type_details')->setValidity(777);
22+
23+
self::assertSame([
24+
'from' =>'test_from',
25+
'type' =>'test_type',
26+
'scheduled_datetime' =>'test_scheduled_datetime',
27+
'created_datetime' =>'test_created_datetime',
28+
'data_coding' =>'test_data_coding',
29+
'gateway' =>999,
30+
'group_ids' => ['test_group_ids'],
31+
'm_class' =>888,
32+
'reference' =>'test_reference',
33+
'report_url' =>'test_report_url',
34+
'shorten_urls' =>true,
35+
'type_details' =>'test_type_details',
36+
'validity' =>777,
37+
],$messageBirdOptions->toArray());
38+
}
39+
}

‎src/Symfony/Component/Notifier/Bridge/MessageBird/Tests/MessageBirdTransportTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\Notifier\Bridge\MessageBird\Tests;
1313

1414
useSymfony\Component\HttpClient\MockHttpClient;
15+
useSymfony\Component\Notifier\Bridge\MessageBird\MessageBirdOptions;
1516
useSymfony\Component\Notifier\Bridge\MessageBird\MessageBirdTransport;
1617
useSymfony\Component\Notifier\Message\ChatMessage;
1718
useSymfony\Component\Notifier\Message\SmsMessage;
@@ -34,6 +35,7 @@ public static function toStringProvider(): iterable
3435
publicstaticfunctionsupportedMessagesProvider():iterable
3536
{
3637
yield [newSmsMessage('0611223344','Hello!')];
38+
yield [newSmsMessage('0611223344','Hello!','from',newMessageBirdOptions(['from' =>'foo']))];
3739
}
3840

3941
publicstaticfunctionunsupportedMessagesProvider():iterable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp