Skip to content

Commit f923f15

Browse files
committed
feature #45951 [Notifier] [OvhCloud] Add no_stop_clause to DSN (alamirault)
This PR was squashed before being merged into the 6.1 branch. Discussion ---------- [Notifier] [OvhCloud] Add `no_stop_clause` to DSN | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #45932 | License | MIT This PR allow to configure `no_stop_clause` (default false) for OvhCloud. Was always false before. Commits ------- 0999ac0 [Notifier] [OvhCloud] Add `no_stop_clause` to DSN
2 parents fb40adc + 0999ac0 commit f923f15

File tree

6 files changed

+47
-11
lines changed

6 files changed

+47
-11
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Add `no_stop_clause` option to the DSN that allows removing "STOP clause" at the end of the message for non-commercial use
8+
49
5.3
510
---
611

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ final class OvhCloudTransport extends AbstractTransport
3333
private string $consumerKey;
3434
private string $serviceName;
3535
private ?string $sender = null;
36+
private bool $noStopClause = false;
3637

3738
public function __construct(string $applicationKey, string $applicationSecret, string $consumerKey, string $serviceName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3839
{
@@ -47,10 +48,20 @@ public function __construct(string $applicationKey, string $applicationSecret, s
4748
public function __toString(): string
4849
{
4950
if (null !== $this->sender) {
50-
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&sender=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, $this->sender);
51+
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&sender=%s&no_stop_clause=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, $this->sender, (int) $this->noStopClause);
5152
}
5253

53-
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName);
54+
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&no_stop_clause=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, (int) $this->noStopClause);
55+
}
56+
57+
/**
58+
* @return $this
59+
*/
60+
public function setNoStopClause(bool $noStopClause): static
61+
{
62+
$this->noStopClause = $noStopClause;
63+
64+
return $this;
5465
}
5566

5667
/**
@@ -82,7 +93,7 @@ protected function doSend(MessageInterface $message): SentMessage
8293
'coding' => '8bit',
8394
'message' => $message->getSubject(),
8495
'receivers' => [$message->getPhone()],
85-
'noStopClause' => false,
96+
'noStopClause' => $this->noStopClause,
8697
'priority' => 'medium',
8798
];
8899

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): OvhCloudTransport
3333
$consumerKey = $dsn->getRequiredOption('consumer_key');
3434
$serviceName = $dsn->getRequiredOption('service_name');
3535
$sender = $dsn->getOption('sender');
36+
$noStopClause = filter_var($dsn->getOption('no_stop_clause', false), \FILTER_VALIDATE_BOOLEAN);
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)->setSender($sender);
40+
return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port)->setSender($sender)->setNoStopClause($noStopClause);
4041
}
4142

4243
protected function getSupportedSchemes(): array

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

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

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

1313
where:
@@ -16,6 +16,8 @@ where:
1616
- `CONSUMER_KEY` is your OvhCloud consumer key
1717
- `SERVICE_NAME` is your OvhCloud service name
1818
- `SENDER` is your sender (optional)
19+
- `NO_STOP_CLAUSE` setting this parameter to "1" (default "0") allow removing "STOP clause" at the end of the message for non-commercial use (optional)
20+
1921

2022
Resources
2123
---------

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,35 @@ public function createFactory(): OvhCloudTransportFactory
2424
public function createProvider(): iterable
2525
{
2626
yield [
27-
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName',
27+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
2828
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName',
2929
];
3030

3131
yield [
32-
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
32+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender&no_stop_clause=0',
3333
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
3434
];
35+
36+
yield [
37+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
38+
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
39+
];
40+
41+
yield [
42+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
43+
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
44+
];
45+
46+
yield [
47+
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
48+
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=true',
49+
];
3550
}
3651

3752
public function supportsProvider(): iterable
3853
{
3954
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
55+
yield [true, 'ovhcloud://key:secret@default?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1'];
4056
yield [false, 'somethingElse://key:secret@default?consumer_key=consumerKey&service_name=serviceName&sender=sender'];
4157
}
4258

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222

2323
final class OvhCloudTransportTest extends TransportTestCase
2424
{
25-
public function createTransport(HttpClientInterface $client = null, string $sender = null): OvhCloudTransport
25+
public function createTransport(HttpClientInterface $client = null, string $sender = null, bool $noStopClause = false): OvhCloudTransport
2626
{
27-
return (new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?? $this->createMock(HttpClientInterface::class)))->setSender($sender);
27+
return (new OvhCloudTransport('applicationKey', 'applicationSecret', 'consumerKey', 'serviceName', $client ?? $this->createMock(HttpClientInterface::class)))->setSender($sender)->setNoStopClause($noStopClause);
2828
}
2929

3030
public function toStringProvider(): iterable
3131
{
32-
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName', $this->createTransport()];
33-
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&sender=sender', $this->createTransport(null, 'sender')];
32+
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0', $this->createTransport()];
33+
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1', $this->createTransport(null, null, true)];
34+
yield ['ovhcloud://eu.api.ovh.com?consumer_key=consumerKey&service_name=serviceName&sender=sender&no_stop_clause=0', $this->createTransport(null, 'sender')];
3435
}
3536

3637
public function supportedMessagesProvider(): iterable

0 commit comments

Comments
 (0)