8000 # Das ist eine Kombination aus 24 Commits. · PGLongo/symfony@2a4f97c · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a4f97c

Browse files
PGLongoOskarStark
authored andcommitted
# Das ist eine Kombination aus 24 Commits.
# Das ist die erste Commit-Beschreibung: [Notifier] add support for gatewayapi-notifier # Die Commit-Beschreibung symfony#2 wird ausgelassen: # Make GatewayAPITransportFactory final # Die Commit-Beschreibung symfony#3 wird ausgelassen: # Fix typo in gatewaypi # Die Commit-Beschreibung symfony#4 wird ausgelassen: # Fix typo # Die Commit-Beschreibung symfony#5 wird ausgelassen: # Update README.md # Die Commit-Beschreibung symfony#6 wird ausgelassen: # Rename GatewayAPI -> GatewayApi # Die Commit-Beschreibung symfony#7 wird ausgelassen: # Add GatewayApiTransportFactory tests # Die Commit-Beschreibung symfony#8 wird ausgelassen: # Add GatewayApiTransportTest testSend # Die Commit-Beschreibung symfony#9 wird ausgelassen: # Add GatewayApiTransportTest testSupportsSmsMessage # Die Commit-Beschreibung symfony#10 wird ausgelassen: # Add GatewayApiTransportTest testNotSupportsChatMessage # Die Commit-Beschreibung symfony#11 wird ausgelassen: # Lint code # Die Commit-Beschreibung symfony#12 wird ausgelassen: # Fix name and email in composer.json # # Co-authored-by: Tobias Nyholm <tobias.nyholm@gmail.com> # Die Commit-Beschreibung symfony#13 wird ausgelassen: # Remove extra from composer.json # Die Commit-Beschreibung symfony#14 wird ausgelassen: # Update version tag in GatewayApiTransport # Die Commit-Beschreibung symfony#15 wird ausgelassen: # Add /.gitattributes export-ignore in .gitattributes # Die Commit-Beschreibung symfony#16 wird ausgelassen: # Update UnsupportedSchemeException # Die Commit-Beschreibung symfony#17 wird ausgelassen: # Add required space in phpdoc # Die Commit-Beschreibung symfony#18 wird ausgelassen: # Update GatewayApiTransportFactory.php # # Update version tag in GatewayApiTransportFactory # Die Commit-Beschreibung symfony#19 wird ausgelassen: # [Notifier] add support for gatewayapi-notifier # Die Commit-Beschreibung symfony#20 wird ausgelassen: # Make GatewayAPITransportFactory final # Die Commit-Beschreibung symfony#21 wird ausgelassen: # Make GatewayAPITransportFactory final # Die Commit-Beschreibung symfony#22 wird ausgelassen: # Fix typo in gatewaypi # Die Commit-Beschreibung symfony#23 wird ausgelassen: # Fix typo # Die Commit-Beschreibung symfony#24 wird ausgelassen: # Update README.md
1 parent 44e98db commit 2a4f97c
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
106106
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
107107
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
108+
use Symfony\Component\Notifier\Bridge\GatewayApi\GatewayApiTransportFactory;
108109
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory;
109110
use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory;
110111
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
@@ -2236,6 +2237,11 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $
22362237
SendinblueNotifierTransportFactory::class => 'notifier.transport_factory.sendinblue',
22372238
DiscordTransportFactory::class => 'notifier.transport_factory.discord',
22382239
LinkedInTransportFactory::class => 'notifier.transport_factory.linkedin',
2240+
<<<<<<< HEAD
2241+
GatewayApiTransportFactory::class => 'notifier.transport_factory.gatewayapi',
2242+
=======
2243+
GatewayAPITransportFactory::class => 'notifier.transport_factory.gatewayapi',
2244+
>>>>>>> 2575ca2b12 ([Notifier] add support for gatewayapi-notifier)
22392245
];
22402246

22412247
foreach ($classToServices as $class => $service) {
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Notifier\Bridge\Esendex\EsendexTransportFactory;
1616
use Symfony\Component\Notifier\Bridge\Firebase\FirebaseTransportFactory;
1717
use Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransportFactory;
18+
use Symfony\Component\Notifier\Bridge\GatewayAPI\GatewayAPITransportFactory;
1819
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatTransportFactory;
1920
use Symfony\Component\Notifier\Bridge\Infobip\InfobipTransportFactory;
2021
use Symfony\Component\Notifier\Bridge\Iqsms\IqsmsTransportFactory;
@@ -120,6 +121,10 @@
120121
->parent('notifier.transport_factory.abstract')
121122
->tag('chatter.transport_factory')
122123

124+
->set('notifier.transport_factory.gatewayapi', GatewayApiTransportFactory::class)
125+
->parent('notifier.transport_factory.abstract')
126+
->tag('texter.transport_factory')
127+
123128
->set('notifier.transport_factory.null', NullTransportFactory::class)
124129
->parent('notifier.transport_factory.abstract')
125130
->tag('chatter.transport_factory')
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
1616
use Doctrine\DBAL\DriverManager;
1717
use Doctrine\DBAL\Schema\Schema;
18-
use Doctrine\DBAL\Version;
1918
use Psr\Cache\CacheItemPoolInterface;
2019
use Symfony\Component\Cache\Adapter\PdoAdapter;
2120
use Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait;
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
namespace Symfony\Component\Notifier\Bridge\GatewayAPI;
13+
14+
use Symfony\Component\Notifier\Exception\LogicException;
15+
use Symfony\Component\Notifier\Exception\TransportException;
16+
use Symfony\Component\Notifier\Message\MessageInterface;
17+
use Symfony\Component\Notifier\Message\SentMessage;
18+
use Symfony\Component\Notifier\Message\SmsMessage;
19+
use Symfony\Component\Notifier\Transport\AbstractTransport;
20+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
22+
23+
/**
24+
* @author Piergiuseppe Longo <piergiuseppe.longo@gmail.com>
25+
* @experimental in 5.2
26+
*/
27+
final class GatewayAPITransport extends AbstractTransport
28+
{
29+
protected const HOST = 'gatewayapi.com';
30+
31+
private $authToken;
32+
private $from;
33+
34+
public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
35+
{
36+
$this->authToken = $authToken;
37+
$this->from = $from;
38+
39+
parent::__construct($client, $dispatcher);
40+
}
41+
42+
public function __toString(): string
43+
{
44+
return sprintf('gatewayapi://%s?from=%s', $this->getEndpoint(), $this->from);
45+
}
46+
47+
public function supports(MessageInterface $message): bool
48+
{
49+
return $message instanceof SmsMessage;
50+
}
51+
52+
protected function doSend(MessageInterface $message): SentMessage
53+
{
54+
if (!$message instanceof SmsMessage) {
55+
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
56+
}
57+
58+
$endpoint = sprintf('https://%s/rest/mtsms', $this->getEndpoint());
59+
60+
$response = $this->client->request('POST', $endpoint, [
61+
'auth_basic' => [$this->authToken, ''],
62+
'json' => [
63+
'sender' => $this->from,
64+
'recipients' => [['msisdn' => $message->getPhone()]],
65+
'message' => $message->getSubject(),
66+
],
67+
]);
68+
69+
$statusCode = $response->getStatusCode();
70+
if (200 !== $statusCode) {
71+
throw new TransportException(sprintf('Unable to send the SMS: error %d.', $statusCode), $response);
72+
}
73+
74+
return new SentMessage($message, (string) $this);
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
namespace Symfony\Component\Notifier\Bridge\GatewayAPI;
13+
14+
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
15+
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
16+
use Symfony\Component\Notifier\Transport\Dsn;
17+
use Symfony\Component\Notifier\Transport\TransportInterface;
18+
19+
/**
20+
* @author Piergiuseppe Longo <piergiuseppe.longo@gmail.com>
21+
* @experimental in 5.2
22+
*/
23+
final class GatewayAPITransportFactory extends AbstractTransportFactory
24+
{
25+
/**
26+
* @return GatewayAPITransport
27+
*/
28+
public function create(Dsn $dsn): TransportInterface
29+
{
30+
$scheme = $dsn->getScheme();
31+
$authToken = $dsn->getUser();
32+
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
33+
$from = $dsn->getOption('from');
34+
$port = $dsn->getPort();
35+
36+
if ('gatewayapi' === $scheme) {
37+
return (new GatewayAPITransport($authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
38+
}
39+
40+
throw new UnsupportedSchemeException($dsn, 'gatewayapi', $this->getSupportedSchemes());
41+
}
42+
43+
protected function getSupportedSchemes(): array
44+
{
45+
return ['gatewayapi'];
46+
}
47+
}
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
GatewayAPI Notifier
2+
===================
3+
4+
Provides GatewayAPI integration for Symfony Notifier.
5+
6+
DSN example
7+
-----------
8+
9+
```
10+
// .env file
11+
GATEWAYAPI_DSN=gatewayapi://TOKEN@default?from=FROM
12+
```
13+
14+
where:
15+
- `TOKEN` is API Token (OAuth)
16+
- `FROM` is sender name
17+
18+
See your account info at https://gatewayapi.com
19+
20+
Resources
21+
---------
22+
23+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
24+
* [Report issues](https://github.com/symfony/symfony/issues) and
25+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
26+
in the [main Symfony repository](https://github.com/symfony/symfony)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "symfony/gatewayapi-notifier",
3+
"type": "symfony-bridge",
4+
"description": "Symfony GatewayAPI Notifier Bridge",
5+
"keywords": ["sms", "gatewayapi", "notifier"],
6+
"homepage": "https://gatewayapi.com",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Piergiuseppe Longo",
11+
"email": "piergiuseppe.longo@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\\GatewayAPI\\": ""
26+
},
27+
"exclude-from-classmap": [
28+
"/Tests/"
29+
]
30+
},
31+
"minimum-stability": "dev",
32+
"extra": {
33+
"branch-version": "5.2"
34+
}
35+
}
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 GatewayAPI 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>
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
namespace Symfony\Component\Notifier\Bridge\GatewayAPI;
13+
14+
use Symfony\Component\Notifier\Exception\LogicException;
15+
use Symfony\Component\Notifier\Exception\TransportException;
16+
use Symfony\Component\Notifier\Message\MessageInterface;
17+
use Symfony\Component\Notifier\Message\SentMessage;
18+
use Symfony\Component\Notifier\Message\SmsMessage;
19+
use Symfony\Component\Notifier\Transport\AbstractTransport;
20+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
22+
23+
/**
24+
* @author Piergiuseppe Longo <piergiuseppe.longo@gmail.com>
25+
* @experimental in 5.2
26+
*/
27+
final class GatewayAPITransport extends AbstractTransport
28+
{
29+
protected const HOST = 'gatewayapi.com';
30+
31+
private $authToken;
32+
private $from;
33+
34+
public function __construct(string $authToken, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
35+
{
36+
$this->authToken = $authToken;
37+
$this->from = $from;
38+
39+
parent::__construct($client, $dispatcher);
40+
}
41+
42+
public function __toString(): string
43+
{
44+
return sprintf('gatewaypi://%s?from=%s', $this->getEndpoint(), $this->from);
45+
}
46+
47+
public function supports(MessageInterface $message): bool
48+
{
49+
return $message instanceof SmsMessage;
50+
}
51+
52+
protected function doSend(MessageInterface $message): SentMessage
53+
{
54+
if (!$message instanceof SmsMessage) {
55+
throw new LogicException(sprintf('The "%s" transport only supports instances of "%s" (instance of "%s" given).', __CLASS__, SmsMessage::class, get_debug_type($message)));
56+
}
57+
58+
$endpoint = sprintf('https://%s/rest/mtsms', $this->getEndpoint());
59+
60+
$response = $this->client->request('POST', $endpoint, [
61+
'auth_basic' => [$this->authToken, ''],
62+
'json' => [
63+
'sender' => $this->from,
64+
'recipients' => [['msisdn' => $message->getPhone()]],
65+
'message' => $message->getSubject(),
66+
],
67+
]);
68+
69+
$statusCode = $response->getStatusCode();
70+
if (200 !== $statusCode) {
71+
throw new TransportException(sprintf('Unable to send the SMS: error %d.', $statusCode), $response);
72+
}
73+
74+
return new SentMessage($message, (string) $this);
75+
}
76+
}