8000 [Notifier] Bring consistency to bridges · symfony/symfony@657e9be · GitHub
[go: up one dir, main page]

Skip to content

Commit 657e9be

Browse files
[Notifier] Bring consistency to bridges
1 parent 725fac4 commit 657e9be

File tree

109 files changed

+681
-1833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+681
-1833
lines changed

src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsOptions.php

Lines changed: 33 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -25,108 +25,75 @@ public function __construct(array $options = [])
2525
$this->options = $op 10000 tions;
2626
}
2727

28-
public function getAlerting(): ?int
29-
{
30-
return $this->options['alerting'] ?? null;
31-
}
32-
33-
public function getCampaignName(): ?string
34-
{
35-
return $this->options['campaign_name'] ?? null;
36-
}
37-
38-
public function getCliMsgId(): ?string
39-
{
40-
return $this->options['cli_msg_id'] ?? null;
41-
}
42-
43-
public function getDate(): ?string
44-
{
45-
return $this->options['date'] ?? null;
46-
}
47-
48-
public function getFrom(): ?string
49-
{
50-
return $this->options['from'] ?? null;
51-
}
52-
5328
public function getRecipientId(): ?string
5429
{
55-
return $this->options['recipient_id'] ?? null;
56-
}
57-
58-
public function getSimulate(): ?int
59-
{
60-
return $this->options['simulate'] ?? null;
30+
return null;
6131
}
6232

63-
public function getUniqueIdentifier(): ?string
64-
{
65-
return $this->options['unique_identifier'] ?? null;
66-
}
67-
68-
public function getVerbose(): ?int
69-
{
70-
return $this->options['verbose'] ?? null;
71-
}
72-
73-
public function setAlerting(int $alerting): self
33+
/**
34+
* @return $this
35+
*/
36+
public function alerting(int $alerting): static
7437
{
7538
$this->options['alerting'] = $alerting;
7639

7740
return $this;
7841
}
7942

80-
public function setCampaignName(string $campaignName): self
43+
/**
44+
* @return $this
45+
*/
46+
public function campaignName(string $campaignName): static
8147
{
82-
$this->options['campaign_name'] = $campaignName;
48+
$this->options['campaignName'] = $campaignName;
8349

8450
return $this;
8551
}
8652

87-
public function setCliMsgId(string $cliMsgId): self
53+
/**
54+
* @return $this
55+
*/
56+
public function cliMsgId(string $cliMsgId): static
8857
{
89-
$this->options['cli_msg_id'] = $cliMsgId;
58+
$this->options['cliMsgId'] = $cliMsgId;
9059

9160
return $this;
9261
}
9362

94-
public function setDate(string $date): self
63+
/**
64+
* @return $this
65+
*/
66+
public function date(string $date): static
9567
{
9668
$this->options['date'] = $date;
9769

9870
return $this;
9971
}
10072

101-
public function setFrom(string $from): self
102-
{
103-
$this->options['from'] = $from;
104-
105-
return $this;
106-
}
107-
108-
public function setRecipientId(string $id): self
109-
{
110-
$this->options['recipient_id'] = $id;
111-
112-
return $this;
113-
}
114-
115-
public function setSimulate(int $simulate): self
73+
/**
74+
* @return $this
75+
*/
76+
public function simulate(int $simulate): static
11677
{
11778
$this->options['simulate'] = $simulate;
11879

11980
return $this;
12081
}
12182

122-
public function setUniqueIdentifier(string $uniqueIdentifier): self
83+
/**
84+
* @return $this
85+
*/
86+
public function uniqueIdentifier(string $uniqueIdentifier): static
12387
{
124-
$this->options['unique_identifier'] = $uniqueIdentifier;
88+
$this->options['uniqueIdentifier'] = $uniqueIdentifier;
12589

12690
return $this;
12791
}
12892

129-
public function setVerbose(int $verbose): self
93+
/**
94+
* @return $this
95+
*/
96+
public function verbose(int $verbose): static
13097
{
13198
$this->options['verbose'] = $verbose;
13299

@@ -135,11 +102,6 @@ public function setVerbose(int $verbose): self
135102

136103
public function toArray(): array
137104
{
138-
$options = $this->options;
139-
if (isset($options['recipient_id'])) {
140-
unset($options['recipient_id']);
141-
}
142-
143-
return $options;
105+
return $this->options;
144106
}
145107
}

src/Symfony/Component/Notifier/Bridge/AllMySms/AllMySmsTransport.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public function __construct(string $login, #[\SensitiveParameter] string $apiKey
4343

4444
public function __toString(): string
4545
{
46-
if (null !== $this->from) {
47-
return sprintf('allmysms://%s?from=%s', $this->getEndpoint(), $this->from);
48-
}
49-
50-
return sprintf('allmysms://%s', $this->getEndpoint());
46+
return sprintf('allmysms://%s%s', $this->getEndpoint(), null !== $this->from ? '?from='.$this->from : '');
5147
}
5248

5349
public function supports(MessageInterface $message): bool
@@ -61,32 +57,14 @@ protected function doSend(MessageInterface $message): SentMessage
6157
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
6258
}
6359

64-
$from = $message->getFrom() ?: $this->from;
65-
66-
$opts = $message->getOptions();
67-
$options = $opts ? $opts->toArray() : [];
68-
$options['from'] = $options['from'] ?? $from;
60+
$options = $message->getOptions()?->toArray() ?? [];
61+
$options['from'] = $message->getFrom() ?: $this->from;
6962
$options['to'] = $message->getPhone();
7063
$options['text'] = $message->getSubject();
7164

72-
if (isset($options['campaign_name'])) {
73-
$options['campaignName'] = $options['campaign_name'];
74-
unset($options['campaign_name']);
75-
}
76-
77-
if (isset($options['cli_msg_id'])) {
78-
$options['cliMsgId'] = $options['cli_msg_id'];
79-
unset($options['cli_msg_id']);
80-
}
81-
82-
if (isset($options['unique_identifier'])) {
83-
$options['uniqueIdentifier'] = $options['unique_identifier'];
84-
unset($options['unique_identifier']);
85-
}
86-
8765
$endpoint = sprintf('https://%s/sms/send/', $this->getEndpoint());
8866
$response = $this->client->request('POST', $endpoint, [
89-
'auth_basic' => $this->login.':'.$this->apiKey,
67+
'auth_basic' => [$this->login, $this->apiKey],
9068
'json' => array_filter($options),
9169
]);
9270

src/Symfony/Component/Notifier/Bridge/AllMySms/Tests/AllMySmsOptionsTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ class AllMySmsOptionsTest extends TestCase
1818
{
1919
public function testAllMySmsOptions()
2020
{
21-
$allMySmsOptions = (new AllMySmsOptions())->setFrom('test_from')->setAlerting(1)->setDate('test_date')->setCampaignName('test_campaign_name')->setRecipientId('test_recipient')->setCliMsgId('test_cli_msg_id')->setSimulate(1)->setUniqueIdentifier('test_unique_identifier')->setVerbose(1);
21+
$allMySmsOptions = (new AllMySmsOptions())
22+
->alerting(1)
23+
->date('test_date')
24+
->campaignName('test_campaign_name')
25+
->cliMsgId('test_cli_msg_id')
26+
->simulate(1)
27+
->uniqueIdentifier('test_unique_identifier')
28+
->verbose(1);
2229

2330
self::assertSame([
24-
'from' => 'test_from',
2531
'alerting' => 1,
2632
'date' => 'test_date',
27-
'campaign_name' => 'test_campaign_name',
28-
'cli_msg_id' => 'test_cli_msg_id',
33+
'campaignName' => 'test_campaign_name',
34+
'cliMsgId' => 'test_cli_msg_id',
2935
'simulate' => 1,
30-
'unique_identifier' => 'test_unique_identifier',
36+
'uniqueIdentifier' => 'test_unique_identifier',
3137
'verbose' => 1,
3238
], $allMySmsOptions->toArray());
3339
}

src/Symfony/Component/Notifier/Bridge/AmazonSns/AmazonSnsTransport.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,23 @@ protected function doSend(MessageInterface $message): SentMessage
6060

6161
if ($message instanceof ChatMessage && $message->getOptions() instanceof AmazonSnsOptions) {
6262
$options = $message->getOptions()->toArray();
63+
} else {
64+
$options = [];
6365
}
6466
$options['Message'] = $message->getSubject();
65-
$options[($message instanceof ChatMessage) ? 'TopicArn' : 'PhoneNumber'] = $message->getRecipientId();
67+
68+
if ($message instanceof SmsMessage) {
69+
$options['PhoneNumber'] = $message->getPhone();
70+
} else {
71+
$options['TopicArn'] = $message->getRecipientId();
72+
}
6673

6774
try {
6875
$response = $this->snsClient->publish($options);
6976
$message = new SentMessage($message, (string) $this);
7077
$message->setMessageId($response->getMessageId());
7178
} catch (\Exception $exception) {
72-
$info = isset($response) ? $response->info() : [];
79+
$info = $response?->info() ?? [];
7380
throw new TransportException('Unable to send the message.', $info['response'] ?? null, $info['status'] ?? 0, $exception);
7481
}
7582

0 commit comments

Comments
 (0)
0