plugin updates
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -7,7 +8,7 @@ namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
*/
|
||||
class AggregateException extends \WPMailSMTP\Vendor\GuzzleHttp\Promise\RejectionException
|
||||
{
|
||||
public function __construct($msg, array $reasons)
|
||||
public function __construct(string $msg, array $reasons)
|
||||
{
|
||||
parent::__construct($reasons, \sprintf('%s; %d rejected promises', $msg, \count($reasons)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
use Exception;
|
||||
use Generator;
|
||||
use Throwable;
|
||||
/**
|
||||
@@ -26,7 +26,7 @@ use Throwable;
|
||||
* $value = (yield createPromise('a'));
|
||||
* try {
|
||||
* $value = (yield createPromise($value . 'b'));
|
||||
* } catch (\Exception $e) {
|
||||
* } catch (\Throwable $e) {
|
||||
* // The promise was rejected.
|
||||
* }
|
||||
* yield $value . 'c';
|
||||
@@ -39,7 +39,7 @@ use Throwable;
|
||||
*
|
||||
* @return Promise
|
||||
*
|
||||
* @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
|
||||
* @see https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
|
||||
*/
|
||||
final class Coroutine implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
@@ -58,65 +58,61 @@ final class Coroutine implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
public function __construct(callable $generatorFn)
|
||||
{
|
||||
$this->generator = $generatorFn();
|
||||
$this->result = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise(function () {
|
||||
$this->result = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise(function () : void {
|
||||
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)
|
||||
public static function of(callable $generatorFn) : self
|
||||
{
|
||||
return new self($generatorFn);
|
||||
}
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return $this->result->then($onFulfilled, $onRejected);
|
||||
}
|
||||
public function otherwise(callable $onRejected)
|
||||
public function otherwise(callable $onRejected) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return $this->result->otherwise($onRejected);
|
||||
}
|
||||
public function wait($unwrap = \true)
|
||||
public function wait(bool $unwrap = \true)
|
||||
{
|
||||
return $this->result->wait($unwrap);
|
||||
}
|
||||
public function getState()
|
||||
public function getState() : string
|
||||
{
|
||||
return $this->result->getState();
|
||||
}
|
||||
public function resolve($value)
|
||||
public function resolve($value) : void
|
||||
{
|
||||
$this->result->resolve($value);
|
||||
}
|
||||
public function reject($reason)
|
||||
public function reject($reason) : void
|
||||
{
|
||||
$this->result->reject($reason);
|
||||
}
|
||||
public function cancel()
|
||||
public function cancel() : void
|
||||
{
|
||||
$this->currentPromise->cancel();
|
||||
$this->result->cancel();
|
||||
}
|
||||
private function nextCoroutine($yielded)
|
||||
private function nextCoroutine($yielded) : void
|
||||
{
|
||||
$this->currentPromise = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::promiseFor($yielded)->then([$this, '_handleSuccess'], [$this, '_handleFailure']);
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _handleSuccess($value)
|
||||
public function _handleSuccess($value) : void
|
||||
{
|
||||
unset($this->currentPromise);
|
||||
try {
|
||||
@@ -126,8 +122,6 @@ final class Coroutine implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
} else {
|
||||
$this->result->resolve($value);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$this->result->reject($exception);
|
||||
} catch (\Throwable $throwable) {
|
||||
$this->result->reject($throwable);
|
||||
}
|
||||
@@ -135,15 +129,13 @@ final class Coroutine implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _handleFailure($reason)
|
||||
public function _handleFailure($reason) : void
|
||||
{
|
||||
unset($this->currentPromise);
|
||||
try {
|
||||
$nextYield = $this->generator->throw(\WPMailSMTP\Vendor\GuzzleHttp\Promise\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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
final class Create
|
||||
@@ -8,10 +9,8 @@ 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)
|
||||
public static function promiseFor($value) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
if ($value instanceof \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface) {
|
||||
return $value;
|
||||
@@ -31,10 +30,8 @@ final class Create
|
||||
* 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)
|
||||
public static function rejectionFor($reason) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
if ($reason instanceof \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface) {
|
||||
return $reason;
|
||||
@@ -45,12 +42,10 @@ final class Create
|
||||
* Create an exception for a rejected promise value.
|
||||
*
|
||||
* @param mixed $reason
|
||||
*
|
||||
* @return \Exception|\Throwable
|
||||
*/
|
||||
public static function exceptionFor($reason)
|
||||
public static function exceptionFor($reason) : \Throwable
|
||||
{
|
||||
if ($reason instanceof \Exception || $reason instanceof \Throwable) {
|
||||
if ($reason instanceof \Throwable) {
|
||||
return $reason;
|
||||
}
|
||||
return new \WPMailSMTP\Vendor\GuzzleHttp\Promise\RejectionException($reason);
|
||||
@@ -59,10 +54,8 @@ final class Create
|
||||
* Returns an iterator for the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Iterator
|
||||
*/
|
||||
public static function iterFor($value)
|
||||
public static function iterFor($value) : \Iterator
|
||||
{
|
||||
if ($value instanceof \Iterator) {
|
||||
return $value;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
final class Each
|
||||
@@ -17,13 +18,9 @@ final class Each
|
||||
* 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
|
||||
* @param mixed $iterable Iterator or array to iterate over.
|
||||
*/
|
||||
public static function of($iterable, callable $onFulfilled = null, callable $onRejected = null)
|
||||
public static function of($iterable, callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return (new \WPMailSMTP\Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected]))->promise();
|
||||
}
|
||||
@@ -37,12 +34,8 @@ final class Each
|
||||
*
|
||||
* @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)
|
||||
public static function ofLimit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return (new \WPMailSMTP\Vendor\GuzzleHttp\Promise\EachPromise($iterable, ['fulfilled' => $onFulfilled, 'rejected' => $onRejected, 'concurrency' => $concurrency]))->promise();
|
||||
}
|
||||
@@ -53,13 +46,10 @@ final class Each
|
||||
*
|
||||
* @param mixed $iterable
|
||||
* @param int|callable $concurrency
|
||||
* @param callable $onFulfilled
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*/
|
||||
public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null)
|
||||
public static function ofLimitAll($iterable, $concurrency, callable $onFulfilled = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) {
|
||||
return self::ofLimit($iterable, $concurrency, $onFulfilled, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $aggregate) : void {
|
||||
$aggregate->reject($reason);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* Represents a promise that iterates over many promises and invokes
|
||||
* side-effect functions in the process.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInterface
|
||||
{
|
||||
@@ -57,7 +60,7 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
}
|
||||
}
|
||||
/** @psalm-suppress InvalidNullableReturnType */
|
||||
public function promise()
|
||||
public function promise() : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
if ($this->aggregate) {
|
||||
return $this->aggregate;
|
||||
@@ -69,19 +72,16 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
$this->refillPending();
|
||||
} catch (\Throwable $e) {
|
||||
$this->aggregate->reject($e);
|
||||
} catch (\Exception $e) {
|
||||
$this->aggregate->reject($e);
|
||||
}
|
||||
/**
|
||||
* @psalm-suppress NullableReturnStatement
|
||||
* @phpstan-ignore-next-line
|
||||
*/
|
||||
return $this->aggregate;
|
||||
}
|
||||
private function createPromise()
|
||||
private function createPromise() : void
|
||||
{
|
||||
$this->mutex = \false;
|
||||
$this->aggregate = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise(function () {
|
||||
$this->aggregate = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise(function () : void {
|
||||
if ($this->checkIfFinished()) {
|
||||
return;
|
||||
}
|
||||
@@ -97,14 +97,14 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
}
|
||||
});
|
||||
// Clear the references when the promise is resolved.
|
||||
$clearFn = function () {
|
||||
$clearFn = function () : void {
|
||||
$this->iterable = $this->concurrency = $this->pending = null;
|
||||
$this->onFulfilled = $this->onRejected = null;
|
||||
$this->nextPendingIndex = 0;
|
||||
};
|
||||
$this->aggregate->then($clearFn, $clearFn);
|
||||
}
|
||||
private function refillPending()
|
||||
private function refillPending() : void
|
||||
{
|
||||
if (!$this->concurrency) {
|
||||
// Add all pending promises.
|
||||
@@ -113,7 +113,7 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
return;
|
||||
}
|
||||
// Add only up to N pending promises.
|
||||
$concurrency = \is_callable($this->concurrency) ? \call_user_func($this->concurrency, \count($this->pending)) : $this->concurrency;
|
||||
$concurrency = \is_callable($this->concurrency) ? ($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) {
|
||||
@@ -128,7 +128,7 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
while (--$concurrency && $this->advanceIterator() && $this->addPending()) {
|
||||
}
|
||||
}
|
||||
private function addPending()
|
||||
private function addPending() : bool
|
||||
{
|
||||
if (!$this->iterable || !$this->iterable->valid()) {
|
||||
return \false;
|
||||
@@ -138,20 +138,20 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
// Iterable keys may not be unique, so we use a counter to
|
||||
// guarantee uniqueness
|
||||
$idx = $this->nextPendingIndex++;
|
||||
$this->pending[$idx] = $promise->then(function ($value) use($idx, $key) {
|
||||
$this->pending[$idx] = $promise->then(function ($value) use($idx, $key) : void {
|
||||
if ($this->onFulfilled) {
|
||||
\call_user_func($this->onFulfilled, $value, $key, $this->aggregate);
|
||||
($this->onFulfilled)($value, $key, $this->aggregate);
|
||||
}
|
||||
$this->step($idx);
|
||||
}, function ($reason) use($idx, $key) {
|
||||
}, function ($reason) use($idx, $key) : void {
|
||||
if ($this->onRejected) {
|
||||
\call_user_func($this->onRejected, $reason, $key, $this->aggregate);
|
||||
($this->onRejected)($reason, $key, $this->aggregate);
|
||||
}
|
||||
$this->step($idx);
|
||||
});
|
||||
return \true;
|
||||
}
|
||||
private function advanceIterator()
|
||||
private function advanceIterator() : bool
|
||||
{
|
||||
// Place a lock on the iterator so that we ensure to not recurse,
|
||||
// preventing fatal generator errors.
|
||||
@@ -167,13 +167,9 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
$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)
|
||||
private function step(int $idx) : void
|
||||
{
|
||||
// If the promise was already resolved, then ignore this step.
|
||||
if (\WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::settled($this->aggregate)) {
|
||||
@@ -188,7 +184,7 @@ class EachPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromisorInter
|
||||
$this->refillPending();
|
||||
}
|
||||
}
|
||||
private function checkIfFinished()
|
||||
private function checkIfFinished() : bool
|
||||
{
|
||||
if (!$this->pending && !$this->iterable->valid()) {
|
||||
// Resolve the promise if there's nothing left to do.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -7,10 +8,15 @@ namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
*
|
||||
* Thenning off of this promise will invoke the onFulfilled callback
|
||||
* immediately and ignore other callbacks.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class FulfilledPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
private $value;
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __construct($value)
|
||||
{
|
||||
if (\is_object($value) && \method_exists($value, 'then')) {
|
||||
@@ -18,7 +24,7 @@ class FulfilledPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseI
|
||||
}
|
||||
$this->value = $value;
|
||||
}
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
// Return itself if there is no onFulfilled function.
|
||||
if (!$onFulfilled) {
|
||||
@@ -27,42 +33,40 @@ class FulfilledPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseI
|
||||
$queue = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::queue();
|
||||
$p = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise([$queue, 'run']);
|
||||
$value = $this->value;
|
||||
$queue->add(static function () use($p, $value, $onFulfilled) {
|
||||
$queue->add(static function () use($p, $value, $onFulfilled) : void {
|
||||
if (\WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::pending($p)) {
|
||||
try {
|
||||
$p->resolve($onFulfilled($value));
|
||||
} catch (\Throwable $e) {
|
||||
$p->reject($e);
|
||||
} catch (\Exception $e) {
|
||||
$p->reject($e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return $p;
|
||||
}
|
||||
public function otherwise(callable $onRejected)
|
||||
public function otherwise(callable $onRejected) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return $this->then(null, $onRejected);
|
||||
}
|
||||
public function wait($unwrap = \true, $defaultDelivery = null)
|
||||
public function wait(bool $unwrap = \true)
|
||||
{
|
||||
return $unwrap ? $this->value : null;
|
||||
}
|
||||
public function getState()
|
||||
public function getState() : string
|
||||
{
|
||||
return self::FULFILLED;
|
||||
}
|
||||
public function resolve($value)
|
||||
public function resolve($value) : void
|
||||
{
|
||||
if ($value !== $this->value) {
|
||||
throw new \LogicException("Cannot resolve a fulfilled promise");
|
||||
throw new \LogicException('Cannot resolve a fulfilled promise');
|
||||
}
|
||||
}
|
||||
public function reject($reason)
|
||||
public function reject($reason) : void
|
||||
{
|
||||
throw new \LogicException("Cannot reject a fulfilled promise");
|
||||
throw new \LogicException('Cannot reject a fulfilled promise');
|
||||
}
|
||||
public function cancel()
|
||||
public function cancel() : void
|
||||
{
|
||||
// pass
|
||||
}
|
||||
|
||||
@@ -1,42 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
final class Is
|
||||
{
|
||||
/**
|
||||
* Returns true if a promise is pending.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function pending(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
public static function pending(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise) : bool
|
||||
{
|
||||
return $promise->getState() === \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::PENDING;
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is fulfilled or rejected.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function settled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
public static function settled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise) : bool
|
||||
{
|
||||
return $promise->getState() !== \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::PENDING;
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is fulfilled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function fulfilled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
public static function fulfilled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise) : bool
|
||||
{
|
||||
return $promise->getState() === \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::FULFILLED;
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is rejected.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function rejected(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
public static function rejected(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise) : bool
|
||||
{
|
||||
return $promise->getState() === \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::REJECTED;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* Promises/A+ implementation that avoids recursion when possible.
|
||||
*
|
||||
* @link https://promisesaplus.com/
|
||||
* @see https://promisesaplus.com/
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
@@ -24,7 +27,7 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$this->waitFn = $waitFn;
|
||||
$this->cancelFn = $cancelFn;
|
||||
}
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
if ($this->state === self::PENDING) {
|
||||
$p = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise(null, [$this, 'cancel']);
|
||||
@@ -43,11 +46,11 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$rejection = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::rejectionFor($this->result);
|
||||
return $onRejected ? $rejection->then(null, $onRejected) : $rejection;
|
||||
}
|
||||
public function otherwise(callable $onRejected)
|
||||
public function otherwise(callable $onRejected) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return $this->then(null, $onRejected);
|
||||
}
|
||||
public function wait($unwrap = \true)
|
||||
public function wait(bool $unwrap = \true)
|
||||
{
|
||||
$this->waitIfPending();
|
||||
if ($this->result instanceof \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface) {
|
||||
@@ -61,11 +64,11 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
throw \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::exceptionFor($this->result);
|
||||
}
|
||||
}
|
||||
public function getState()
|
||||
public function getState() : string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
public function cancel()
|
||||
public function cancel() : void
|
||||
{
|
||||
if ($this->state !== self::PENDING) {
|
||||
return;
|
||||
@@ -78,8 +81,6 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$fn();
|
||||
} catch (\Throwable $e) {
|
||||
$this->reject($e);
|
||||
} catch (\Exception $e) {
|
||||
$this->reject($e);
|
||||
}
|
||||
}
|
||||
// Reject the promise only if it wasn't rejected in a then callback.
|
||||
@@ -88,15 +89,15 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$this->reject(new \WPMailSMTP\Vendor\GuzzleHttp\Promise\CancellationException('Promise has been cancelled'));
|
||||
}
|
||||
}
|
||||
public function resolve($value)
|
||||
public function resolve($value) : void
|
||||
{
|
||||
$this->settle(self::FULFILLED, $value);
|
||||
}
|
||||
public function reject($reason)
|
||||
public function reject($reason) : void
|
||||
{
|
||||
$this->settle(self::REJECTED, $reason);
|
||||
}
|
||||
private function settle($state, $value)
|
||||
private function settle(string $state, $value) : void
|
||||
{
|
||||
if ($this->state !== self::PENDING) {
|
||||
// Ignore calls with the same resolution.
|
||||
@@ -123,7 +124,7 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
if (!\is_object($value) || !\method_exists($value, 'then')) {
|
||||
$id = $state === self::FULFILLED ? 1 : 2;
|
||||
// It's a success, so resolve the handlers in the queue.
|
||||
\WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::queue()->add(static function () use($id, $value, $handlers) {
|
||||
\WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::queue()->add(static function () use($id, $value, $handlers) : void {
|
||||
foreach ($handlers as $handler) {
|
||||
self::callHandler($id, $value, $handler);
|
||||
}
|
||||
@@ -133,11 +134,11 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$value->handlers = \array_merge($value->handlers, $handlers);
|
||||
} else {
|
||||
// Resolve the handlers when the forwarded promise is resolved.
|
||||
$value->then(static function ($value) use($handlers) {
|
||||
$value->then(static function ($value) use($handlers) : void {
|
||||
foreach ($handlers as $handler) {
|
||||
self::callHandler(1, $value, $handler);
|
||||
}
|
||||
}, static function ($reason) use($handlers) {
|
||||
}, static function ($reason) use($handlers) : void {
|
||||
foreach ($handlers as $handler) {
|
||||
self::callHandler(2, $reason, $handler);
|
||||
}
|
||||
@@ -151,7 +152,7 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
* @param mixed $value Value to pass to the callback.
|
||||
* @param array $handler Array of handler data (promise and callbacks).
|
||||
*/
|
||||
private static function callHandler($index, $value, array $handler)
|
||||
private static function callHandler(int $index, $value, array $handler) : void
|
||||
{
|
||||
/** @var PromiseInterface $promise */
|
||||
$promise = $handler[0];
|
||||
@@ -180,11 +181,9 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
}
|
||||
} catch (\Throwable $reason) {
|
||||
$promise->reject($reason);
|
||||
} catch (\Exception $reason) {
|
||||
$promise->reject($reason);
|
||||
}
|
||||
}
|
||||
private function waitIfPending()
|
||||
private function waitIfPending() : void
|
||||
{
|
||||
if ($this->state !== self::PENDING) {
|
||||
return;
|
||||
@@ -202,13 +201,13 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
$this->reject('Invoking the wait callback did not resolve the promise');
|
||||
}
|
||||
}
|
||||
private function invokeWaitFn()
|
||||
private function invokeWaitFn() : void
|
||||
{
|
||||
try {
|
||||
$wfn = $this->waitFn;
|
||||
$this->waitFn = null;
|
||||
$wfn(\true);
|
||||
} catch (\Exception $reason) {
|
||||
} catch (\Throwable $reason) {
|
||||
if ($this->state === self::PENDING) {
|
||||
// The promise has not been resolved yet, so reject the promise
|
||||
// with the exception.
|
||||
@@ -220,7 +219,7 @@ class Promise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
private function invokeWaitList()
|
||||
private function invokeWaitList() : void
|
||||
{
|
||||
$waitList = $this->waitList;
|
||||
$this->waitList = null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -9,23 +10,21 @@ namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
* which registers callbacks to receive either a promise’s eventual value or
|
||||
* the reason why the promise cannot be fulfilled.
|
||||
*
|
||||
* @link https://promisesaplus.com/
|
||||
* @see https://promisesaplus.com/
|
||||
*/
|
||||
interface PromiseInterface
|
||||
{
|
||||
const PENDING = 'pending';
|
||||
const FULFILLED = 'fulfilled';
|
||||
const REJECTED = 'rejected';
|
||||
public const PENDING = 'pending';
|
||||
public const FULFILLED = 'fulfilled';
|
||||
public 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);
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface;
|
||||
/**
|
||||
* 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,
|
||||
@@ -33,19 +32,15 @@ interface PromiseInterface
|
||||
* fulfilled.
|
||||
*
|
||||
* @param callable $onRejected Invoked when the promise is rejected.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*/
|
||||
public function otherwise(callable $onRejected);
|
||||
public function otherwise(callable $onRejected) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface;
|
||||
/**
|
||||
* 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();
|
||||
public function getState() : string;
|
||||
/**
|
||||
* Resolve the promise with the given value.
|
||||
*
|
||||
@@ -53,7 +48,7 @@ interface PromiseInterface
|
||||
*
|
||||
* @throws \RuntimeException if the promise is already resolved.
|
||||
*/
|
||||
public function resolve($value);
|
||||
public function resolve($value) : void;
|
||||
/**
|
||||
* Reject the promise with the given reason.
|
||||
*
|
||||
@@ -61,13 +56,13 @@ interface PromiseInterface
|
||||
*
|
||||
* @throws \RuntimeException if the promise is already resolved.
|
||||
*/
|
||||
public function reject($reason);
|
||||
public function reject($reason) : void;
|
||||
/**
|
||||
* Cancels the promise if possible.
|
||||
*
|
||||
* @link https://github.com/promises-aplus/cancellation-spec/issues/7
|
||||
* @see https://github.com/promises-aplus/cancellation-spec/issues/7
|
||||
*/
|
||||
public function cancel();
|
||||
public function cancel() : void;
|
||||
/**
|
||||
* Waits until the promise completes if possible.
|
||||
*
|
||||
@@ -76,12 +71,10 @@ interface PromiseInterface
|
||||
*
|
||||
* 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);
|
||||
public function wait(bool $unwrap = \true);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -9,8 +10,6 @@ interface PromisorInterface
|
||||
{
|
||||
/**
|
||||
* Returns a promise.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*/
|
||||
public function promise();
|
||||
public function promise() : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -7,10 +8,15 @@ namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
*
|
||||
* Thenning off of this promise will invoke the onRejected callback
|
||||
* immediately and ignore other callbacks.
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class RejectedPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
private $reason;
|
||||
/**
|
||||
* @param mixed $reason
|
||||
*/
|
||||
public function __construct($reason)
|
||||
{
|
||||
if (\is_object($reason) && \method_exists($reason, 'then')) {
|
||||
@@ -18,7 +24,7 @@ class RejectedPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
}
|
||||
$this->reason = $reason;
|
||||
}
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null)
|
||||
public function then(callable $onFulfilled = null, callable $onRejected = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
// If there's no onRejected callback then just return self.
|
||||
if (!$onRejected) {
|
||||
@@ -27,7 +33,7 @@ class RejectedPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
$queue = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::queue();
|
||||
$reason = $this->reason;
|
||||
$p = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise([$queue, 'run']);
|
||||
$queue->add(static function () use($p, $reason, $onRejected) {
|
||||
$queue->add(static function () use($p, $reason, $onRejected) : void {
|
||||
if (\WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::pending($p)) {
|
||||
try {
|
||||
// Return a resolved promise if onRejected does not throw.
|
||||
@@ -35,40 +41,37 @@ class RejectedPromise implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseIn
|
||||
} catch (\Throwable $e) {
|
||||
// onRejected threw, so return a rejected promise.
|
||||
$p->reject($e);
|
||||
} catch (\Exception $e) {
|
||||
// onRejected threw, so return a rejected promise.
|
||||
$p->reject($e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return $p;
|
||||
}
|
||||
public function otherwise(callable $onRejected)
|
||||
public function otherwise(callable $onRejected) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return $this->then(null, $onRejected);
|
||||
}
|
||||
public function wait($unwrap = \true, $defaultDelivery = null)
|
||||
public function wait(bool $unwrap = \true)
|
||||
{
|
||||
if ($unwrap) {
|
||||
throw \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::exceptionFor($this->reason);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public function getState()
|
||||
public function getState() : string
|
||||
{
|
||||
return self::REJECTED;
|
||||
}
|
||||
public function resolve($value)
|
||||
public function resolve($value) : void
|
||||
{
|
||||
throw new \LogicException("Cannot resolve a rejected promise");
|
||||
throw new \LogicException('Cannot resolve a rejected promise');
|
||||
}
|
||||
public function reject($reason)
|
||||
public function reject($reason) : void
|
||||
{
|
||||
if ($reason !== $this->reason) {
|
||||
throw new \LogicException("Cannot reject a rejected promise");
|
||||
throw new \LogicException('Cannot reject a rejected promise');
|
||||
}
|
||||
}
|
||||
public function cancel()
|
||||
public function cancel() : void
|
||||
{
|
||||
// pass
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -12,10 +13,10 @@ class RejectionException extends \RuntimeException
|
||||
/** @var mixed Rejection reason. */
|
||||
private $reason;
|
||||
/**
|
||||
* @param mixed $reason Rejection reason.
|
||||
* @param string $description Optional description
|
||||
* @param mixed $reason Rejection reason.
|
||||
* @param string|null $description Optional description.
|
||||
*/
|
||||
public function __construct($reason, $description = null)
|
||||
public function __construct($reason, string $description = null)
|
||||
{
|
||||
$this->reason = $reason;
|
||||
$message = 'The promise was rejected';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
@@ -10,15 +11,17 @@ namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
* by calling the `run()` function of the global task queue in an event loop.
|
||||
*
|
||||
* GuzzleHttp\Promise\Utils::queue()->run();
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class TaskQueue implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterface
|
||||
{
|
||||
private $enableShutdown = \true;
|
||||
private $queue = [];
|
||||
public function __construct($withShutdown = \true)
|
||||
public function __construct(bool $withShutdown = \true)
|
||||
{
|
||||
if ($withShutdown) {
|
||||
\register_shutdown_function(function () {
|
||||
\register_shutdown_function(function () : void {
|
||||
if ($this->enableShutdown) {
|
||||
// Only run the tasks if an E_ERROR didn't occur.
|
||||
$err = \error_get_last();
|
||||
@@ -29,15 +32,15 @@ class TaskQueue implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterf
|
||||
});
|
||||
}
|
||||
}
|
||||
public function isEmpty()
|
||||
public function isEmpty() : bool
|
||||
{
|
||||
return !$this->queue;
|
||||
}
|
||||
public function add(callable $task)
|
||||
public function add(callable $task) : void
|
||||
{
|
||||
$this->queue[] = $task;
|
||||
}
|
||||
public function run()
|
||||
public function run() : void
|
||||
{
|
||||
while ($task = \array_shift($this->queue)) {
|
||||
/** @var callable $task */
|
||||
@@ -55,7 +58,7 @@ class TaskQueue implements \WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterf
|
||||
*
|
||||
* Note: This shutdown will occur before any destructors are triggered.
|
||||
*/
|
||||
public function disableShutdown()
|
||||
public function disableShutdown() : void
|
||||
{
|
||||
$this->enableShutdown = \false;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
interface TaskQueueInterface
|
||||
{
|
||||
/**
|
||||
* Returns true if the queue is empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty();
|
||||
public function isEmpty() : bool;
|
||||
/**
|
||||
* Adds a task to the queue that will be executed the next time run is
|
||||
* called.
|
||||
*/
|
||||
public function add(callable $task);
|
||||
public function add(callable $task) : void;
|
||||
/**
|
||||
* Execute all of the pending task in the queue.
|
||||
*/
|
||||
public function run();
|
||||
public function run() : void;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
final class Utils
|
||||
@@ -17,11 +18,9 @@ final class Utils
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
|
||||
*
|
||||
* @return TaskQueueInterface
|
||||
* @param TaskQueueInterface|null $assign Optionally specify a new queue instance.
|
||||
*/
|
||||
public static function queue(\WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
|
||||
public static function queue(\WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterface
|
||||
{
|
||||
static $queue;
|
||||
if ($assign) {
|
||||
@@ -36,22 +35,18 @@ final class Utils
|
||||
* 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)
|
||||
public static function task(callable $task) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
$queue = self::queue();
|
||||
$promise = new \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise([$queue, 'run']);
|
||||
$queue->add(function () use($task, $promise) {
|
||||
$queue->add(function () use($task, $promise) : void {
|
||||
try {
|
||||
if (\WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::pending($promise)) {
|
||||
$promise->resolve($task());
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$promise->reject($e);
|
||||
} catch (\Exception $e) {
|
||||
$promise->reject($e);
|
||||
}
|
||||
});
|
||||
return $promise;
|
||||
@@ -67,10 +62,8 @@ final class Utils
|
||||
* key mapping to the rejection reason of the promise.
|
||||
*
|
||||
* @param PromiseInterface $promise Promise or value.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function inspect(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
public static function inspect(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise) : array
|
||||
{
|
||||
try {
|
||||
return ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::FULFILLED, 'value' => $promise->wait()];
|
||||
@@ -78,8 +71,6 @@ final class Utils
|
||||
return ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::REJECTED, 'reason' => $e->getReason()];
|
||||
} catch (\Throwable $e) {
|
||||
return ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::REJECTED, 'reason' => $e];
|
||||
} catch (\Exception $e) {
|
||||
return ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::REJECTED, 'reason' => $e];
|
||||
}
|
||||
}
|
||||
/**
|
||||
@@ -91,10 +82,8 @@ final class Utils
|
||||
* @see inspect for the inspection state array format.
|
||||
*
|
||||
* @param PromiseInterface[] $promises Traversable of promises to wait upon.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function inspectAll($promises)
|
||||
public static function inspectAll($promises) : array
|
||||
{
|
||||
$results = [];
|
||||
foreach ($promises as $key => $promise) {
|
||||
@@ -111,12 +100,9 @@ final class Utils
|
||||
*
|
||||
* @param iterable<PromiseInterface> $promises Iterable of PromiseInterface objects to wait on.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Exception on error
|
||||
* @throws \Throwable on error in PHP >=7
|
||||
* @throws \Throwable on error
|
||||
*/
|
||||
public static function unwrap($promises)
|
||||
public static function unwrap($promises) : array
|
||||
{
|
||||
$results = [];
|
||||
foreach ($promises as $key => $promise) {
|
||||
@@ -134,15 +120,13 @@ final class Utils
|
||||
*
|
||||
* @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)
|
||||
public static function all($promises, bool $recursive = \false) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
$results = [];
|
||||
$promise = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx) use(&$results) {
|
||||
$promise = \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx) use(&$results) : void {
|
||||
$results[$idx] = $value;
|
||||
}, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise $aggregate) {
|
||||
}, function ($reason, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\Promise $aggregate) : void {
|
||||
$aggregate->reject($reason);
|
||||
})->then(function () use(&$results) {
|
||||
\ksort($results);
|
||||
@@ -173,14 +157,12 @@ final class Utils
|
||||
*
|
||||
* @param int $count Total number of promises.
|
||||
* @param mixed $promises Promises or values.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*/
|
||||
public static function some($count, $promises)
|
||||
public static function some(int $count, $promises) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
$results = [];
|
||||
$rejections = [];
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $p) use(&$results, $count) {
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx, \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $p) use(&$results, $count) : void {
|
||||
if (\WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::settled($p)) {
|
||||
return;
|
||||
}
|
||||
@@ -188,7 +170,7 @@ final class Utils
|
||||
if (\count($results) >= $count) {
|
||||
$p->resolve(null);
|
||||
}
|
||||
}, function ($reason) use(&$rejections) {
|
||||
}, function ($reason) use(&$rejections) : void {
|
||||
$rejections[] = $reason;
|
||||
})->then(function () use(&$results, &$rejections, $count) {
|
||||
if (\count($results) !== $count) {
|
||||
@@ -203,10 +185,8 @@ final class Utils
|
||||
* 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)
|
||||
public static function any($promises) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
return self::some(1, $promises)->then(function ($values) {
|
||||
return $values[0];
|
||||
@@ -221,15 +201,13 @@ final class Utils
|
||||
* @see inspect for the inspection state array format.
|
||||
*
|
||||
* @param mixed $promises Promises or values.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*/
|
||||
public static function settle($promises)
|
||||
public static function settle($promises) : \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface
|
||||
{
|
||||
$results = [];
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx) use(&$results) {
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($promises, function ($value, $idx) use(&$results) : void {
|
||||
$results[$idx] = ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::FULFILLED, 'value' => $value];
|
||||
}, function ($reason, $idx) use(&$results) {
|
||||
}, function ($reason, $idx) use(&$results) : void {
|
||||
$results[$idx] = ['state' => \WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface::REJECTED, 'reason' => $reason];
|
||||
})->then(function () use(&$results) {
|
||||
\ksort($results);
|
||||
|
||||
@@ -1,334 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Vendor\GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* 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\queue()->run();
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @param TaskQueueInterface $assign Optionally specify a new queue instance.
|
||||
*
|
||||
* @return TaskQueueInterface
|
||||
*
|
||||
* @deprecated queue will be removed in guzzlehttp/promises:2.0. Use Utils::queue instead.
|
||||
*/
|
||||
function queue(\WPMailSMTP\Vendor\GuzzleHttp\Promise\TaskQueueInterface $assign = null)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::queue($assign);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated task will be removed in guzzlehttp/promises:2.0. Use Utils::task instead.
|
||||
*/
|
||||
function task(callable $task)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::task($task);
|
||||
}
|
||||
/**
|
||||
* Creates a promise for a value if the value is not a promise.
|
||||
*
|
||||
* @param mixed $value Promise or value.
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*
|
||||
* @deprecated promise_for will be removed in guzzlehttp/promises:2.0. Use Create::promiseFor instead.
|
||||
*/
|
||||
function promise_for($value)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::promiseFor($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
|
||||
*
|
||||
* @deprecated rejection_for will be removed in guzzlehttp/promises:2.0. Use Create::rejectionFor instead.
|
||||
*/
|
||||
function rejection_for($reason)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::rejectionFor($reason);
|
||||
}
|
||||
/**
|
||||
* Create an exception for a rejected promise value.
|
||||
*
|
||||
* @param mixed $reason
|
||||
*
|
||||
* @return \Exception|\Throwable
|
||||
*
|
||||
* @deprecated exception_for will be removed in guzzlehttp/promises:2.0. Use Create::exceptionFor instead.
|
||||
*/
|
||||
function exception_for($reason)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::exceptionFor($reason);
|
||||
}
|
||||
/**
|
||||
* Returns an iterator for the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Iterator
|
||||
*
|
||||
* @deprecated iter_for will be removed in guzzlehttp/promises:2.0. Use Create::iterFor instead.
|
||||
*/
|
||||
function iter_for($value)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Create::iterFor($value);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspect instead.
|
||||
*/
|
||||
function inspect(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::inspect($promise);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated inspect will be removed in guzzlehttp/promises:2.0. Use Utils::inspectAll instead.
|
||||
*/
|
||||
function inspect_all($promises)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::inspectAll($promises);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated unwrap will be removed in guzzlehttp/promises:2.0. Use Utils::unwrap instead.
|
||||
*/
|
||||
function unwrap($promises)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::unwrap($promises);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated all will be removed in guzzlehttp/promises:2.0. Use Utils::all instead.
|
||||
*/
|
||||
function all($promises, $recursive = \false)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::all($promises, $recursive);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated some will be removed in guzzlehttp/promises:2.0. Use Utils::some instead.
|
||||
*/
|
||||
function some($count, $promises)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::some($count, $promises);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated any will be removed in guzzlehttp/promises:2.0. Use Utils::any instead.
|
||||
*/
|
||||
function any($promises)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::any($promises);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated settle will be removed in guzzlehttp/promises:2.0. Use Utils::settle instead.
|
||||
*/
|
||||
function settle($promises)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Utils::settle($promises);
|
||||
}
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @deprecated each will be removed in guzzlehttp/promises:2.0. Use Each::of instead.
|
||||
*/
|
||||
function each($iterable, callable $onFulfilled = null, callable $onRejected = null)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::of($iterable, $onFulfilled, $onRejected);
|
||||
}
|
||||
/**
|
||||
* Like each, 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
|
||||
*
|
||||
* @deprecated each_limit will be removed in guzzlehttp/promises:2.0. Use Each::ofLimit instead.
|
||||
*/
|
||||
function each_limit($iterable, $concurrency, callable $onFulfilled = null, callable $onRejected = null)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::ofLimit($iterable, $concurrency, $onFulfilled, $onRejected);
|
||||
}
|
||||
/**
|
||||
* Like each_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
|
||||
*
|
||||
* @deprecated each_limit_all will be removed in guzzlehttp/promises:2.0. Use Each::ofLimitAll instead.
|
||||
*/
|
||||
function each_limit_all($iterable, $concurrency, callable $onFulfilled = null)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Each::ofLimitAll($iterable, $concurrency, $onFulfilled);
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is fulfilled.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated is_fulfilled will be removed in guzzlehttp/promises:2.0. Use Is::fulfilled instead.
|
||||
*/
|
||||
function is_fulfilled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::fulfilled($promise);
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is rejected.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated is_rejected will be removed in guzzlehttp/promises:2.0. Use Is::rejected instead.
|
||||
*/
|
||||
function is_rejected(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::rejected($promise);
|
||||
}
|
||||
/**
|
||||
* Returns true if a promise is fulfilled or rejected.
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated is_settled will be removed in guzzlehttp/promises:2.0. Use Is::settled instead.
|
||||
*/
|
||||
function is_settled(\WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface $promise)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Is::settled($promise);
|
||||
}
|
||||
/**
|
||||
* Create a new coroutine.
|
||||
*
|
||||
* @see Coroutine
|
||||
*
|
||||
* @return PromiseInterface
|
||||
*
|
||||
* @deprecated coroutine will be removed in guzzlehttp/promises:2.0. Use Coroutine::of instead.
|
||||
*/
|
||||
function coroutine(callable $generatorFn)
|
||||
{
|
||||
return \WPMailSMTP\Vendor\GuzzleHttp\Promise\Coroutine::of($generatorFn);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Vendor;
|
||||
|
||||
// Don't redefine the functions if included multiple times.
|
||||
if (!\function_exists('WPMailSMTP\\Vendor\\GuzzleHttp\\Promise\\promise_for')) {
|
||||
require __DIR__ . '/functions.php';
|
||||
}
|
||||
Reference in New Issue
Block a user