fixing telegram token

This commit is contained in:
Christopher Hertel 2019-11-01 16:20:49 +01:00
parent 0ea2855cdf
commit c2c3e70e6b
2 changed files with 16 additions and 2 deletions

View File

@ -38,7 +38,7 @@ final class TelegramTransport extends AbstractTransport
private $token;
private $chatChannel;
public function __construct(string $token, string $chatChannel, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
public function __construct(string $token, string $chatChannel = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
{
$this->token = $token;
$this->chatChannel = $chatChannel;

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Notifier\Bridge\Telegram;
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
use Symfony\Component\Notifier\Transport\Dsn;
@ -26,7 +27,7 @@ final class TelegramTransportFactory extends AbstractTransportFactory
public function create(Dsn $dsn): TransportInterface
{
$scheme = $dsn->getScheme();
$token = $this->getUser($dsn);
$token = $this->getToken($dsn);
$channel = $dsn->getOption('channel');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();
@ -42,4 +43,17 @@ final class TelegramTransportFactory extends AbstractTransportFactory
{
return ['telegram'];
}
private function getToken(Dsn $dsn): string
{
if (null === $dsn->getUser() && null === $dsn->getPassword()) {
throw new IncompleteDsnException('Missing token');
}
if (null === $dsn->getPassword()) {
throw new IncompleteDsnException('Malformed token');
}
return sprintf('%s:%s', $dsn->getUser(), $dsn->getPassword());
}
}