| Server IP : 54.233.248.239 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/irazasyed/telegram-bot-sdk/src/HttpClients/ |
Upload File : |
<?php
namespace Telegram\Bot\HttpClients;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
use Telegram\Bot\Exceptions\TelegramSDKException;
/**
* Class GuzzleHttpClient.
*/
class GuzzleHttpClient implements HttpClientInterface
{
/**
* HTTP client.
*
* @var Client
*/
protected $client;
/**
* @var PromiseInterface[]
*/
private static $promises = [];
/**
* Timeout of the request in seconds.
*
* @var int
*/
protected $timeOut = 30;
/**
* Connection timeout of the request in seconds.
*
* @var int
*/
protected $connectTimeOut = 10;
/**
* @param Client|null $client
*/
public function __construct(Client $client = null)
{
$this->client = $client ?: new Client();
}
/**
* Unwrap Promises.
*/
public function __destruct()
{
Promise\unwrap(self::$promises);
}
/**
* Sets HTTP client.
*
* @param Client $client
*
* @return GuzzleHttpClient
*/
public function setClient(Client $client)
{
$this->client = $client;
return $this;
}
/**
* Gets HTTP client for internal class use.
*
* @return Client
*/
private function getClient()
{
return $this->client;
}
/**
* {@inheritdoc}
*/
public function send(
$url,
$method,
array $headers = [],
array $options = [],
$timeOut = 30,
$isAsyncRequest = false,
$connectTimeOut = 10
) {
$this->timeOut = $timeOut;
$this->connectTimeOut = $connectTimeOut;
$body = isset($options['body']) ? $options['body'] : null;
$options = $this->getOptions($headers, $body, $options, $timeOut, $isAsyncRequest, $connectTimeOut);
try {
$response = $this->getClient()->requestAsync($method, $url, $options);
if ($isAsyncRequest) {
self::$promises[] = $response;
} else {
$response = $response->wait();
}
} catch (RequestException $e) {
$response = $e->getResponse();
if (!$response instanceof ResponseInterface) {
throw new TelegramSDKException($e->getMessage(), $e->getCode());
}
}
return $response;
}
/**
* Prepares and returns request options.
*
* @param array $headers
* @param $body
* @param $options
* @param $timeOut
* @param $isAsyncRequest
* @param int $connectTimeOut
*
* @return array
*/
private function getOptions(array $headers, $body, $options, $timeOut, $isAsyncRequest = false, $connectTimeOut = 10)
{
$default_options = [
RequestOptions::HEADERS => $headers,
RequestOptions::BODY => $body,
RequestOptions::TIMEOUT => $timeOut,
RequestOptions::CONNECT_TIMEOUT => $connectTimeOut,
RequestOptions::SYNCHRONOUS => !$isAsyncRequest,
];
return array_merge($default_options, $options);
}
/**
* @return int
*/
public function getTimeOut()
{
return $this->timeOut;
}
/**
* @return int
*/
public function getConnectTimeOut()
{
return $this->connectTimeOut;
}
}