Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/guzzleht.../guzzle/src
File: Pool.php
<?php
[0] Fix | Delete
namespace GuzzleHttp;
[1] Fix | Delete
[2] Fix | Delete
use GuzzleHttp\Promise\EachPromise;
[3] Fix | Delete
use GuzzleHttp\Promise\PromiseInterface;
[4] Fix | Delete
use GuzzleHttp\Promise\PromisorInterface;
[5] Fix | Delete
use Psr\Http\Message\RequestInterface;
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Sends an iterator of requests concurrently using a capped pool size.
[9] Fix | Delete
*
[10] Fix | Delete
* The pool will read from an iterator until it is cancelled or until the
[11] Fix | Delete
* iterator is consumed. When a request is yielded, the request is sent after
[12] Fix | Delete
* applying the "request_options" request options (if provided in the ctor).
[13] Fix | Delete
*
[14] Fix | Delete
* When a function is yielded by the iterator, the function is provided the
[15] Fix | Delete
* "request_options" array that should be merged on top of any existing
[16] Fix | Delete
* options, and the function MUST then return a wait-able promise.
[17] Fix | Delete
*/
[18] Fix | Delete
class Pool implements PromisorInterface
[19] Fix | Delete
{
[20] Fix | Delete
/** @var EachPromise */
[21] Fix | Delete
private $each;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* @param ClientInterface $client Client used to send the requests.
[25] Fix | Delete
* @param array|\Iterator $requests Requests or functions that return
[26] Fix | Delete
* requests to send concurrently.
[27] Fix | Delete
* @param array $config Associative array of options
[28] Fix | Delete
* - concurrency: (int) Maximum number of requests to send concurrently
[29] Fix | Delete
* - options: Array of request options to apply to each request.
[30] Fix | Delete
* - fulfilled: (callable) Function to invoke when a request completes.
[31] Fix | Delete
* - rejected: (callable) Function to invoke when a request is rejected.
[32] Fix | Delete
*/
[33] Fix | Delete
public function __construct(
[34] Fix | Delete
ClientInterface $client,
[35] Fix | Delete
$requests,
[36] Fix | Delete
array $config = []
[37] Fix | Delete
) {
[38] Fix | Delete
// Backwards compatibility.
[39] Fix | Delete
if (isset($config['pool_size'])) {
[40] Fix | Delete
$config['concurrency'] = $config['pool_size'];
[41] Fix | Delete
} elseif (!isset($config['concurrency'])) {
[42] Fix | Delete
$config['concurrency'] = 25;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
if (isset($config['options'])) {
[46] Fix | Delete
$opts = $config['options'];
[47] Fix | Delete
unset($config['options']);
[48] Fix | Delete
} else {
[49] Fix | Delete
$opts = [];
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
$iterable = \GuzzleHttp\Promise\iter_for($requests);
[53] Fix | Delete
$requests = function () use ($iterable, $client, $opts) {
[54] Fix | Delete
foreach ($iterable as $key => $rfn) {
[55] Fix | Delete
if ($rfn instanceof RequestInterface) {
[56] Fix | Delete
yield $key => $client->sendAsync($rfn, $opts);
[57] Fix | Delete
} elseif (is_callable($rfn)) {
[58] Fix | Delete
yield $key => $rfn($opts);
[59] Fix | Delete
} else {
[60] Fix | Delete
throw new \InvalidArgumentException('Each value yielded by '
[61] Fix | Delete
. 'the iterator must be a Psr7\Http\Message\RequestInterface '
[62] Fix | Delete
. 'or a callable that returns a promise that fulfills '
[63] Fix | Delete
. 'with a Psr7\Message\Http\ResponseInterface object.');
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
};
[67] Fix | Delete
[68] Fix | Delete
$this->each = new EachPromise($requests(), $config);
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Get promise
[73] Fix | Delete
*
[74] Fix | Delete
* @return PromiseInterface
[75] Fix | Delete
*/
[76] Fix | Delete
public function promise()
[77] Fix | Delete
{
[78] Fix | Delete
return $this->each->promise();
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Sends multiple requests concurrently and returns an array of responses
[83] Fix | Delete
* and exceptions that uses the same ordering as the provided requests.
[84] Fix | Delete
*
[85] Fix | Delete
* IMPORTANT: This method keeps every request and response in memory, and
[86] Fix | Delete
* as such, is NOT recommended when sending a large number or an
[87] Fix | Delete
* indeterminate number of requests concurrently.
[88] Fix | Delete
*
[89] Fix | Delete
* @param ClientInterface $client Client used to send the requests
[90] Fix | Delete
* @param array|\Iterator $requests Requests to send concurrently.
[91] Fix | Delete
* @param array $options Passes through the options available in
[92] Fix | Delete
* {@see GuzzleHttp\Pool::__construct}
[93] Fix | Delete
*
[94] Fix | Delete
* @return array Returns an array containing the response or an exception
[95] Fix | Delete
* in the same order that the requests were sent.
[96] Fix | Delete
* @throws \InvalidArgumentException if the event format is incorrect.
[97] Fix | Delete
*/
[98] Fix | Delete
public static function batch(
[99] Fix | Delete
ClientInterface $client,
[100] Fix | Delete
$requests,
[101] Fix | Delete
array $options = []
[102] Fix | Delete
) {
[103] Fix | Delete
$res = [];
[104] Fix | Delete
self::cmpCallback($options, 'fulfilled', $res);
[105] Fix | Delete
self::cmpCallback($options, 'rejected', $res);
[106] Fix | Delete
$pool = new static($client, $requests, $options);
[107] Fix | Delete
$pool->promise()->wait();
[108] Fix | Delete
ksort($res);
[109] Fix | Delete
[110] Fix | Delete
return $res;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Execute callback(s)
[115] Fix | Delete
*
[116] Fix | Delete
* @return void
[117] Fix | Delete
*/
[118] Fix | Delete
private static function cmpCallback(array &$options, $name, array &$results)
[119] Fix | Delete
{
[120] Fix | Delete
if (!isset($options[$name])) {
[121] Fix | Delete
$options[$name] = function ($v, $k) use (&$results) {
[122] Fix | Delete
$results[$k] = $v;
[123] Fix | Delete
};
[124] Fix | Delete
} else {
[125] Fix | Delete
$currentFn = $options[$name];
[126] Fix | Delete
$options[$name] = function ($v, $k) use (&$results, $currentFn) {
[127] Fix | Delete
$currentFn($v, $k);
[128] Fix | Delete
$results[$k] = $v;
[129] Fix | Delete
};
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function