10000 [Notifier] [OvhCloud] Add `no_stop_clause` to DSN by alamirault · Pull Request #45951 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] [OvhCloud] Add no_stop_clause to DSN #45951

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
---

* Add `no_stop_clause` option to the DSN that allows removing "STOP clause" at the end of the message for non-commercial use

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class OvhCloudTransport extends AbstractTransport
private string $consumerKey;
private string $serviceName;
private ?string $sender = null;
private bool $noStopClause = false;

public function __construct(string $applicationKey, string $applicationSecret, string $consumerKey, string $serviceName, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
Expand All @@ -47,10 +48,20 @@ public function __construct(string $applicationKey, string $applicationSecret, s
public function __toString(): string
{
if (null !== $this->sender) {
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&sender=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, $this->sender);
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);
}

return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName);
return sprintf('ovhcloud://%s?consumer_key=%s&service_name=%s&no_stop_clause=%s', $this->getEndpoint(), $this->consumerKey, $this->serviceName, (int) $this->noStopClause);
}

/**
* @return $this
*/
public function setNoStopClause(bool $noStopClause): static
{
$this->noStopClause = $noStopClause;

return $this;
}

/**
Expand Down Expand Up @@ -82,7 +93,7 @@ protected function doSend(MessageInterface $message): SentMessage
'coding' => '8bit',
'message' => $message->getSubject(),
'receivers' => [$message->getPhone()],
'noStopClause' => false,
'noStopClause' => $this->noStopClause,
'priority' => 'medium',
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ public function create(Dsn $dsn): OvhCloudTransport
$consumerKey = $dsn->getRequiredOption('consumer_key');
$serviceName = $dsn->getRequiredOption('service_name');
$sender = $dsn->getOption('sender');
$noStopClause = filter_var($dsn->getOption('no_stop_clause', false), \FILTER_VALIDATE_BOOLEAN);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port)->setSender($sender);
return (new OvhCloudTransport($applicationKey, $applicationSecret, $consumerKey, $serviceName, $this->client, $this->dispatcher))->setHost($host)->setPort($port)->setSender($sender)->setNoStopClause($noStopClause);
}

protected function getSupportedSchemes(): array
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DSN example
-----------

```
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME&sender=SENDER
OVHCLOUD_DSN=ovhcloud://APPLICATION_KEY:APPLICATION_SECRET@default?consumer_key=CONSUMER_KEY&service_name=SERVICE_NAME&sender=SENDER&no_stop_clause=NO_STOP_CLAUSE
```

where:
Expand All @@ -16,6 +16,8 @@ where:
- `CONSUMER_KEY` is your OvhCloud consumer key
- `SERVICE_NAME` is your OvhCloud service name
- `SENDER` is your sender (optional)
- `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)


Resources
---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,35 @@ public function createFactory(): OvhCloudTransportFactory
public function createProvider(): iterable
{
yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName',
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName',
];

yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender&no_stop_clause=0',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&sender=sender',
];

yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=0',
];

yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
];

yield [
'ovhcloud://host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=1',
'ovhcloud://key:secret@host.test?consumer_key=consumerKey&service_name=serviceName&no_stop_clause=true',
];
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@

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

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

public function supportedMessagesProvider(): iterable
Expand Down
0