-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] [Mobyt] Change ctor signature and validate message types #39587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -33,11 +33,15 @@ final class MobytTransport extends AbstractTransport | |||||||||||||||||||||||||||||||||||||||
private $from; | ||||||||||||||||||||||||||||||||||||||||
private $typeQuality; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
public function __construct(string $accountSid, string $authToken, string $from, string $typeQuality, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) | ||||||||||||||||||||||||||||||||||||||||
public function __construct(string $accountSid, string $authToken, string $from, string $typeQuality = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null) | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want to make that parameter nullable anyway?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest that staying BC from the ctor signature is easier if the default value can be handled in the ctor itself, isn't it? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah and we need to know the default value in the transport factory too: symfony/src/Symfony/Component/Notifier/Bridge/Mobyt/MobytTransportFactory.php Lines 27 to 43 in 73509d9
By using null, only the transport sets and knows about the default value |
||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||
$this->accountSid = $accountSid; | ||||||||||||||||||||||||||||||||||||||||
$this->authToken = $authToken; | ||||||||||||||||||||||||||||||||||||||||
$this->from = $from; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
$typeQuality = $typeQuality ?? MobytOptions::MESSAGE_TYPE_QUALITY_LOW; | ||||||||||||||||||||||||||||||||||||||||
MobytOptions::validateMessageType($typeQuality); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
$this->typeQuality = $typeQuality; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
parent::__construct($client, $dispatcher); | ||||||||||||||||||||||||||||||||||||||||
|
@@ -77,14 +81,16 @@ protected function doSend(MessageInterface $message): SentMessage | |||||||||||||||||||||||||||||||||||||||
'user_key: '.$this->accountSid, | ||||||||||||||||||||||||||||||||||||||||
'Access_token: '.$this->authToken, | ||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||
'body' => json_encode(array_filter($options)), | ||||||||||||||||||||||||||||||||||||||||
'json' => array_filter($options), | ||||||||||||||||||||||||||||||||||||||||
]); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if (401 === $response->getStatusCode() || 404 === $response->getStatusCode()) { | ||||||||||||||||||||||||||||||||||||||||
$statusCode = $response->getStatusCode(); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if (401 === $statusCode || 404 === $statusCode) { | ||||||||||||||||||||||||||||||||||||||||
throw new TransportException(sprintf('Unable to send the SMS: "%s". Check your credentials.', $message->getSubject()), $response); | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if (201 !== $response->getStatusCode()) { | ||||||||||||||||||||||||||||||||||||||||
if (201 !== $statusCode) { | ||||||||||||||||||||||||||||||||||||||||
$error = $response->toArray(false); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
throw new TransportException(sprintf('Unable to send the SMS: "%s".', $error['result']), $response); | ||||||||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.