Initial commit: WordPress wp-content (themes, plugins, languages)

- Theme: momentry (custom theme with REST API routes)
- Plugins: code-snippets (contains all API proxies)
- Languages: zh_TW translations
- Excludes: cache, backups, uploads, logs
This commit is contained in:
OpenCode
2026-05-29 19:07:56 +08:00
commit 09ef1f000f
6521 changed files with 867163 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
The MIT License
Copyright (c) 2013-2015 Mashape (https://www.mashape.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
==============
Modified under MIT License by APIMATIC (https://www.apimatic.io)

View File

@@ -0,0 +1,341 @@
<?php
declare (strict_types=1);
namespace WPForms\Vendor\Unirest;
use WPForms\Vendor\CoreInterfaces\Http\HttpConfigurations;
class Configuration
{
/**
* @var string|null
*/
private $cookie;
/**
* @var string|null
*/
private $cookieFile;
private $curlOpts = [];
private $jsonOpts = [];
private $socketTimeout = 0;
private $enableRetries = \false;
// should we enable retries feature
private $maxNumberOfRetries = 3;
// total number of allowed retries
private $retryOnTimeout = \false;
// Should we retry on timeout?
private $retryInterval = 1.0;
// Initial retry interval in seconds, to be increased by backoffFactor
private $maximumRetryWaitTime = 120;
// maximum retry wait time (commutative)
private $backoffFactor = 2.0;
// backoff factor to be used to increase retry interval
private $httpStatusCodesToRetry = [408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
private $httpMethodsToRetry = ["GET", "PUT"];
private $verifyPeer = \true;
private $verifyHost = \true;
private $defaultHeaders = [];
private $auth = ['user' => '', 'pass' => '', 'method' => \CURLAUTH_BASIC];
private $proxy = ['port' => \false, 'tunnel' => \false, 'address' => \false, 'type' => \CURLPROXY_HTTP, 'auth' => ['user' => '', 'pass' => '', 'method' => \CURLAUTH_BASIC]];
public static function init(?HttpConfigurations $httpConfigurations = null) : self
{
return new self($httpConfigurations);
}
private function __construct(?HttpConfigurations $httpConfigurations)
{
if (\is_null($httpConfigurations)) {
return;
}
$this->timeout($httpConfigurations->getTimeout())->enableRetries($httpConfigurations->shouldEnableRetries())->maxNumberOfRetries($httpConfigurations->getNumberOfRetries())->retryOnTimeout($httpConfigurations->shouldRetryOnTimeout())->retryInterval($httpConfigurations->getRetryInterval())->maximumRetryWaitTime($httpConfigurations->getMaximumRetryWaitTime())->backoffFactor($httpConfigurations->getBackOffFactor())->httpStatusCodesToRetry($httpConfigurations->getHttpStatusCodesToRetry())->httpMethodsToRetry($httpConfigurations->getHttpMethodsToRetry());
}
/**
* @param int $socketTimeout Timeout for API calls in seconds.
*/
public function timeout(int $socketTimeout) : self
{
$this->socketTimeout = $socketTimeout;
return $this;
}
/**
* @param bool $enableRetries Whether to enable retries and backoff feature.
*/
public function enableRetries(bool $enableRetries) : self
{
$this->enableRetries = $enableRetries;
return $this;
}
/**
* @param int $maxNumberOfRetries The number of retries to make.
*/
public function maxNumberOfRetries(int $maxNumberOfRetries) : self
{
$this->maxNumberOfRetries = $maxNumberOfRetries;
return $this;
}
/**
* @param bool $retryOnTimeout Whether to retry on timeout
*/
public function retryOnTimeout(bool $retryOnTimeout) : self
{
$this->retryOnTimeout = $retryOnTimeout;
return $this;
}
/**
* @param float $retryInterval The retry time interval between the endpoint calls.
*/
public function retryInterval(float $retryInterval) : self
{
$this->retryInterval = $retryInterval;
return $this;
}
/**
* @param int $maximumRetryWaitTime The maximum wait time in seconds for overall retrying requests.
*/
public function maximumRetryWaitTime(int $maximumRetryWaitTime) : self
{
$this->maximumRetryWaitTime = $maximumRetryWaitTime;
return $this;
}
/**
* @param float $backoffFactor Exponential backoff factor to increase interval between retries.
*/
public function backoffFactor(float $backoffFactor) : self
{
$this->backoffFactor = $backoffFactor;
return $this;
}
/**
* @param int[] $httpStatusCodesToRetry Http status codes to retry against.
*/
public function httpStatusCodesToRetry(array $httpStatusCodesToRetry) : self
{
$this->httpStatusCodesToRetry = $httpStatusCodesToRetry;
return $this;
}
/**
* @param string[] $httpMethodsToRetry Http methods to retry against.
*/
public function httpMethodsToRetry(array $httpMethodsToRetry) : self
{
$this->httpMethodsToRetry = $httpMethodsToRetry;
return $this;
}
/**
* Set JSON decode mode
*
* @param bool $assoc When TRUE, returned objects will be converted into associative arrays.
* @param int $depth User specified recursion depth.
* @param int $options Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported
* (default is to cast large integers as floats)
*/
public function jsonOpts(bool $assoc = \false, int $depth = 512, int $options = 0) : self
{
$this->jsonOpts = [$assoc, $depth, $options];
return $this;
}
/**
* Verify SSL peer
*
* @param bool $enabled enable SSL verification, by default is true
*/
public function verifyPeer(bool $enabled) : self
{
$this->verifyPeer = $enabled;
return $this;
}
/**
* Verify SSL host
*
* @param bool $enabled enable SSL host verification, by default is true
*/
public function verifyHost(bool $enabled) : self
{
$this->verifyHost = $enabled;
return $this;
}
/**
* Set default headers to send on every request
*
* @param array $headers headers array
*/
public function defaultHeaders(array $headers) : self
{
$this->defaultHeaders = \array_merge($this->defaultHeaders, $headers);
return $this;
}
/**
* Set a new default header to send on every request
*
* @param string $name header name
* @param string $value header value
*/
public function defaultHeader(string $name, string $value) : self
{
$this->defaultHeaders[$name] = $value;
return $this;
}
/**
* Set curl options to send on every request
*
* @param array $options options array
*/
public function curlOpts(array $options) : self
{
$this->curlOpts = \array_merge($this->curlOpts, $options);
return $this;
}
/**
* Set a new default header to send on every request
*
* @param string|int $name header name
* @param string $value header value
*/
public function curlOpt($name, string $value) : self
{
$this->curlOpts[$name] = $value;
return $this;
}
/**
* Set a cookie string for enabling cookie handling
*
* @param string $cookie
*/
public function cookie(string $cookie) : self
{
$this->cookie = $cookie;
return $this;
}
/**
* Set a cookie file path for enabling cookie handling
*
* $cookieFile must be a correct path with write permission
*
* @param string $cookieFile - path to file for saving cookie
*/
public function cookieFile(string $cookieFile) : self
{
$this->cookieFile = $cookieFile;
return $this;
}
/**
* Set authentication method to use
*
* @param string $username authentication username
* @param string $password authentication password
* @param integer $method authentication method
*/
public function auth(string $username = '', string $password = '', int $method = \CURLAUTH_BASIC) : self
{
$this->auth['user'] = $username;
$this->auth['pass'] = $password;
$this->auth['method'] = $method;
return $this;
}
/**
* Set proxy to use
*
* @param string $address proxy address
* @param integer $port proxy port
* @param integer $type (Available options for this are CURLPROXY_HTTP, CURLPROXY_HTTP_1_0 CURLPROXY_SOCKS4,
* CURLPROXY_SOCKS5, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5_HOSTNAME)
* @param bool $tunnel enable/disable tunneling
*/
public function proxy(string $address, int $port = 1080, int $type = \CURLPROXY_HTTP, bool $tunnel = \false) : self
{
$this->proxy['type'] = $type;
$this->proxy['port'] = $port;
$this->proxy['tunnel'] = $tunnel;
$this->proxy['address'] = $address;
return $this;
}
public function proxyConfiguration(array $proxyConfiguration) : self
{
$this->proxy = \array_merge($this->proxy, $proxyConfiguration);
return $this;
}
/**
* Set proxy authentication method to use
*
* @param string $username authentication username
* @param string $password authentication password
* @param integer $method authentication method
*/
public function proxyAuth(string $username = '', string $password = '', int $method = \CURLAUTH_BASIC) : self
{
$this->proxy['auth']['user'] = $username;
$this->proxy['auth']['pass'] = $password;
$this->proxy['auth']['method'] = $method;
return $this;
}
public function getTimeout() : int
{
return $this->socketTimeout;
}
public function shouldEnableRetries() : bool
{
return $this->enableRetries;
}
public function getNumberOfRetries() : int
{
return $this->maxNumberOfRetries;
}
public function getRetryInterval() : float
{
return $this->retryInterval;
}
public function getBackOffFactor() : float
{
return $this->backoffFactor;
}
public function getMaximumRetryWaitTime() : int
{
return $this->maximumRetryWaitTime;
}
public function shouldRetryOnTimeout() : bool
{
return $this->retryOnTimeout;
}
public function getHttpStatusCodesToRetry() : array
{
return $this->httpStatusCodesToRetry;
}
public function getHttpMethodsToRetry() : array
{
return $this->httpMethodsToRetry;
}
public function getCookie() : ?string
{
return $this->cookie;
}
public function getCookieFile() : ?string
{
return $this->cookieFile;
}
public function getCurlOpts() : array
{
return $this->curlOpts;
}
public function getJsonOpts() : array
{
return $this->jsonOpts;
}
public function shouldVerifyPeer() : bool
{
return $this->verifyPeer;
}
public function shouldVerifyHost() : bool
{
return $this->verifyHost;
}
public function getDefaultHeaders() : array
{
return $this->defaultHeaders;
}
public function getAuth() : array
{
return $this->auth;
}
public function getProxy() : array
{
return $this->proxy;
}
}

View File

@@ -0,0 +1,310 @@
<?php
declare (strict_types=1);
namespace WPForms\Vendor\Unirest;
use WPForms\Vendor\CoreInterfaces\Core\Request\RequestInterface;
use WPForms\Vendor\CoreInterfaces\Core\Request\RequestMethod;
use WPForms\Vendor\CoreInterfaces\Core\Response\ResponseInterface;
use WPForms\Vendor\CoreInterfaces\Http\HttpClientInterface;
use WPForms\Vendor\CoreInterfaces\Http\RetryOption;
use DateTime;
use WPForms\Vendor\Unirest\Request\Request;
class HttpClient implements HttpClientInterface
{
private $handle = null;
protected $totalNumberOfConnections = 0;
/**
* @var Configuration
*/
protected $config;
/**
* @param Configuration|null $configurations
*/
public function __construct(?Configuration $configurations = null)
{
$this->config = $configurations ?? Configuration::init();
}
public function execute(RequestInterface $request) : ResponseInterface
{
if ($this->handle == null) {
$this->initializeHandle();
} else {
\curl_reset($this->handle);
}
$this->setCurlOptions($this->handle, $request);
$retryCount = 0;
// current retry count
$waitTime = 0.0;
// wait time in secs before current api call
$allowedWaitTime = $this->config->getMaximumRetryWaitTime();
// remaining allowed wait time in seconds
$httpCode = null;
$headers = [];
do {
// If Retrying i.e. retryCount >= 1
if ($retryCount > 0) {
$this->sleep($waitTime);
// calculate remaining allowed wait Time
$allowedWaitTime -= $waitTime;
}
// Execution of api call
$response = \curl_exec($this->handle);
$error = \curl_error($this->handle);
$info = $this->getInfo();
if (empty($error) && \is_string($response)) {
$header_size = $info['header_size'];
$httpCode = (int) $info['http_code'];
$headers = $this->parseHeaders(\substr($response, 0, $header_size));
}
if ($this->shouldRetryRequest($request)) {
// calculate wait time for retry, and should not retry when wait time becomes 0
$waitTime = $this->getRetryWaitTime($httpCode, $headers, $error, $allowedWaitTime, $retryCount);
$retryCount++;
}
} while ($waitTime > 0.0);
if (!empty($error) || !isset($header_size, $headers, $httpCode)) {
throw $request->toApiException($error);
}
// get response body
$body = \substr($response, $header_size);
$this->totalNumberOfConnections += $this->getInfo(\CURLINFO_NUM_CONNECTS);
return new Response($httpCode, $body, $headers, $this->config->getJsonOpts());
}
protected function initializeHandle()
{
$this->handle = \curl_init();
$this->totalNumberOfConnections = 0;
}
protected function getBody(RequestInterface $request)
{
if (empty($request->getParameters())) {
return $request->getBody();
}
// special handling for form parameters i.e.
// returning flatten array with encoded keys if any multipart parameter exists
// OR returning concatenated encoded parameters string
$encodedBody = \join('&', $request->getEncodedParameters());
$multipartParameters = $request->getMultipartParameters();
if (empty($multipartParameters)) {
return $encodedBody;
}
if (empty($encodedBody)) {
return $multipartParameters;
}
foreach (\explode('&', $encodedBody) as $param) {
$keyValue = \explode('=', $param);
$multipartParameters[\urldecode($keyValue[0])] = \urldecode($keyValue[1]);
}
return $multipartParameters;
}
protected function setCurlOptions($handle, RequestInterface $request) : void
{
$queryUrl = $request->getQueryUrl();
$body = $this->getBody($request);
if ($request->getHttpMethod() !== RequestMethod::GET) {
if ($request->getHttpMethod() === RequestMethod::POST) {
\curl_setopt($handle, \CURLOPT_POST, \true);
\curl_setopt($handle, \CURLOPT_POSTFIELDS, \is_null($body) ? [] : $body);
} else {
if ($request->getHttpMethod() === RequestMethod::HEAD) {
\curl_setopt($handle, \CURLOPT_NOBODY, \true);
}
\curl_setopt($handle, \CURLOPT_CUSTOMREQUEST, \strtoupper($request->getHttpMethod()));
if (!\is_null($body)) {
\curl_setopt($handle, \CURLOPT_POSTFIELDS, $body);
}
}
} elseif (\is_array($body)) {
if (\strpos($queryUrl, '?') !== \false) {
$queryUrl .= '&';
} else {
$queryUrl .= '?';
}
$queryUrl .= \http_build_query(Request::buildHTTPCurlQuery($body));
}
$curl_base_options = [
\CURLOPT_URL => $queryUrl,
\CURLOPT_RETURNTRANSFER => \true,
\CURLOPT_FOLLOWLOCATION => \true,
\CURLOPT_MAXREDIRS => 10,
\CURLOPT_HTTPHEADER => $this->getFormattedHeaders($request),
\CURLOPT_HEADER => \true,
\CURLOPT_SSL_VERIFYPEER => $this->config->shouldVerifyPeer(),
// CURLOPT_SSL_VERIFYHOST accepts only 0 (false) or 2 (true).
// Future versions of libcurl will treat values 1 and 2 as equals
\CURLOPT_SSL_VERIFYHOST => $this->config->shouldVerifyHost() === \false ? 0 : 2,
// If an empty string, '', is set, a header containing all supported encoding types is sent
\CURLOPT_ENCODING => '',
];
\curl_setopt_array($handle, $this->mergeCurlOptions($curl_base_options, $this->config->getCurlOpts()));
if ($this->config->getTimeout() > 0) {
\curl_setopt($handle, \CURLOPT_TIMEOUT, $this->config->getTimeout());
}
if ($this->config->getCookie() !== null) {
\curl_setopt($handle, \CURLOPT_COOKIE, $this->config->getCookie());
}
if ($this->config->getCookieFile() !== null) {
\curl_setopt($handle, \CURLOPT_COOKIEFILE, $this->config->getCookieFile());
\curl_setopt($handle, \CURLOPT_COOKIEJAR, $this->config->getCookieFile());
}
if (!empty($this->config->getAuth()['user'])) {
\curl_setopt_array($handle, [\CURLOPT_HTTPAUTH => $this->config->getAuth()['method'], \CURLOPT_USERPWD => $this->config->getAuth()['user'] . ':' . $this->config->getAuth()['pass']]);
}
$proxy = $this->config->getProxy();
if (!empty($proxy['address'])) {
\curl_setopt_array($handle, [\CURLOPT_PROXYTYPE => $proxy['type'], \CURLOPT_PROXY => $proxy['address'], \CURLOPT_PROXYPORT => $proxy['port'], \CURLOPT_HTTPPROXYTUNNEL => $proxy['tunnel'], \CURLOPT_PROXYAUTH => $proxy['auth']['method'], \CURLOPT_PROXYUSERPWD => $proxy['auth']['user'] . ':' . $proxy['auth']['pass']]);
}
}
/**
* Halts program flow for given number of seconds, and microseconds
*
* @param float $seconds Seconds with upto 6 decimal places, here decimal part will be converted into microseconds
*/
protected function sleep(float $seconds)
{
$secs = (int) $seconds;
// the fraction part of the $seconds will always be less than 1 sec, extracting micro seconds
$microSecs = (int) (($seconds - $secs) * 1000000);
\sleep($secs);
\usleep($microSecs);
}
/**
* Check if retries are enabled at global and request level,
* also check whitelisted httpMethods, if retries are only enabled globally.
*/
protected function shouldRetryRequest(RequestInterface $request) : bool
{
switch ($request->getRetryOption()) {
case RetryOption::ENABLE_RETRY:
return $this->config->shouldEnableRetries();
case RetryOption::USE_GLOBAL_SETTINGS:
return $this->config->shouldEnableRetries() && \in_array(\strtoupper($request->getHttpMethod()), $this->config->getHttpMethodsToRetry(), \true);
case RetryOption::DISABLE_RETRY:
return \false;
}
return \false;
}
/**
* Generate calculated wait time, and 0.0 if api should not be retried
*
* @param int|null $httpCode Http status code in response
* @param array $headers Response headers
* @param string $error Error returned by server
* @param float $allowedWaitTime Remaining allowed wait time
* @param int $retryCount Attempt number
* @return float Wait time before sending the next apiCall
*/
protected function getRetryWaitTime(?int $httpCode, array $headers, string $error, float $allowedWaitTime, int $retryCount) : float
{
$retryWaitTime = 0.0;
$retry_after = 0;
if (empty($error)) {
// Successful apiCall with some status code or with Retry-After header
$headers_lower_keys = \array_change_key_case($headers);
$retry_after_val = \key_exists('retry-after', $headers_lower_keys) ? $headers_lower_keys['retry-after'] : null;
$retry_after = $this->getRetryAfterInSeconds($retry_after_val);
$retry = isset($retry_after_val) || \in_array($httpCode, $this->config->getHttpStatusCodesToRetry(), \true);
} else {
$retry = $this->config->shouldRetryOnTimeout() && \curl_errno($this->handle) == \CURLE_OPERATION_TIMEDOUT;
}
// Calculate wait time only if max number of retries are not already attempted
if ($retry && $retryCount < $this->config->getNumberOfRetries()) {
// noise between 0 and 0.1 secs upto 6 decimal places
$noise = \rand(0, 100000) / 1000000;
// calculate wait time with exponential backoff and noise in seconds
$waitTime = $this->config->getRetryInterval() * \pow($this->config->getBackOffFactor(), $retryCount) + $noise;
// select maximum of waitTime and retry_after
$waitTime = \floatval(\max($waitTime, $retry_after));
if ($waitTime <= $allowedWaitTime) {
// set retry wait time for next api call, only if its under allowed time
$retryWaitTime = $waitTime;
}
}
return $retryWaitTime;
}
/**
* Returns the number of seconds by extracting them from $retry-after parameter
*
* @param int|string $retry_after Some numeric value in seconds, or it could be RFC1123
* formatted datetime string
* @return int Number of seconds specified by retry-after param
*/
protected function getRetryAfterInSeconds($retry_after) : int
{
if (isset($retry_after)) {
if (\is_numeric($retry_after)) {
return (int) $retry_after;
// if value is already in seconds
} else {
// if value is a date time string in format RFC1123
$retry_after_date = DateTime::createFromFormat('D, d M Y H:i:s O', $retry_after);
// retry_after_date could either be undefined, or false, or a DateTime object (if valid format string)
return !$retry_after_date ? 0 : $retry_after_date->getTimestamp() - \time();
}
}
return 0;
}
/**
* if PECL_HTTP is not available use a fallback function
*
* thanks to ricardovermeltfoort@gmail.com
* http://php.net/manual/en/function.http-parse-headers.php#112986
*/
private function parseHeaders(string $raw_headers) : array
{
if (\function_exists('http_parse_headers')) {
return \http_parse_headers($raw_headers);
} else {
$key = '';
$headers = [];
foreach (\explode("\n", $raw_headers) as $i => $h) {
$h = \explode(':', $h, 2);
if (isset($h[1])) {
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = \trim($h[1]);
} elseif (\is_array($headers[$h[0]])) {
$headers[$h[0]] = \array_merge($headers[$h[0]], [\trim($h[1])]);
} else {
$headers[$h[0]] = \array_merge([$headers[$h[0]]], [\trim($h[1])]);
}
$key = $h[0];
} else {
if (\substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t" . \trim($h[0]);
} elseif (empty($key)) {
$headers[0] = \trim($h[0]);
}
}
}
return $headers;
}
}
public function getInfo(?int $option = null)
{
if (\is_null($option)) {
return \curl_getinfo($this->handle);
}
return \curl_getinfo($this->handle, $option);
}
protected function getFormattedHeaders(RequestInterface $request) : array
{
$combinedHeaders = \array_change_key_case(\array_merge(['user-agent' => 'unirest-php/4.0', 'expect' => ''], $this->config->getDefaultHeaders(), $request->getHeaders()));
$formattedHeaders = [];
foreach ($combinedHeaders as $key => $val) {
$key = \trim($key);
if (!empty($request->getParameters()) && $key == 'content-type') {
// special handling for form parameters i.e. removing content-type header
// As, Curl will automatically add content-type for form params
continue;
}
$formattedHeaders[] = "{$key}: {$val}";
}
return $formattedHeaders;
}
private function mergeCurlOptions(array &$existing_options, array $new_options) : array
{
$existing_options = $new_options + $existing_options;
return $existing_options;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace WPForms\Vendor\Unirest\Request;
use CURLFile;
use Exception;
class Body
{
/**
* Prepares a file for upload. To be used inside the parameters declaration for a request.
* @param string $filename The file path
* @param string $mimetype MIME type
* @param string $postName the file name
* @return string|CURLFile
*/
public static function file(string $filename, string $mimetype = '', string $postName = '')
{
if (\class_exists('CURLFile')) {
return new CURLFile($filename, $mimetype, $postName);
}
if (\function_exists('curl_file_create')) {
return \curl_file_create($filename, $mimetype, $postName);
}
return \sprintf('@%s;filename=%s;type=%s', $filename, $postName ?: \basename($filename), $mimetype);
}
/**
* @throws Exception
*/
public static function json($data)
{
if (!\function_exists('json_encode')) {
throw new Exception('JSON Extension not available');
}
return \json_encode($data);
}
public static function form($data)
{
if (\is_array($data) || \is_object($data) || $data instanceof \Traversable) {
return \http_build_query(Request::buildHTTPCurlQuery($data));
}
return $data;
}
public static function multipart($data, $files = \false) : array
{
if (\is_object($data)) {
return \get_object_vars($data);
}
if (!\is_array($data)) {
return [$data];
}
if ($files !== \false) {
foreach ($files as $name => $file) {
$data[$name] = \call_user_func([__CLASS__, 'File'], $file);
}
}
return $data;
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace WPForms\Vendor\Unirest\Request;
use WPForms\Vendor\CoreInterfaces\Core\Request\RequestInterface;
use WPForms\Vendor\CoreInterfaces\Core\Request\RequestMethod;
use WPForms\Vendor\CoreInterfaces\Http\RetryOption;
use Exception;
use InvalidArgumentException;
class Request implements RequestInterface
{
/**
* This function is useful for serializing multidimensional arrays, and avoid getting
* the 'Array to string conversion' notice
* @param array|object $data array to flatten.
* @param bool|string $parent parent key or false if no parent
*/
public static function buildHTTPCurlQuery($data, $parent = \false) : array
{
$result = [];
if (\is_object($data)) {
$data = \get_object_vars($data);
}
foreach ($data as $key => $value) {
if (!empty($parent)) {
$new_key = \sprintf('%s[%s]', $parent, $key);
} else {
$new_key = $key;
}
if (!$value instanceof \CURLFile and (\is_array($value) or \is_object($value))) {
$result = \array_merge($result, self::buildHTTPCurlQuery($value, $new_key));
} else {
$result[$new_key] = $value;
}
}
return $result;
}
private $httpMethod;
private $queryUrl;
private $headers;
private $body;
private $retryOption;
/**
* @param string $url Query url
* @param string $method Http method
* @param array $headers Http request headers
* @param mixed $body Http request body
* @param string $retryOption To enable/disable httpMethods whitelist while retrying Api call
*/
public function __construct(string $url, string $method = RequestMethod::GET, array $headers = [], $body = null, string $retryOption = RetryOption::USE_GLOBAL_SETTINGS)
{
$this->queryUrl = $this->validateUrl($url);
$this->httpMethod = $method;
$this->headers = $headers;
$this->body = $body;
$this->retryOption = $retryOption;
}
/**
* Validates and processes the given Url to ensure safe usage with cURL.
* @param string $url The given Url to process
* @return string Pre-processed Url as string
* @throws InvalidArgumentException
*/
private function validateUrl(string $url) : string
{
//ensure that the urls are absolute
$matchCount = \preg_match("#^(https?://[^/]+)#", $url, $matches);
if ($matchCount == 0) {
throw new InvalidArgumentException('Invalid Url format.');
}
//get the http protocol match
$protocol = $matches[1];
//remove redundant forward slashes
$query = \substr($url, \strlen($protocol));
$query = \preg_replace("#//+#", "/", $query);
//return process url
return $protocol . $query;
}
public function getHttpMethod() : string
{
return $this->httpMethod;
}
public function getQueryUrl() : string
{
return $this->queryUrl;
}
public function getHeaders() : array
{
return $this->headers;
}
public function getParameters() : array
{
return [];
}
public function getEncodedParameters() : array
{
return [];
}
public function getMultipartParameters() : array
{
return [];
}
public function getBody()
{
return $this->body;
}
public function getRetryOption() : string
{
return $this->retryOption;
}
public function convert() : Request
{
return $this;
}
public function toApiException(string $message) : Exception
{
return new Exception($message);
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare (strict_types=1);
namespace WPForms\Vendor\Unirest;
use WPForms\Vendor\CoreInterfaces\Core\Response\ResponseInterface;
use WPForms\Vendor\CoreInterfaces\Sdk\ConverterInterface;
class Response implements ResponseInterface
{
private $code;
private $raw_body;
private $body;
private $headers;
/**
* @param int $code response code of the cURL request
* @param string $raw_body the raw body of the cURL response
* @param array $headers parsed headers array from cURL response
* @param array $json_args arguments to pass to json_decode function
*/
public function __construct(int $code, string $raw_body, array $headers, array $json_args = [])
{
$this->code = $code;
$this->headers = $headers;
$this->raw_body = $raw_body;
$this->body = $raw_body;
// make sure raw_body is the first argument
\array_unshift($json_args, $raw_body);
if (\function_exists('json_decode')) {
$json = \call_user_func_array('json_decode', $json_args);
if (\json_last_error() === \JSON_ERROR_NONE) {
$this->body = $json;
}
}
}
public function getStatusCode() : int
{
return $this->code;
}
public function getHeaders() : array
{
return $this->headers;
}
public function getRawBody() : string
{
return $this->raw_body;
}
public function getBody()
{
return $this->body;
}
public function convert(ConverterInterface $converter)
{
return $converter->createHttpResponse($this);
}
}