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

Skip to content

Commit 2e07b05

Browse files
[Notifier] Bring consistency to bridges
1 parent 725fac4 commit 2e07b05

File tree

82 files changed

+552
-1599
lines changed

Some content is hidden

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

82 files changed

+552
-1599
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 = $options;
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/AmazonSns/AmazonSnsTransport.php

Lines changed: 9 additions & 2 deletions
< 741A td data-grid-cell-id="diff-83949de14c9a1641d3989dfa765e548ddb6a1f1774e0507ece9c90f1a599faca-61-61-2" data-line-anchor="diff-83949de14c9a1641d3989dfa765e548ddb6a1f1774e0507ece9c90f1a599facaR61" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
if ($message instanceof ChatMessage && $message->getOptions() instanceof AmazonSnsOptions) {
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,23 @@ protected function doSend(MessageInterface $message): SentMessage
6060

6161
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

src/Symfony/Component/Notifier/Bridge/Bandwidth/BandwidthOptions.php

Lines changed: 28 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,121 +25,73 @@ public function __construct(array $options = [])
2525
$this->options = $options;
2626
}
2727

28-
public function getAccountId(): ?string
29-
{
30-
return $this->options['account_id'] ?? null;
31-
}
32-
33-
public function getApplicationId(): ?string
34-
{
35-
return $this->options['application_id'] ?? null;
36-
}
37-
38-
public function getExpiration(): ?string
39-
{
40-
return $this->options['expiration'] ?? null;
41-
}
42-
43-
public function getFrom(): ?string
44-
{
45-
return $this->options['from'] ?? null;
46-
}
47-
48-
public function getMedia(): ?array
49-
{
50-
return $this->options['media'] ?? null;
51-
}
52-
53-
public function getPriority(): ?string
54-
{
55-
return $this->options['priority'] ?? null;
56-
}
57-
5828
public function getRecipientId(): ?string
5929
{
60-
return $this->options['recipient_id'] ?? null;
61-
}
62-
63-
public function getTag(): ?string
64-
{
65-
return $this->options['tag'] ?? null;
30+
return null;
6631
}
6732

68-
public function getTo(): ?array
33+
/**
34+
* @return $this
35+
*/
36+
public function accountId(string $accountId): static
6937
{
70-
return $this->options['to'] ?? null;
71-
}
72-
73-
public function setAccountId(string $accountId): self
74-
{
75-
$this->options['account_id'] = $accountId;
38+
$this->options['accountId'] = $accountId;
7639

7740
return $this;
7841
}
7942

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

8450
return $this;
8551
}
8652

87-
public function setExpiration(string $expiration): self
53+
/**
54+
* @return $this
55+
*/
56+
public function expiration(string $expiration): static
8857
{
8958
$this->options['expiration'] = $expiration;
9059

9160
return $this;
9261
}
9362

94-
public function setFrom(string $from): self
95-
{
96-
$this->options['from'] = $from;
97-
98-
return $this;
99-
}
100-
101-
public function setMedia(array $media): self
63+
/**
64+
* @return $this
65+
*/
66+
public function media(array $media): static
10267
{
10368
$this->options['media'] = $media;
10469

10570
return $this;
10671
}
10772

108-
public function setPriority(string $priority): self
73+
/**
74+
* @return $this
75+
*/
76+
public function priority(string $priority): static
10977
{
11078
$this->options['priority'] = $priority;
11179

11280
return $this;
11381
}
11482

115-
public function setRecipientId(string $id): self
116-
{
117-
$this->options['recipient_id'] = $id;
118-
119-
return $this;
120-
}
121-
122-
public function setTag(string $tag): self
83+
/**
84+
* @return $this
85+
*/
86+
public function tag(string $tag): static
12387
{
12488
$this->options['tag'] = $tag;
12589

12690
return $this;
12791
}
12892

129-
public function setTo(array $to): self
130-
{
131-
$this->options['to'] = $to;
132-
133-
return $this;
134-
}
135-
13693
public function toArray(): array
13794
{
138-
$options = $this->options;
139-
if (isset($options['recipient_id'])) {
140-
unset($options['recipient_id']);
141-
}
142-
143-
return $options;
95+
return $this->options;
14496
}
14597
}

0 commit comments

Comments
 (0)
0