Skip to content

Commit

Permalink
feature #45951 [Notifier] [OvhCloud] Add no_stop_clause to DSN (ala…
Browse files Browse the repository at this point in the history
…mirault)

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
  • Loading branch information
fabpot committed Apr 8, 2022
2 parents fb40adc + 0999ac0 commit f923f15
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
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 comments on commit f923f15

Please sign in to comment.