Server IP : 213.176.29.180 / Your IP : 18.117.183.206 Web Server : Apache System : Linux 213.176.29.180.hostiran.name 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64 User : webtaragh ( 1001) PHP Version : 8.3.14 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0750) : /home/webtaragh/public_html/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
PK s�$Z�߇`G G promises/src/Each.phpnu �[��� <?php namespace GuzzleHttp\Promise; final class Each { /** * Given an iterator that yields promises or values, returns a promise that * is fulfilled with a null value when the iterator has been consumed or * the aggregate promise has been fulfilled or rejected. * * $onFulfilled is a function that accepts the fulfilled value, iterator * index, and the aggregate promise. The callback can invoke any necessary * side effects and choose to resolve or reject the aggregate if needed. * * $onRejected is a function that accepts the rejection reason, iterator * index, and the aggregate promise. The callback can invoke any necessary * side effects and choose to resolve or reject the aggregate if needed. * * @param mixed $iterable Iterator or array to iterate over. * @param callable $onFulfilled * @param callable $onRejected * * @return PromiseInterface */ public static function of( $iterable, callable $onFulfilled = null, callable $onRejected = null ) { return (new EachPromise($iterable, [ 'fulfilled' => $onFulfilled, 'rejected' => $onRejected ]))->promise(); } /** * Like of, but only allows a certain number of outstanding promises at any * given time. * * $concurrency may be an integer or a function that accepts the number of * pending promises and returns a numeric concurrency limit value to allow * for dynamic a concurrency size. * * @param mixed $iterable * @param int|callable $concurrency * @param callable $onFulfilled * @param callable $onRejected * * @return PromiseInterface */ public static function ofLimit( $iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null ) { return (new EachPromise($iterable, [ 'fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency ]))->promise(); } /** * Like limit, but ensures that no promise in the given $iterable argument * is rejected. If any promise is rejected, then the aggregate promise is * rejected with the encountered rejection. * * @param mixed $iterable * @param int|callable $concurrency * @param callable $onFulfilled * * @return PromiseInterface */ public static function ofLimitAll( $iterable, $concurrency, callable $onFulfilled = null ) { return each_limit( $iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate) { $aggregate->reject($reason); } ); } } PK s�$Z�{:l\ \ promises/src/EachPromise.phpnu �[��� <?php namespace GuzzleHttp\Promise; /** * Represents a promise that iterates over many promises and invokes * side-effect functions in the process. */ class EachPromise implements PromisorInterface { private $pending = []; /** @var \Iterator|null */ private $iterable; /** @var callable|int|null */ private $concurrency; /** @var callable|null */ private $onFulfilled; /** @var callable|null */ private $onRejected; /** @var Promise|null */ private $aggregate; /** @var bool|null */ private $mutex; /** * Configuration hash can include the following key value pairs: * * - fulfilled: (callable) Invoked when a promise fulfills. The function * is invoked with three arguments: the fulfillment value, the index * position from the iterable list of the promise, and the aggregate * promise that manages all of the promises. The aggregate promise may * be resolved from within the callback to short-circuit the promise. * - rejected: (callable) Invoked when a promise is rejected. The * function is invoked with three arguments: the rejection reason, the * index position from the iterable list of the promise, and the * aggregate promise that manages all of the promises. The aggregate * promise may be resolved from within the callback to short-circuit * the promise. * - concurrency: (integer) Pass this configuration option to limit the * allowed number of outstanding concurrently executing promises, * creating a capped pool of promises. There is no limit by default. * * @param mixed $iterable Promises or values to iterate. * @param array $config Configuration options */ public function __construct($iterable, array $config = []) { $this->iterable = Create::iterFor($iterable); if (isset($config['concurrency'])) { $this->concurrency = $config['concurrency']; } if (isset($config['fulfilled'])) { $this->onFulfilled = $config['fulfilled']; } if (isset($config['rejected'])) { $this->onRejected = $config['rejected']; } } /** @psalm-suppress InvalidNullableReturnType */ public function promise() { if ($this->aggregate) { return $this->aggregate; } try { $this->createPromise(); /** @psalm-assert Promise $this->aggregate */ $this->iterable->rewind(); if (!$this->checkIfFinished()) { $this->refillPending(); } } catch (\Throwable $e) { /** * @psalm-suppress NullReference * @phpstan-ignore-next-line */ $this->aggregate->reject($e); } catch (\Exception $e) { /** * @psalm-suppress NullReference * @phpstan-ignore-next-line */ $this->aggregate->reject($e); } /** * @psalm-suppress NullableReturnStatement * @phpstan-ignore-next-line */ return $this->aggregate; } private function createPromise() { $this->mutex = false; $this->aggregate = new Promise(function () { reset($this->pending); // Consume a potentially fluctuating list of promises while // ensuring that indexes are maintained (precluding array_shift). while ($promise = current($this->pending)) { next($this->pending); $promise->wait(); if (Is::settled($this->aggregate)) { return; } } }); // Clear the references when the promise is resolved. $clearFn = function () { $this->iterable = $this->concurrency = $this->pending = null; $this->onFulfilled = $this->onRejected = null; }; $this->aggregate->then($clearFn, $clearFn); } private function refillPending() { if (!$this->concurrency) { // Add all pending promises. while ($this->addPending() && $this->advanceIterator()); return; } // Add only up to N pending promises. $concurrency = is_callable($this->concurrency) ? call_user_func($this->concurrency, count($this->pending)) : $this->concurrency; $concurrency = max($concurrency - count($this->pending), 0); // Concurrency may be set to 0 to disallow new promises. if (!$concurrency) { return; } // Add the first pending promise. $this->addPending(); // Note this is special handling for concurrency=1 so that we do // not advance the iterator after adding the first promise. This // helps work around issues with generators that might not have the // next value to yield until promise callbacks are called. while (--$concurrency && $this->advanceIterator() && $this->addPending()); } private function addPending() { if (!$this->iterable || !$this->iterable->valid()) { return false; } $promise = Create::promiseFor($this->iterable->current()); $key = $this->iterable->key(); // Iterable keys may not be unique, so we add the promises at the end // of the pending array and retrieve the array index being used $this->pending[] = null; end($this->pending); $idx = key($this->pending); $this->pending[$idx] = $promise->then( function ($value) use ($idx, $key) { if ($this->onFulfilled) { call_user_func( $this->onFulfilled, $value, $key, $this->aggregate ); } $this->step($idx); }, function ($reason) use ($idx, $key) { if ($this->onRejected) { call_user_func( $this->onRejected, $reason, $key, $this->aggregate ); } $this->step($idx); } ); return true; } private function advanceIterator() { // Place a lock on the iterator so that we ensure to not recurse, // preventing fatal generator errors. if ($this->mutex) { return false; } $this->mutex = true; try { $this->iterable->next(); $this->mutex = false; return true; } catch (\Throwable $e) { $this->aggregate->reject($e); $this->mutex = false; return false; } catch (\Exception $e) { $this->aggregate->reject($e); $this->mutex = false; return false; } } private function step($idx) { // If the promise was already resolved, then ignore this step. if (Is::settled($this->aggregate)) { return; } unset($this->pending[$idx]); // Only refill pending promises if we are not locked, preventing the // EachPromise to recursively invoke the provided iterator, which // cause a fatal error: "Cannot resume an already running generator" if ($this->advanceIterator() && !$this->checkIfFinished()) { // Add more pending promises if possible. $this->refillPending(); } } private function checkIfFinished() { if (!$this->pending && !$this->iterable->valid()) { // Resolve the promise if there's nothing left to do. $this->aggregate->resolve(null); return true; } return false; } } PK s�$Zl�� � # promises/src/TaskQueueInterface.phpnu �[��� <?php namespace GuzzleHttp\Promise; interface TaskQueueInterface { /** * Returns true if the queue is empty. * * @return bool */ public function isEmpty(); /** * Adds a task to the queue that will be executed the next time run is * called. */ public function add(callable $task); /** * Execute all of the pending task in the queue. */ public function run(); } PK s�$Z�2~$ $ ! promises/src/PromiseInterface.phpnu �[��� <?php namespace GuzzleHttp\Promise; /** * A promise represents the eventual result of an asynchronous operation. * * The primary way of interacting with a promise is through its then method, * which registers callbacks to receive either a promise’s eventual value or * the reason why the promise cannot be fulfilled. * * @link https://promisesaplus.com/ */ interface PromiseInterface { const PENDING = 'pending'; const FULFILLED = 'fulfilled'; const REJECTED = 'rejected'; /** * Appends fulfillment and rejection handlers to the promise, and returns * a new promise resolving to the return value of the called handler. * * @param callable $onFulfilled Invoked when the promise fulfills. * @param callable $onRejected Invoked when the promise is rejected. * * @return PromiseInterface */ public function then( callable $onFulfilled = null, callable $onRejected = null ); /** * Appends a rejection handler callback to the promise, and returns a new * promise resolving to the return value of the callback if it is called, * or to its original fulfillment value if the promise is instead * fulfilled. * * @param callable $onRejected Invoked when the promise is rejected. * * @return PromiseInterface */ public function otherwise(callable $onRejected); /** * Get the state of the promise ("pending", "rejected", or "fulfilled"). * * The three states can be checked against the constants defined on * PromiseInterface: PENDING, FULFILLED, and REJECTED. * * @return string */ public function getState(); /** * Resolve the promise with the given value. * * @param mixed $value * * @throws \RuntimeException if the promise is already resolved. */ public function resolve($value); /** * Reject the promise with the given reason. * * @param mixed $reason * * @throws \RuntimeException if the promise is already resolved. */ public function reject($reason); /** * Cancels the promise if possible. * * @link https://github.com/promises-aplus/cancellation-spec/issues/7 */ public function cancel(); /** * Waits until the promise completes if possible. * * Pass $unwrap as true to unwrap the result of the promise, either * returning the resolved value or throwing the rejected exception. * * If the promise cannot be waited on, then the promise will be rejected. * * @param bool $unwrap * * @return mixed * * @throws \LogicException if the promise has no wait function or if the * promise does not settle after waiting. */ public function wait($unwrap = true); } PK s�$Z�C�M� � promises/src/Coroutine.phpnu �[��� <?php namespace GuzzleHttp\Promise; use Exception; use Generator; use Throwable; /** * Creates a promise that is resolved using a generator that yields values or * promises (somewhat similar to C#'s async keyword). * * When called, the Coroutine::of method will start an instance of the generator * and returns a promise that is fulfilled with its final yielded value. * * Control is returned back to the generator when the yielded promise settles. * This can lead to less verbose code when doing lots of sequential async calls * with minimal processing in between. * * use GuzzleHttp\Promise; * * function createPromise($value) { * return new Promise\FulfilledPromise($value); * } * * $promise = Promise\Coroutine::of(function () { * $value = (yield createPromise('a')); * try { * $value = (yield createPromise($value . 'b')); * } catch (\Exception $e) { * // The promise was rejected. * } * yield $value . 'c'; * }); * * // Outputs "abc" * $promise->then(function ($v) { echo $v; }); * * @param callable $generatorFn Generator function to wrap into a promise. * * @return Promise * * @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration */ final class Coroutine implements PromiseInterface { /** * @var PromiseInterface|null */ private $currentPromise; /** * @var Generator */ private $generator; /** * @var Promise */ private $result; public function __construct(callable $generatorFn) { $this->generator = $generatorFn(); $this->result = new Promise(function () { while (isset($this->currentPromise)) { $this->currentPromise->wait(); } }); try { $this->nextCoroutine($this->generator->current()); } catch (\Exception $exception) { $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } } /** * Create a new coroutine. * * @return self */ public static function of(callable $generatorFn) { return new self($generatorFn); } public function then( callable $onFulfilled = null, callable $onRejected = null ) { return $this->result->then($onFulfilled, $onRejected); } public function otherwise(callable $onRejected) { return $this->result->otherwise($onRejected); } public function wait($unwrap = true) { return $this->result->wait($unwrap); } public function getState() { return $this->result->getState(); } public function resolve($value) { $this->result->resolve($value); } public function reject($reason) { $this->result->reject($reason); } public function cancel() { $this->currentPromise->cancel(); $this->result->cancel(); } private function nextCoroutine($yielded) { $this->currentPromise = Create::promiseFor($yielded) ->then([$this, '_handleSuccess'], [$this, '_handleFailure']); } /** * @internal */ public function _handleSuccess($value) { unset($this->currentPromise); try { $next = $this->generator->send($value); if ($this->generator->valid()) { $this->nextCoroutine($next); } else { $this->result->resolve($value); } } catch (Exception $exception) { $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } } /** * @internal */ public function _handleFailure($reason) { unset($this->currentPromise); try { $nextYield = $this->generator->throw(Create::exceptionFor($reason)); // The throw was caught, so keep iterating on the coroutine $this->nextCoroutine($nextYield); } catch (Exception $exception) { $this->result->reject($exception); } catch (Throwable $throwable) { $this->result->reject($throwable); } } } PK s�$ZrW�� � promises/src/Is.phpnu �[��� <?php namespace GuzzleHttp\Promise; final class Is { /** * Returns true if a promise is pending. * * @return bool */ public static function pending(PromiseInterface $promise) { return $promise->getState() === PromiseInterface::PENDING; } /** * Returns true if a promise is fulfilled or rejected. * * @return bool */ public static function settled(PromiseInterface $promise) { return $promise->getState() !== PromiseInterface::PENDING; } /** * Returns true if a promise is fulfilled. * * @return bool */ public static function fulfilled(PromiseInterface $promise) { return $promise->getState() === PromiseInterface::FULFILLED; } /** * Returns true if a promise is rejected. * * @return bool */ public static function rejected(PromiseInterface $promise) { return $promise->getState() === PromiseInterface::REJECTED; } } PK s�$Z-�{J�! �! promises/src/Utils.phpnu �[��� <?php namespace GuzzleHttp\Promise; final class Utils { /** * Get the global task queue used for promise resolution. * * This task queue MUST be run in an event loop in order for promises to be * settled asynchronously. It will be automatically run when synchronously * waiting on a promise. * * <code> * while ($eventLoop->isRunning()) { * GuzzleHttp\Promise\Utils::queue()->run(); * } * </code> * * @param TaskQueueInterface $assign Optionally specify a new queue instance. * * @return TaskQueueInterface */ public static function queue(TaskQueueInterface $assign = null) { static $queue; if ($assign) { $queue = $assign; } elseif (!$queue) { $queue = new TaskQueue(); } return $queue; } /** * Adds a function to run in the task queue when it is next `run()` and * returns a promise that is fulfilled or rejected with the result. * * @param callable $task Task function to run. * * @return PromiseInterface */ public static function task(callable $task) { $queue = self::queue(); $promise = new Promise([$queue, 'run']); $queue->add(function () use ($task, $promise) { try { $promise->resolve($task()); } catch (\Throwable $e) { $promise->reject($e); } catch (\Exception $e) { $promise->reject($e); } }); return $promise; } /** * Synchronously waits on a promise to resolve and returns an inspection * state array. * * Returns a state associative array containing a "state" key mapping to a * valid promise state. If the state of the promise is "fulfilled", the * array will contain a "value" key mapping to the fulfilled value of the * promise. If the promise is rejected, the array will contain a "reason" * key mapping to the rejection reason of the promise. * * @param PromiseInterface $promise Promise or value. * * @return array */ public static function inspect(PromiseInterface $promise) { try { return [ 'state' => PromiseInterface::FULFILLED, 'value' => $promise->wait() ]; } catch (RejectionException $e) { return ['state' => PromiseInterface::REJECTED, 'reason' => $e->getReason()]; } catch (\Throwable $e) { return ['state' => PromiseInterface::REJECTED, 'reason' => $e]; } catch (\Exception $e) { return ['state' => PromiseInterface::REJECTED, 'reason' => $e]; } } /** * Waits on all of the provided promises, but does not unwrap rejected * promises as thrown exception. * * Returns an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param PromiseInterface[] $promises Traversable of promises to wait upon. * * @return array */ public static function inspectAll($promises) { $results = []; foreach ($promises as $key => $promise) { $results[$key] = inspect($promise); } return $results; } /** * Waits on all of the provided promises and returns the fulfilled values. * * Returns an array that contains the value of each promise (in the same * order the promises were provided). An exception is thrown if any of the * promises are rejected. * * @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on. * * @return array * * @throws \Exception on error * @throws \Throwable on error in PHP >=7 */ public static function unwrap($promises) { $results = []; foreach ($promises as $key => $promise) { $results[$key] = $promise->wait(); } return $results; } /** * Given an array of promises, return a promise that is fulfilled when all * the items in the array are fulfilled. * * The promise's fulfillment value is an array with fulfillment values at * respective positions to the original array. If any promise in the array * rejects, the returned promise is rejected with the rejection reason. * * @param mixed $promises Promises or values. * @param bool $recursive If true, resolves new promises that might have been added to the stack during its own resolution. * * @return PromiseInterface */ public static function all($promises, $recursive = false) { $results = []; $promise = Each::of( $promises, function ($value, $idx) use (&$results) { $results[$idx] = $value; }, function ($reason, $idx, Promise $aggregate) { $aggregate->reject($reason); } )->then(function () use (&$results) { ksort($results); return $results; }); if (true === $recursive) { $promise = $promise->then(function ($results) use ($recursive, &$promises) { foreach ($promises as $promise) { if (Is::pending($promise)) { return self::all($promises, $recursive); } } return $results; }); } return $promise; } /** * Initiate a competitive race between multiple promises or values (values * will become immediately fulfilled promises). * * When count amount of promises have been fulfilled, the returned promise * is fulfilled with an array that contains the fulfillment values of the * winners in order of resolution. * * This promise is rejected with a {@see AggregateException} if the number * of fulfilled promises is less than the desired $count. * * @param int $count Total number of promises. * @param mixed $promises Promises or values. * * @return PromiseInterface */ public static function some($count, $promises) { $results = []; $rejections = []; return Each::of( $promises, function ($value, $idx, PromiseInterface $p) use (&$results, $count) { if (Is::settled($p)) { return; } $results[$idx] = $value; if (count($results) >= $count) { $p->resolve(null); } }, function ($reason) use (&$rejections) { $rejections[] = $reason; } )->then( function () use (&$results, &$rejections, $count) { if (count($results) !== $count) { throw new AggregateException( 'Not enough promises to fulfill count', $rejections ); } ksort($results); return array_values($results); } ); } /** * Like some(), with 1 as count. However, if the promise fulfills, the * fulfillment value is not an array of 1 but the value directly. * * @param mixed $promises Promises or values. * * @return PromiseInterface */ public static function any($promises) { return self::some(1, $promises)->then(function ($values) { return $values[0]; }); } /** * Returns a promise that is fulfilled when all of the provided promises have * been fulfilled or rejected. * * The returned promise is fulfilled with an array of inspection state arrays. * * @see inspect for the inspection state array format. * * @param mixed $promises Promises or values. * * @return PromiseInterface */ public static function settle($promises) { $results = []; return Each::of( $promises, function ($value, $idx) use (&$results) { $results[$idx] = ['state' => PromiseInterface::FULFILLED, 'value' => $value]; }, function ($reason, $idx) use (&$results) { $results[$idx] = ['state' => PromiseInterface::REJECTED, 'reason' => $reason]; } )->then(function () use (&$results) { ksort($results); return $results; }); } } PK s�$Zc��]@ @ promises/src/Create.phpnu �[��� <?php namespace GuzzleHttp\Promise; final class Create { /** * Creates a promise for a value if the value is not a promise. * * @param mixed $value Promise or value. * * @return PromiseInterface */ public static function promiseFor($value) { if ($value instanceof PromiseInterface) { return $value; } // Return a Guzzle promise that shadows the given promise. if (is_object($value) && method_exists($value, 'then')) { $wfn = method_exists($value, 'wait') ? [$value, 'wait'] : null; $cfn = method_exists($value, 'cancel') ? [$value, 'cancel'] : null; $promise = new Promise($wfn, $cfn); $value->then([$promise, 'resolve'], [$promise, 'reject']); return $promise; } return new FulfilledPromise($value); } /** * Creates a rejected promise for a reason if the reason is not a promise. * If the provided reason is a promise, then it is returned as-is. * * @param mixed $reason Promise or reason. * * @return PromiseInterface */ public static function rejectionFor($reason) { if ($reason instanceof PromiseInterface) { return $reason; } return new RejectedPromise($reason); } /** * Create an exception for a rejected promise value. * * @param mixed $reason * * @return \Exception|\Throwable */ public static function exceptionFor($reason) { if ($reason instanceof \Exception || $reason instanceof \Throwable) { return $reason; } return new RejectionException($reason); } /** * Returns an iterator for the given value. * * @param mixed $value * * @return \Iterator */ public static function iterFor($value) { if ($value instanceof \Iterator) { return $value; } if (is_array($value)) { return new \ArrayIterator($value); } return new \ArrayIterator([$value]); } } PK s�$Z߇'� � "