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

Commitc25cea7

Browse files
gnito-orgnicolas-grekas
authored andcommitted
[Notifier] Add SMS options to Esendex notifier
1 parent45113ba commitc25cea7

File tree

5 files changed

+118
-12
lines changed

5 files changed

+118
-12
lines changed

‎src/Symfony/Component/Notifier/Bridge/Esendex/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`EsendexOptions` class
8+
49
6.2
510
---
611

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\Esendex;
13+
14+
useSymfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
/**
17+
* @author gnito-org <https://github.com/gnito-org>
18+
*/
19+
finalclass EsendexOptionsimplements MessageOptionsInterface
20+
{
21+
privatearray$options;
22+
23+
publicfunction__construct(array$options = [])
24+
{
25+
$this->options =$options;
26+
}
27+
28+
publicfunctiongetAccountReference(): ?string
29+
{
30+
return$this->options['account_reference'] ??null;
31+
}
32+
33+
publicfunctiongetFrom(): ?string
34+
{
35+
return$this->options['from'] ??null;
36+
}
37+
38+
publicfunctiongetRecipientId(): ?string
39+
{
40+
return$this->options['recipient_id'] ??null;
41+
}
42+
43+
publicfunctionsetAccountReference(string$accountReference):self
44+
{
45+
$this->options['account_reference'] =$accountReference;
46+
47+
return$this;
48+
}
49+
50+
publicfunctionsetFrom(string$from):self
51+
{
52+
$this->options['from'] =$from;
53+
54+
return$this;
55+
}
56+
57+
publicfunctionsetRecipientId(string$id):self
58+
{
59+
$this->options['recipient_id'] =$id;
60+
61+
return$this;
62+
}
63+
64+
publicfunctiontoArray():array
65+
{
66+
$options =$this->options;
67+
if (isset($options['recipient_id'])) {
68+
unset($options['recipient_id']);
69+
}
70+
71+
return$options;
72+
}
73+
}

‎src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __toString(): string
4949

5050
publicfunctionsupports(MessageInterface$message):bool
5151
{
52-
return$messageinstanceof SmsMessage;
52+
return$messageinstanceof SmsMessage && (null ===$message->getOptions() ||$message->getOptions()instanceof EsendexOptions);
5353
}
5454

5555
protectedfunctiondoSend(MessageInterface$message):SentMessage
@@ -58,26 +58,24 @@ protected function doSend(MessageInterface $message): SentMessage
5858
thrownewUnsupportedMessageTypeException(__CLASS__, SmsMessage::class,$message);
5959
}
6060

61-
$messageData = [
61+
$from =$message->getFrom() ?:$this->from;
62+
63+
$opts =$message->getOptions();
64+
$options =$opts ?$opts->toArray() : [];
65+
$options['from'] =$options['from'] ??$from;
66+
$options['messages'] = [
6267
'to' =>$message->getPhone(),
6368
'body' =>$message->getSubject(),
6469
];
65-
66-
if ('' !==$message->getFrom()) {
67-
$messageData['from'] =$message->getFrom();
68-
}elseif (null !==$this->from) {
69-
$messageData['from'] =$this->from;
70-
}
70+
$options['accountreference'] =$options['account_reference'] ??$this->accountReference;
71+
unset($options['account_reference']);
7172

7273
$response =$this->client->request('POST','https://'.$this->getEndpoint().'/v1.0/messagedispatcher', [
7374
'auth_basic' =>sprintf('%s:%s',$this->email,$this->password),
7475
'headers' => [
7576
'Accept' =>'application/json',
7677
],
77-
'json' => [
78-
'accountreference' =>$this->accountReference,
79-
'messages' => [$messageData],
80-
],
78+
'json' =>array_filter($options),
8179
]);
8280

8381
try {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\Esendex\Tests;
13+
14+
usePHPUnit\Framework\TestCase;
15+
useSymfony\Component\Notifier\Bridge\Esendex\EsendexOptions;
16+
17+
class EsendexOptionsTestextends TestCase
18+
{
19+
publicfunctiontestEsendexOptions()
20+
{
21+
$esendexOptions = (newEsendexOptions())->setFrom('test_from')->setAccountReference('test_account_reference')->setRecipientId('test_recipient');
22+
23+
self::assertSame([
24+
'from' =>'test_from',
25+
'account_reference' =>'test_account_reference',
26+
],$esendexOptions->toArray());
27+
}
28+
}

‎src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php‎

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

1414
useSymfony\Component\HttpClient\MockHttpClient;
15+
useSymfony\Component\Notifier\Bridge\Esendex\EsendexOptions;
1516
useSymfony\Component\Notifier\Bridge\Esendex\EsendexTransport;
1617
useSymfony\Component\Notifier\Exception\TransportException;
1718
useSymfony\Component\Notifier\Message\ChatMessage;
@@ -36,6 +37,7 @@ public function toStringProvider(): iterable
3637
publicfunctionsupportedMessagesProvider():iterable
3738
{
3839
yield [newSmsMessage('0611223344','Hello!')];
40+
yield [newSmsMessage('0611223344','Hello!','from',newEsendexOptions(['from' =>'foo']))];
3941
}
4042

4143
publicfunctionunsupportedMessagesProvider():iterable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp