Skip to content

Commit

Permalink
Allow to pass on parameters to ReactPHP's HTTP Client. Closes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
unreal4u committed Nov 28, 2017
1 parent 557ad10 commit 61a2891
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
21 changes: 21 additions & 0 deletions examples/02.send-message-with-custom-dns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types = 1);

include __DIR__.'/basics.php';

use \React\EventLoop\Factory;
use \unreal4u\TelegramAPI\HttpClientRequestHandler;
use \unreal4u\TelegramAPI\TgLog;
use \unreal4u\TelegramAPI\Telegram\Methods\SendMessage;

$loop = Factory::create();
// Passing along an array with options will allow you to choose a custom DNS that isn't 8.8.8.8
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop, ['dns' => '8.8.4.4']));

$sendMessage = new SendMessage();
$sendMessage->chat_id = A_USER_CHAT_ID;
$sendMessage->text = 'Hello world!';

$tgLog->performApiRequest($sendMessage);
$loop->run();
6 changes: 4 additions & 2 deletions src/HttpClientRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use React\HttpClient\Response;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use React\Socket\Connector;
use unreal4u\TelegramAPI\Exceptions\ClientException;
use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse;

Expand All @@ -23,10 +24,11 @@ class HttpClientRequestHandler implements RequestHandlerInterface
/**
* HttpClientRequestHandler constructor.
* @param LoopInterface $loop
* @param array $options Use this to set options such as DNS and alike
*/
public function __construct(LoopInterface $loop)
public function __construct(LoopInterface $loop, array $options = [])
{
$this->client = new Client($loop);
$this->client = new Client($loop, new Connector($loop, $options));
}

/**
Expand Down

0 comments on commit 61a2891

Please sign in to comment.