8000 feature #39579 [Notifier] [GoogleChat] [BC BREAK] Rename threadKey pa… · symfony/symfony@3796af6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3796af6

Browse files
committed
feature #39579 [Notifier] [GoogleChat] [BC BREAK] Rename threadKey parameter to thread_key + set parameter via ctor (OskarStark)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Notifier] [GoogleChat] [BC BREAK] Rename threadKey parameter to thread_key + set parameter via ctor | Q | A | ------------- | --- | Branch? | 5.x, but BC BREAK for experimental bridge | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | --- | License | MIT | Doc PR | symfony/symfony-docs#14834 | Recipe | symfony/recipes#871 All bridges receive their options via the `constructor` and use snake_case parameters. ### Todos * [x] Update recipe * [x] Update documentation cc @GromNaN as you provided the bridge Commits ------- 5a71928 [Notifier] [GoogleChat] [BC BREAK] Rename threadKey parameter to thread_key + set parameter via ctor
2 parents 28533aa + 5a71928 commit 3796af6

File tree

6 files changed

+38
-34
lines changed

6 files changed

+38
-34
lines changed

src/Symfony/Component/Notifier/Bridge/GoogleChat/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ CHANGELOG
55
---
66

77
* The bridge is not marked as `@experimental` anymore
8+
* [BC BREAK] Remove `GoogleChatTransport::setThreadKey()` method, this parameter should now be provided via the constructor,
9+
which has changed from:
10+
`__construct(string $space, string $accessKey, string $accessToken, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
11+
to:
12+
`__construct(string $space, string $accessKey, string $accessToken, string $threadKey = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)`
13+
* [BC BREAK] Rename the parameter `threadKey` to `thread_key` in DSN
814

915
5.2.0
1016
-----

src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatTransport.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,33 @@ final class GoogleChatTransport extends AbstractTransport
3232
private $space;
3333
private $accessKey;
3434
private $accessToken;
35-
36-
/**
37-
* @var ?string
38-
*/
3935
private $threadKey;
4036

4137
/**
42-
* @param string $space The space name the the webhook url "/v1/spaces/<space>/messages"
43-
* @param string $accessKey The "key" parameter of the webhook url
44-
* @param string $accessToken The "token" parameter of the webhook url
38+
* @param string $space The space name the the webhook url "/v1/spaces/<space>/messages"
39+
* @param string $accessKey 10000 The "key" parameter of the webhook url
40+
* @param string $accessToken The "token" parameter of the webhook url
41+
* @param string|null $threadKey Opaque thread identifier string that can be specified to group messages into a single thread.
42+
* If this is the first message with a given thread identifier, a new thread is created.
43+
* Subsequent messages with the same thread identifier will be posted into the same thread.
44+
* {@see https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create#query-parameters}
4545
*/
46-
public function __construct(string $space, string $accessKey, string $accessToken, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
46+
public function __construct(string $space, string $accessKey, string $accessToken, string $threadKey = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
4747
{
4848
$this->space = $space;
4949
$this->accessKey = $accessKey;
5050
$this->accessToken = $accessToken;
51-
52-
parent::__construct($client, $dispatcher);
53-
}
54-
55-
/**
56-
* Opaque thread identifier string that can be specified to group messages into a single thread.
57-
* If this is the first message with a given thread identifier, a new thread is created.
58-
* Subsequent messages with the same thread identifier will be posted into the same thread.
59-
*
60-
* @see https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create#query-parameters
61-
*/
62-
public function setThreadKey(?string $threadKey): self
63-
{
6451
$this->threadKey = $threadKey;
6552

66-
return $this;
53+
parent::__construct($client, $dispatcher);
6754
}
6855

6956
public function __toString(): string
7057
{
7158
return sprintf('googlechat://%s/%s%s',
7259
$this->getEndpoint(),
7360
$this->space,
74-
$this->threadKey ? '?threadKey='.urlencode($this->threadKey) : ''
61+
$this->threadKey ? '?thread_key='.urlencode($this->threadKey) : ''
7562
);
7663
}
7764

src/Symfony/Component/Notifier/Bridge/GoogleChat/GoogleChatTransportFactory.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat;
1313

14+
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
1415
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
1516
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
1617
use Symfony\Component\Notifier\Transport\Dsn;
@@ -22,7 +23,7 @@
2223
final class GoogleChatTransportFactory extends AbstractTransportFactory
2324
{
2425
/**
25-
* @param Dsn $dsn Format: googlechat://<key>:<token>@default/<space>?threadKey=<thread>
26+
* @param Dsn $dsn Format: googlechat://<key>:<token>@default/<space>?thread_key=<thread>
2627
*
2728
* @return GoogleChatTransport
2829
*/
@@ -37,11 +38,20 @@ public function create(Dsn $dsn): TransportInterface
3738
$space = explode('/', $dsn->getPath())[1];
3839
$accessKey = $this->getUser($dsn);
3940
$accessToken = $this->getPassword($dsn);
40-
$threadKey = $dsn->getOption('threadKey');
41+
42+
$threadKey = $dsn->getOption('thread_key');
43+
44+
/*
45+
* Remove this check for 5.4
46+
*/
47+
if (null === $threadKey && null !== $dsn->getOption('threadKey')) {
48+
throw new IncompleteDsnException('GoogleChat DSN has changed since 5.3, use "thread_key" instead of "threadKey" parameter.');
49+
}
50+
4151
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
4252
$port = $dsn->getPort();
4353

44-
return (new GoogleChatTransport($space, $accessKey, $accessToken, $this->client, $this->dispatcher))->setThreadKey($threadKey)->setHost($host)->setPort($port);
54+
return (new GoogleChatTransport($space, $accessKey, $accessToken, $threadKey, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
4555
}
4656

4757
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/GoogleChat/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ DSN example
77
-----------
88

99
```
10-
GOOGLE_CHAT_DSN=googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?threadKey=THREAD_KEY
10+
GOOGLE_CHAT_DSN=googlechat://ACCESS_KEY:ACCESS_TOKEN@default/SPACE?thread_key=THREAD_KEY
1111
```
1212

1313
where:

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatTransportFactoryTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function createProvider(): iterable
3333
];
3434

3535
yield [
36-
'googlechat://chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
37-
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg',
36+
'googlechat://chat.googleapis.com/AAAAA_YYYYY?thread_key=abcdefg',
37+
'googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?thread_key=abcdefg',
3838
];
3939
}
4040

@@ -46,7 +46,8 @@ public function supportsProvider(): iterable
4646

4747
public function incompleteDsnProvider(): iterable
4848
{
49-
yield 'missing credentials' => ['googlechat://chat.googleapis.com/AAAAA_YYYYY'];
49+
yield 'missing credentials' => ['googlechat://chat.googleapis.com/v1/spaces/AAAAA_YYYYY/messages'];
50+
yield 'using old option: threadKey' => ['googlechat://abcde-fghij:kl_mnopqrstwxyz%3D@chat.googleapis.com/AAAAA_YYYYY?threadKey=abcdefg', 'GoogleChat DSN has changed since 5.3, use "thread_key" instead of "threadKey" parameter.']; // can be removed in Symfony 5.4
5051
}
5152

5253
public function unsupportedSchemeProvider(): iterable

src/Symfony/Component/Notifier/Bridge/GoogleChat/Tests/GoogleChatTransportTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ final class GoogleChatTransportTest extends TransportTestCase
3131
/**
3232
* @return GoogleChatTransport
3333
*/
34-
public function createTransport(?HttpClientInterface $client = null): TransportInterface
34+
public function createTransport(?HttpClientInterface $client = null, string $threadKey = null): TransportInterface
3535
{
36-
return new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $client ?: $this->createMock(HttpClientInterface::class));
36+
return new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $threadKey, $client ?: $this->createMock(HttpClientInterface::class));
3737
}
3838

3939
public function toStringProvider(): iterable
4040
{
4141
yield ['googlechat://chat.googleapis.com/My-Space', $this->createTransport()];
42+
yield ['googlechat://chat.googleapis.com/My-Space?thread_key=abcdefg', $this->createTransport(null, 'abcdefg')];
4243
}
4344

4445
public function supportedMessagesProvider(): iterable
@@ -125,8 +126,7 @@ public function testSendWithOptions()
125126
return $response;
126127
});
127128

128-
$transport = $this->createTransport($client);
129-
$transport->setThreadKey('My-Thread');
129+
$transport = $this->createTransport($client, 'My-Thread');
130130

131131
$sentMessage = $transport->send(new ChatMessage('testMessage'));
132132

0 commit comments

Comments
 (0)
0