Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit25486e5

Browse files
imadzairigimad
imad
authored andcommitted
Add Prelude Notifier for SMS
1 parent1f337e8 commit25486e5

File tree

17 files changed

+559
-0
lines changed

17 files changed

+559
-0
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,6 +3270,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
32703270
NotifierBridge\OvhCloud\OvhCloudTransportFactory::class =>'notifier.transport_factory.ovh-cloud',
32713271
NotifierBridge\PagerDuty\PagerDutyTransportFactory::class =>'notifier.transport_factory.pager-duty',
32723272
NotifierBridge\Plivo\PlivoTransportFactory::class =>'notifier.transport_factory.plivo',
3273+
NotifierBridge\Prelude\PreludeTransportFactory::class =>'notifier.transport_factory.prelude',
32733274
NotifierBridge\Primotexto\PrimotextoTransportFactory::class =>'notifier.transport_factory.primotexto',
32743275
NotifierBridge\Pushover\PushoverTransportFactory::class =>'notifier.transport_factory.pushover',
32753276
NotifierBridge\Pushy\PushyTransportFactory::class =>'notifier.transport_factory.pushy',

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
'orange-sms' =>Bridge\OrangeSms\OrangeSmsTransportFactory::class,
9090
'ovh-cloud' =>Bridge\OvhCloud\OvhCloudTransportFactory::class,
9191
'plivo' =>Bridge\Plivo\PlivoTransportFactory::class,
92+
'prelude' =>Bridge\Prelude\PreludeTransportFactory::class,
9293
'primotexto' =>Bridge\Primotexto\PrimotextoTransportFactory::class,
9394
'pushover' =>Bridge\Pushover\PushoverTransportFactory::class,
9495
'pushy' =>Bridge\Pushy\PushyTransportFactory::class,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Testsexport-ignore
2+
/phpunit.xml.distexport-ignore
3+
/.git*export-ignore

‎src/Symfony/Component/Notifier/Bridge/Prelude/.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/Symfony/Component/Notifier/Bridge/Prelude/.github/workflows/close-pull-request.yml‎

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
phpunit.xml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGELOG
2+
=========
3+
4+
8.1
5+
---
6+
7+
* Add bridge
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2025-present Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Prelude;
13+
14+
useSymfony\Component\Notifier\Message\MessageOptionsInterface;
15+
16+
/**
17+
* @author Imad Zairig <imadzairig@gmail.com>
18+
*/
19+
finalclass PreludeOptionsimplements MessageOptionsInterface
20+
{
21+
publicfunction__construct(
22+
privatereadonly ?string$templateId =null,
23+
privatereadonlyarray$variables = [],
24+
privatereadonly ?string$from =null,
25+
privatereadonly ?string$locale =null,
26+
privatereadonly ?string$expiresAt =null,
27+
privatereadonly ?string$scheduleAt =null,
28+
privatereadonly ?string$callbackUrl =null,
29+
privatereadonly ?string$correlationId =null,
30+
privatereadonly ?string$preferredChannel =null,
31+
) {
32+
}
33+
34+
publicfunctiontoArray():array
35+
{
36+
$options = [];
37+
if (null !==$this->templateId) {
38+
$options['template_id'] =$this->templateId;
39+
}
40+
if ($this->variables) {
41+
$options['variables'] =$this->variables;
42+
}
43+
if (null !==$this->from) {
44+
$options['from'] =$this->from;
45+
}
46+
if (null !==$this->locale) {
47+
$options['locale'] =$this->locale;
48+
}
49+
if (null !==$this->expiresAt) {
50+
$options['expires_at'] =$this->expiresAt;
51+
}
52+
if (null !==$this->scheduleAt) {
53+
$options['schedule_at'] =$this->scheduleAt;
54+
}
55+
if (null !==$this->callbackUrl) {
56+
$options['callback_url'] =$this->callbackUrl;
57+
}
58+
if (null !==$this->correlationId) {
59+
$options['correlation_id'] =$this->correlationId;
60+
}
61+
if (null !==$this->preferredChannel) {
62+
$options['preferred_channel'] =$this->preferredChannel;
63+
}
64+
65+
return$options;
66+
}
67+
68+
publicfunctiongetRecipientId(): ?string
69+
{
70+
returnnull;
71+
}
72+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Notifier\Bridge\Prelude;
13+
14+
useSymfony\Component\Notifier\Exception\TransportException;
15+
useSymfony\Component\Notifier\Exception\LogicException;
16+
useSymfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
17+
useSymfony\Component\Notifier\Exception\UnsupportedOptionsException;
18+
useSymfony\Component\Notifier\Message\MessageInterface;
19+
useSymfony\Component\Notifier\Message\SentMessage;
20+
useSymfony\Component\Notifier\Message\SmsMessage;
21+
useSymfony\Component\Notifier\Transport\AbstractTransport;
22+
useSymfony\Contracts\EventDispatcher\EventDispatcherInterface;
23+
useSymfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
24+
useSymfony\Contracts\HttpClient\HttpClientInterface;
25+
26+
/**
27+
* @author Imad Zairig <imadzairig@gmail.com>
28+
*/
29+
finalclass PreludeTransportextends AbstractTransport
30+
{
31+
protectedconstHOST ='api.prelude.dev';
32+
33+
publicfunction__construct(
34+
#[\SensitiveParameter]privatereadonlystring$apiKey,
35+
privatereadonlystring$sender,
36+
?HttpClientInterface$client =null,
37+
?EventDispatcherInterface$dispatcher =null,
38+
) {
39+
parent::__construct($client,$dispatcher);
40+
}
41+
42+
publicfunction__toString():string
43+
{
44+
return\sprintf('prelude://%s?sender=%s',$this->getEndpoint(),$this->sender);
45+
}
46+
47+
publicfunctionsupports(MessageInterface$message):bool
48+
{
49+
return$messageinstanceof SmsMessage;
50+
}
51+
52+
protectedfunctiondoSend(MessageInterface$message):SentMessage
53+
{
54+
if (!$messageinstanceof SmsMessage) {
55+
thrownewUnsupportedMessageTypeException(__CLASS__, SmsMessage::class,$message);
56+
}
57+
58+
if (($options =$message->getOptions()) && !$optionsinstanceof PreludeOptions) {
59+
thrownewUnsupportedOptionsException(__CLASS__, PreludeOptions::class,$options);
60+
}
61+
62+
$options =$options?->toArray() ?? [];
63+
64+
$body = [
65+
'to' =>$message->getPhone(),
66+
];
67+
68+
if ($this->sender) {
69+
$body['from'] =$this->sender;
70+
}
71+
72+
if (!isset($options['template_id'])) {
73+
thrownewLogicException(sprintf('The "template_id" option is required for the "%s" transport.',__CLASS__));
74+
}
75+
76+
$body =array_merge($body,$options);
77+
78+
$response =$this->client->request('POST','https://' .$this->getEndpoint() .'/v2/notify', [
79+
'json' =>$body,
80+
'headers' => [
81+
'Authorization' =>'Bearer' .$this->apiKey,
82+
],
83+
]);
84+
85+
try {
86+
$statusCode =$response->getStatusCode();
87+
}catch (TransportExceptionInterface$e) {
88+
thrownewTransportException('Could not reach the remote Prelude server.',$response,0,$e);
89+
}
90+
91+
if (200 !==$statusCode &&201 !==$statusCode) {
92+
$error =$response->toArray(false);
93+
94+
thrownewTransportException('Unable to send the SMS:' . ($error['message'] ??$response->getContent(false)),$response);
95+
}
96+
97+
$success =$response->toArray(false);
98+
99+
$sentMessage =newSentMessage($message, (string)$this);
100+
if (isset($success['id'])) {
101+
$sentMessage->setMessageId($success['id']);
102+
}
103+
104+
return$sentMessage;
105+
}
106+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp