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

Appearance settings

Commit 6b1a64a

Browse filesBrowse files
committed
[Notifier] Throw an exception when the Slack DSN is not valid
1 parent 4cc6055 commit 6b1a64a
Copy full SHA for 6b1a64a

File tree

Expand file treeCollapse file tree

6 files changed

+37
-7
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+37
-7
lines changed

‎src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransportFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/FreeMobile/FreeMobileTransportFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public function create(Dsn $dsn): TransportInterface
3434
$password = $this->getPassword($dsn);
3535
$phone = $dsn->getOption('phone');
3636

37-
if (null === $phone || '' === $phone) {
38-
throw new IncompleteDsnException('Missing phone.');
37+
if (!$phone) {
38+
throw new IncompleteDsnException('Missing phone.', $dsn->getOriginalDsn());
3939
}
4040

4141
if ('freemobile' === $scheme) {

‎src/Symfony/Component/Notifier/Bridge/Slack/SlackTransportFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/SlackTransportFactory.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Slack;
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;
@@ -33,6 +34,10 @@ public function create(Dsn $dsn): TransportInterface
3334
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3435
$port = $dsn->getPort();
3536

37+
if (!$id) {
38+
throw new IncompleteDsnException('Missing path (maybe you haven\'t update the DSN when upgrading from 5.0).', $dsn->getOriginalDsn());
39+
}
40+
3641
if ('slack' === $scheme) {
3742
return (new SlackTransport($id, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
3843
}

‎src/Symfony/Component/Notifier/Bridge/Telegram/TelegramTransportFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Telegram/TelegramTransportFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ protected function getSupportedSchemes(): array
5050
private function getToken(Dsn $dsn): string
5151
{
5252
if (null === $dsn->getUser() && null === $dsn->getPassword()) {
53-
throw new IncompleteDsnException('Missing token.');
53+
throw new IncompleteDsnException('Missing token.', $dsn->getOriginalDsn());
5454
}
5555

5656
if (null === $dsn->getPassword()) {
57-
throw new IncompleteDsnException('Malformed token.');
57+
throw new IncompleteDsnException('Malformed token.', $dsn->getOriginalDsn());
5858
}
5959

6060
return sprintf('%s:%s', $dsn->getUser(), $dsn->getPassword());

‎src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@
1818
*/
1919
class IncompleteDsnException extends InvalidArgumentException
2020
{
21+
private $dsn;
22+
23+
public function __construct(string $message, string $dsn = null, ?\Throwable $previous = null)
24+
{
25+
$this->dsn = $dsn;
26+
if ($dsn) {
27+
$message = sprintf('Invalid "%s" notifier DSN: ', $dsn).$message;
28+
}
29+
30+
parent::__construct($message, 0, $previous);
31+
}
32+
33+
public function getOriginalDsn(): string
34+
{
35+
return $this->dsn;
36+
}
2137
}

‎src/Symfony/Component/Notifier/Transport/AbstractTransportFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Transport/AbstractTransportFactory.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function getUser(Dsn $dsn): string
4848
{
4949
$user = $dsn->getUser();
5050
if (null === $user) {
51-
throw new IncompleteDsnException('User is not set.');
51+
throw new IncompleteDsnException('User is not set.', $dsn->getOriginalDsn());
5252
}
5353

5454
return $user;
@@ -58,7 +58,7 @@ protected function getPassword(Dsn $dsn): string
5858
{
5959
$password = $dsn->getPassword();
6060
if (null === $password) {
61-
throw new IncompleteDsnException('Password is not set.');
61+
throw new IncompleteDsnException('Password is not set.', $dsn->getOriginalDsn());
6262
}
6363

6464
return $password;

‎src/Symfony/Component/Notifier/Transport/Dsn.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Transport/Dsn.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ final class Dsn
2727
private $port;
2828
private $options;
2929
private $path;
30+
private $dsn;
3031

3132
public function __construct(string $scheme, string $host, ?string $user = null, ?string $password = null, ?int $port = null, array $options = [], ?string $path = null)
3233
{
@@ -59,7 +60,10 @@ public static function fromString(string $dsn): self
5960
$path = $parsedDsn['path'] ?? null;
6061
parse_str($parsedDsn['query'] ?? '', $query);
6162

62-
return new self($parsedDsn['scheme'], $parsedDsn['host'], $user, $password, $port, $query, $path);
63+
$dsnObject = new self($parsedDsn['scheme'], $parsedDsn['host'], $user, $password, $port, $query, $path);
64+
$dsnObject->dsn = $dsn;
65+
66+
return $dsnObject;
6367
}
6468

6569
public function getScheme(): string
@@ -96,4 +100,9 @@ public function getPath(): ?string
96100
{
97101
return $this->path;
98102
}
103+
104+
public function getOriginalDsn(): string
105+
{
106+
return $this->dsn;
107+
}
99108
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.