Skip to content

Commit 6c87fbb

Browse files
committed
Merge remote-tracking branch 'upstream/master' into smsapi-notifier
# Conflicts: # src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php # src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier_transports.xml # src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php # src/Symfony/Component/Notifier/Transport.php
1 parent 5f2be64 commit 6c87fbb

File tree

11 files changed

+213
-0
lines changed

11 files changed

+213
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
107107
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
108108
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
109+
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
109110
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
110111
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
111112
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
@@ -2104,6 +2105,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
21042105
SinchTransportFactory::class => 'notifier.transport_factory.sinch',
21052106
ZulipTransportFactory::class => 'notifier.transport_factory.zulip',
21062107
MobytTransportFactory::class => 'notifier.transport_factory.mobyt',
2108+
SmsapiTransportFactory::class => 'notifier.transport_factory.smsapi',
21072109
];
21082110

21092111
foreach ($classToServices as $class => $service) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Notifier\Bridge\RocketChat\RocketChatTransportFactory;
2323
use Symfony\Component\Notifier\Bridge\Sinch\SinchTransportFactory;
2424
use Symfony\Component\Notifier\Bridge\Slack\SlackTransportFactory;
25+
use Symfony\Component\Notifier\Bridge\Smsapi\SmsapiTransportFactory;
2526
use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransportFactory;
2627
use Symfony\Component\Notifier\Bridge\Twilio\TwilioTransportFactory;
2728
use Symfony\Component\Notifier\Bridge\Zulip\ZulipTransportFactory;
@@ -90,6 +91,10 @@
9091
->parent('notifier.transport_factory.abstract')
9192
->tag('texter.transport_factory')
9293

94+
->set('notifier.transport_factory.smsapi', SmsapiTransportFactory::class)
95+
->parent('notifier.transport_factory.abstract')
96+
->tag('texter.transport_factory')
97+
9398
->set('notifier.transport_factory.null', NullTransportFactory::class)
9499
->parent('notifier.transport_factory.abstract')
95100
->tag('chatter.transport_factory')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Tests export-ignore
2+
/phpunit.xml.dist export-ignore
3+
/.gitignore export-ignore
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SMSAPI Notifier
2+
===============
3+
4+
Provides Smsapi integration for Symfony Notifier.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Symfony\Component\Notifier\Bridge\Smsapi;
4+
5+
use Symfony\Component\Notifier\Exception\LogicException;
6+
use Symfony\Component\Notifier\Exception\TransportException;
7+
use Symfony\Component\Notifier\Message\MessageInterface;
8+
use Symfony\Component\Notifier\Message\SmsMessage;
9+
use Symfony\Component\Notifier\Transport\AbstractTransport;
10+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
11+
use Symfony\Contracts\HttpClient\HttpClientInterface;
12+
13+
/**
14+
* @author Marcin Szepczynski <szepczynski@gmail.com>
15+
*/
16+
final class SmsapiTransport extends AbstractTransport
17+
{
18+
protected const HOST = 'api.smsapi.pl';
19+
20+
private $authToken;
21+
private $from;
22+
23+
public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
24+
{
25+
$this->authToken = $authToken;
26+
$this->from = $from;
27+
28+
parent::__construct($client, $dispatcher);
29+
}
30+
31+
public function __toString(): string
32+
{
33+
return sprintf('smsapi://%s?from=%s', $this->getEndpoint(), $this->from);
34+
}
35+
36+
public function supports(MessageInterface $message): bool
37+
{
38+
return $message instanceof SmsMessage;
39+
}
40+
41+
protected function doSend(MessageInterface $message): void
42+
{
43+
if (!$message instanceof SmsMessage) {
44+
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
45+
}
46+
47+
$endpoint = sprintf('https://%s/sms.do', $this->getEndpoint());
48+
$response = $this->client->request('POST', $endpoint, [
49+
'auth_bearer' => $this->authToken,
50+
'body' => [
51+
'from' => $this->from,
52+
'to' => $message->getPhone(),
53+
'message' => $message->getSubject(),
54+
'format' => 'json'
55+
],
56+
]);
57+
58+
if (200 !== $response->getStatusCode()) {
59+
$error = $response->toArray(false);
60+
61+
throw new TransportException(sprintf('Unable to send the SMS: '.$error['message'].' (see %s).', $error['more_info']), $response);
62+
}
63+
}
64+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Symfony\Component\Notifier\Bridge\Smsapi;
4+
5+
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
6+
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
7+
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
8+
use Symfony\Component\Notifier\Transport\Dsn;
9+
use Symfony\Component\Notifier\Transport\TransportInterface;
10+
11+
/**
12+
* @author Marcin Szepczynski <szepczynski@gmail.com>
13+
*/
14+
class SmsapiTransportFactory extends AbstractTransportFactory
15+
{
16+
/**
17+
* @return SmsapiTransport
18+
*/
19+
public function create(Dsn $dsn): TransportInterface
20+
{
21+
$scheme = $dsn->getScheme();
22+
$authToken = $dsn->getUser();
23+
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
24+
$from = $dsn->getOption('from');
25+
$port = $dsn->getPort();
26+
27+
if (!$authToken) {
28+
throw new IncompleteDsnException('Missing path (maybe you haven\'t update the DSN when upgrading from 5.0).', $dsn->getOriginalDsn());
29+
}
30+
31+
if ('smsapi' === $scheme) {
32+
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
33+
}
34+
35+
throw new UnsupportedSchemeException($dsn, 'smsapi', $this->getSupportedSchemes());
36+
}
37+
38+
protected function getSupportedSchemes(): array
39+
{
40+
return ['smsapi'];
41+
}
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "symfony/smsapi-notifier",
3+
"type": "symfony-bridge",
4+
"description": "Symfony Smsapi Notifier Bridge",
5+
"keywords": ["sms", "smsapi", "notifier"],
6+
"homepage": "https://mvpdoers.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Marcin Szepczynski",
11+
"email": "szepczynski@gmail.com"
12+
},
13+
{
14+
"name": "Symfony Community",
15+
"homepage": "https://symfony.com/contributors"
16+
}
17+
],
18+
"require": {
19+
"php": ">=7.2.5",
20+
"symfony/http-client": "^4.3|^5.0",
21+
"symfony/notifier": "^5.2"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": ""
26+
},
27+
"exclude-from-classmap": [
28+
"/Tests/"
29+
]
30+
},
31+
"minimum-stability": "dev",
32+
"extra": {
33+
"branch-alias": {
34+
"dev-master": "5.2-dev"
35+
}
36+
}
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1" />
13+
</php>
14+
15+
<testsuites>
16+
<testsuite name="Symfony Smsapi Notifier Bridge Test Suite">
17+
<directory>./Tests/</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<filter>
22+
<whitelist>
23+
<directory>./</directory>
24+
<exclude>
25+
<directory>./Resources</directory>
26+
<directory>./Tests</directory>
27+
<directory>./vendor</directory>
28+
</exclude>
29+
</whitelist>
30+
</filter>
31+
</phpunit>

src/Symfony/Component/Notifier/Exception/UnsupportedSchemeException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class UnsupportedSchemeException extends LogicException
7474
'class' => Bridge\Zulip\ZulipTransportFactory::class,
7575
'package' => 'symfony/zulip-notifier',
7676
],
77+
'smsapi' => [
78+
'class' => Bridge\Smsapi\SmsapiTransportFactory::class,
79+
'package' => 'symfony/smsapi-notifier',
80+
],
7781
];
7882

7983
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy