| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,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_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/wpforms-lite/vendor_prefixed/apimatic/core/src/ |
Upload File : |
<?php
declare (strict_types=1);
namespace WPForms\Vendor\Core;
use WPForms\Vendor\Core\Authentication\Auth;
use WPForms\Vendor\Core\Request\Parameters\MultipleParams;
use WPForms\Vendor\Core\Request\Request;
use WPForms\Vendor\Core\Response\Context;
use WPForms\Vendor\Core\Response\ResponseHandler;
use WPForms\Vendor\Core\Response\Types\ErrorType;
use WPForms\Vendor\Core\Types\Sdk\CoreCallback;
use WPForms\Vendor\Core\Utils\JsonHelper;
use WPForms\Vendor\CoreInterfaces\Core\Authentication\AuthInterface;
use WPForms\Vendor\CoreInterfaces\Core\Logger\ApiLoggerInterface;
use WPForms\Vendor\CoreInterfaces\Core\Request\ParamInterface;
use WPForms\Vendor\CoreInterfaces\Http\HttpClientInterface;
use WPForms\Vendor\CoreInterfaces\Sdk\ConverterInterface;
class Client
{
private static $converter;
private static $jsonHelper;
public static function getConverter(?Client $client = null) : ConverterInterface
{
if (isset($client)) {
return $client->localConverter;
}
return self::$converter;
}
public static function getJsonHelper(?Client $client = null) : JsonHelper
{
if (isset($client)) {
return $client->localJsonHelper;
}
return self::$jsonHelper;
}
private $httpClient;
private $localConverter;
private $localJsonHelper;
private $authManagers;
private $serverUrls;
private $defaultServer;
private $globalConfig;
private $globalRuntimeConfig;
private $globalErrors;
private $apiCallback;
private $apiLogger;
/**
* @param HttpClientInterface $httpClient
* @param ConverterInterface $converter
* @param JsonHelper $jsonHelper
* @param array<string,AuthInterface> $authManagers
* @param array<string,string> $serverUrls
* @param string $defaultServer
* @param ParamInterface[] $globalConfig
* @param ParamInterface[] $globalRuntimeConfig
* @param array<string,ErrorType> $globalErrors
* @param CoreCallback|null $apiCallback
* @param ApiLoggerInterface $apiLogger
*/
public function __construct(HttpClientInterface $httpClient, ConverterInterface $converter, JsonHelper $jsonHelper, array $authManagers, array $serverUrls, string $defaultServer, array $globalConfig, array $globalRuntimeConfig, array $globalErrors, ?CoreCallback $apiCallback, ApiLoggerInterface $apiLogger)
{
$this->httpClient = $httpClient;
self::$converter = $converter;
$this->localConverter = $converter;
self::$jsonHelper = $jsonHelper;
$this->localJsonHelper = $jsonHelper;
$this->authManagers = $authManagers;
$this->serverUrls = $serverUrls;
$this->defaultServer = $defaultServer;
$this->globalConfig = $globalConfig;
$this->globalRuntimeConfig = $globalRuntimeConfig;
$this->globalErrors = $globalErrors;
$this->apiCallback = $apiCallback;
$this->apiLogger = $apiLogger;
}
public function getGlobalRequest(?string $server = null) : Request
{
$globalParams = new MultipleParams('Global Parameters');
$globalParams->parameters($this->globalConfig)->validate(self::getJsonHelper($this));
return new Request($this->serverUrls[$server ?? $this->defaultServer], $this, $globalParams);
}
public function getGlobalResponseHandler() : ResponseHandler
{
$responseHandler = new ResponseHandler();
\array_walk($this->globalErrors, function (ErrorType $error, string $key) use($responseHandler) : void {
$responseHandler->throwErrorOn($key, $error);
});
return $responseHandler;
}
public function getHttpClient() : HttpClientInterface
{
return $this->httpClient;
}
public function getApiLogger() : ApiLoggerInterface
{
return $this->apiLogger;
}
public function validateAuth(Auth $auth) : Auth
{
$auth->withAuthManagers($this->authManagers)->validate(self::getJsonHelper($this));
return $auth;
}
/**
* @param ParamInterface[] $parameters
*/
public function validateParameters(array $parameters) : MultipleParams
{
$parameters = \array_merge($parameters, $this->globalRuntimeConfig);
$paramGroup = new MultipleParams('Endpoint Parameters');
$paramGroup->parameters($parameters)->validate(self::getJsonHelper($this));
return $paramGroup;
}
public function beforeRequest(Request $request)
{
if (isset($this->apiCallback)) {
$this->apiCallback->callOnBeforeWithConversion($request, self::getConverter($this));
}
$this->apiLogger->logRequest($request);
}
public function afterResponse(Context $context)
{
if (isset($this->apiCallback)) {
$this->apiCallback->callOnAfterWithConversion($context, self::getConverter($this));
}
$this->apiLogger->logResponse($context->getResponse());
}
}