Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 61a2891

Browse files
committed
Allow to pass on parameters to ReactPHP's HTTP Client. Closes #72
1 parent 557ad10 commit 61a2891

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
include __DIR__.'/basics.php';
6+
7+
use \React\EventLoop\Factory;
8+
use \unreal4u\TelegramAPI\HttpClientRequestHandler;
9+
use \unreal4u\TelegramAPI\TgLog;
10+
use \unreal4u\TelegramAPI\Telegram\Methods\SendMessage;
11+
12+
$loop = Factory::create();
13+
// Passing along an array with options will allow you to choose a custom DNS that isn't 8.8.8.8
14+
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop, ['dns' => '8.8.4.4']));
15+
16+
$sendMessage = new SendMessage();
17+
$sendMessage->chat_id = A_USER_CHAT_ID;
18+
$sendMessage->text = 'Hello world!';
19+
20+
$tgLog->performApiRequest($sendMessage);
21+
$loop->run();

src/HttpClientRequestHandler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use React\HttpClient\Response;
1111
use React\Promise\Deferred;
1212
use React\Promise\PromiseInterface;
13+
use React\Socket\Connector;
1314
use unreal4u\TelegramAPI\Exceptions\ClientException;
1415
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;
1516

@@ -23,10 +24,11 @@ class HttpClientRequestHandler implements RequestHandlerInterface
2324
/**
2425
* HttpClientRequestHandler constructor.
2526
* @param LoopInterface $loop
27+
* @param array $options Use this to set options such as DNS and alike
2628
*/
27-
public function __construct(LoopInterface $loop)
29+
public function __construct(LoopInterface $loop, array $options = [])
2830
{
29-
$this->client = new Client($loop);
31+
$this->client = new Client($loop, new Connector($loop, $options));
3032
}
3133

3234
/**

0 commit comments

Comments
 (0)