8000 feature #40377 [Notifier] [OvhCloud] Add "sender" (notFloran) · symfony/symfony@d752c1e · GitHub
[go: up one dir, main page]

Skip to content

Commit d752c1e

Browse files
committed
feature #40377 [Notifier] [OvhCloud] Add "sender" (notFloran)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Notifier] [OvhCloud] Add "sender" | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> (I'm waiting to see if the feature is accepted ) Add "sender" option to the DSN that allows configuring the sender of the message. OVHCloud manages two cases for sending sms according to the [doc](https://docs.ovh.com/fr/sms/envoyer_des_sms_avec_lapi_ovh_en_php/): > The senderForResponse parameter will allow the use of a short number, which allows you to send SMS directly without having to create an alphanumeric sender (for example: your name). > Short numbers also allow you to receive responses from the recipients of your SMS, which can be useful for a satisfaction survey, a voting application, a game, etc. ![CleanShot 2021-03-05 at 13 26 33](https://user-images.githubusercontent.com/523981/110115554-84c5af80-7db6-11eb-815d-7e8bafa81e5d.png) This PR introduces the management of these 2 cases with a new option `sender`: * if `sender` is set, we use it * if `sender` is not set, we use `senderForResponse` to get a short number (current behavior) I took the logic implementedin the old official SDK : https://github.com/ovh/php-ovh-sms/blob/52d279e112a7da8f897745acab32a887321e03f1/src/Message.php#L161 Commits ------- c5a9b25 [Notifier] [OvhCloud] Add "sender"
2 parents 25e8d7d + c5a9b25 commit d752c1e
Copy full SHA for d752c1e

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.3
55
---
66

7+
* Add `sender` option to the DSN that allows configuring the sender
78
* The bridge is not marked as `@experimental` anymore
89

910
5.1.0

src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ final class OvhCloudTransport extends AbstractTransport
3131
private $applicationSecret;
3232
private $consumerKey;
3333
private $serviceName;
34+
private $sender;
3435

3536
public function __construct(string $applicationKey, string $applicationSecret, string $consumerKey, string $serviceName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3637
{
@@ -44,9 +45,20 @@ public function __construct(string $applicationKey, string $applicationSecret, s
4445

4546
public function __toString(): string
4647
{
48+
if (null !== $this->sender) {
49+
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&sender=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, $this->sender);
50+
}
51+
4752
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName);
4853
}
4954

55+
public function setSender(?string $sender): self
56+
{
57+
$this->sender = $sender;
58+
59+
return $this;
60+
}
61+
5062
public function supports(MessageInterface $message): bool
5163
{
5264
return $message instanceof SmsMessage;
@@ -68,9 +80,14 @@ protected function doSend(MessageInterface $message): SentMessage
6880
'receivers' => [$message->getPhone()],
6981
'noStopClause' => false,
7082
'priority' => 'medium',
71-
'senderForResponse' => true,
7283
];
7384

85+
if ($this->sender) {
86+
$content['sender'] = $this->sender;
87+
} else {
88+
$content['senderForResponse'] = true;
89+
}
90+
7491
$now = time() + $this->calculateTimeDelta();
7592
$headers['X-Ovh-Application'] = $this->applicationKey;
7693
$headers['X-Ovh-Timestamp'] = $now;

src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ public function create(Dsn $dsn): TransportInterface
3333
$applicationSecret = $this->getPassword($dsn);
3434
$consumerKey = $dsn->getRequiredOption('consumer_key');
3535
$serviceName = $dsn->getRequiredOption('service_name');
36+
$sender = $dsn->getOption('sender');
3637
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3738
$port = $dsn->getPort();
3839

39-
return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
40+
return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port)->setSender($sender);
4041
}
4142

4243
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ DSN example
77
-----------
88

99
```
10-
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME
10+
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME&sender=SENDER
1111
```
1212

1313
where:
1414
- `APPLICATION_KEY` is your OvhCloud application key
1515
- `APPLICATION_SECRET` is your OvhCloud application secret
1616
- `CONSUMER_KEY` is your OvhCloud consumer key
1717
- `SERVICE_NAME` is your OvhCloud service name
18+
- `SENDER` is your sender (optional)
1819

1920
Resources
2021
---------

src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ public function createProvider(): iterable
3131
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName',
3232
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName',
3333
];
34+
35+
yield [
36+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
37+
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
38+
];
3439
}
3540

3641
public function supportsProvider(): iterable
3742
{
38-
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
39-
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
43+
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
44+
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
4045
}
4146

4247
public function missingRequiredOptionProvider(): iterable
@@ -47,8 +52,9 @@ public function missingRequiredOptionProvider(): iterable
4752

4853
public function unsupportedSchemeProvider(): iterable
4954
{
50-
yield ['somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName'];
55+
yield ['somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
5156
yield ['somethingElse://key:secret@default?service_name=serviceName'];
5257
yield ['somethingElse://key:secret@default?consumer_key=consumerKey'];
58+
yield ['somethingElse://key:secret@default?sender=sender'];
5359
}
5460
}

src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ final class OvhCloudTransportTest extends TransportTestCase
2626
/**
2727
* @return OvhCloudTransport
2828
*/
29-
public function createTransport(?HttpClientInterface $client = null): TransportInterface
29+
public function createTransport(?HttpClientInterface $client = null, string $sender = null): TransportInterface
3030
{
31-
return new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class));
31+
return (new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?: $this->createMock(HttpClientInterface::class)))->setSender($sender);
3232
}
3333

3434
public function toStringProvider(): iterable
3535
{
3636
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName', $this->createTransport()];
37+
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&sender=sender', $this->createTransport(null, 'sender')];
3738
}
3839

3940
public function supportedMessagesProvider(): iterable

0 commit comments

Comments
 (0)
0