Skip to content

Commit

Permalink
[Notifier] Bring consistency to bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 12, 2023
1 parent 3d5c866 commit 18d7f4d
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions SmsFactorTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ public function __construct(#[\SensitiveParameter] string $tokenApi, ?string $se

public function __toString(): string
{
$arguments = [];
if (null !== $this->sender) {
$arguments[] = sprintf('sender=%s', $this->sender);
}

if (null !== $this->pushType) {
$arguments[] = sprintf('push_type=%s', $this->pushType->value);
}
$query = array_filter([
'sender' => $this->sender,
'push_type' => $this->pushType?->value,
]);

return sprintf('sms-factor://%s?%s', $this->getEndpoint(), implode('&', $arguments));
return sprintf('sms-factor://%s%s', $this->getEndpoint(), $query ? '?'.http_build_query($query, '', '&') : '');
}

public function supports(MessageInterface $message): bool
Expand All @@ -71,22 +67,14 @@ protected function doSend(MessageInterface $message): SentMessage
'to' => $message->getPhone(),
'text' => $message->getSubject(),
'gsmsmsid' => $messageId,
'sender' => $message->getFrom() ?: $this->sender,
'pushtype' => $this->pushType?->value,
];

if ('' !== $message->getFrom()) {
$query['sender'] = $message->getFrom();
} elseif (null !== $this->sender) {
$query['sender'] = $this->sender;
}

if (null !== $this->pushType) {
$query['pushtype'] = $this->pushType->value;
}

$response = $this->client->request('GET', 'https://'.$this->getEndpoint().'/send', [
'query' => $query,
'query' => array_filter($query),
'auth_bearer' => $this->tokenApi,
'headers' => [
'Authorization' => sprintf('Bearer %s', $this->tokenApi),
'Accept' => 'application/json',
],
]);
Expand Down

0 comments on commit 18d7f4d

Please sign in to comment.