From 0999ac0dd3a77506605bd4494e12a716b318e9dd Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Wed, 6 Apr 2022 00:14:12 +0200 Subject: [PATCH] [Notifier] [OvhCloud] Add `no_stop_clause` to DSN --- .../Notifier/Bridge/OvhCloud/CHANGELOG.md | 5 +++++ .../Bridge/OvhCloud/OvhCloudTransport.php | 17 +++++++++++++--- .../OvhCloud/OvhCloudTransportFactory.php | 3 ++- .../Notifier/Bridge/OvhCloud/README.md | 4 +++- .../Tests/OvhCloudTransportFactoryTest.php | 20 +++++++++++++++++-- .../OvhCloud/Tests/OvhCloudTransportTest.php | 9 +++++---- 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md b/src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md index 7c63c37954208..d2392fc9757e8 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/CHANGELOG.md @@ -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 --- diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php b/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php index 3a06b5ce5de70..7f419d33e2bde 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransport.php @@ -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) { @@ -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; } /** @@ -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', ]; diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php b/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php index a2caa5dc789fa..a76338ff69fda 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php @@ -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 diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md b/src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md index f1200f0863002..5908ca65b5037 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/README.md @@ -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: @@ -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 --------- diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php index d50fd07ac7f47..1d4a2c893e746 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportFactoryTest.php @@ -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']; } diff --git a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php index 806dad21b932c..f0678323788fa 100644 --- a/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/OvhCloud/Tests/OvhCloudTransportTest.php @@ -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