PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.7.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.7.0
0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src / RetryMiddleware.php
wp-mail-smtp / vendor_prefixed / guzzlehttp / guzzle / src Last commit date
Cookie 3 years ago Exception 3 years ago Handler 3 years ago Client.php 3 years ago ClientInterface.php 3 years ago HandlerStack.php 3 years ago MessageFormatter.php 3 years ago Middleware.php 3 years ago Pool.php 3 years ago PrepareBodyMiddleware.php 3 years ago RedirectMiddleware.php 3 years ago RequestOptions.php 3 years ago RetryMiddleware.php 3 years ago TransferStats.php 3 years ago UriTemplate.php 3 years ago Utils.php 3 years ago functions.php 3 years ago functions_include.php 3 years ago
RetryMiddleware.php
100 lines
1 <?php
2
3 namespace WPMailSMTP\Vendor\GuzzleHttp;
4
5 use WPMailSMTP\Vendor\GuzzleHttp\Promise\PromiseInterface;
6 use WPMailSMTP\Vendor\GuzzleHttp\Promise\RejectedPromise;
7 use WPMailSMTP\Vendor\GuzzleHttp\Psr7;
8 use WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface;
9 use WPMailSMTP\Vendor\Psr\Http\Message\ResponseInterface;
10 /**
11 * Middleware that retries requests based on the boolean result of
12 * invoking the provided "decider" function.
13 */
14 class RetryMiddleware
15 {
16 /** @var callable */
17 private $nextHandler;
18 /** @var callable */
19 private $decider;
20 /** @var callable */
21 private $delay;
22 /**
23 * @param callable $decider Function that accepts the number of retries,
24 * a request, [response], and [exception] and
25 * returns true if the request is to be
26 * retried.
27 * @param callable $nextHandler Next handler to invoke.
28 * @param callable $delay Function that accepts the number of retries
29 * and [response] and returns the number of
30 * milliseconds to delay.
31 */
32 public function __construct(callable $decider, callable $nextHandler, callable $delay = null)
33 {
34 $this->decider = $decider;
35 $this->nextHandler = $nextHandler;
36 $this->delay = $delay ?: __CLASS__ . '::exponentialDelay';
37 }
38 /**
39 * Default exponential backoff delay function.
40 *
41 * @param int $retries
42 *
43 * @return int milliseconds.
44 */
45 public static function exponentialDelay($retries)
46 {
47 return (int) \pow(2, $retries - 1) * 1000;
48 }
49 /**
50 * @param RequestInterface $request
51 * @param array $options
52 *
53 * @return PromiseInterface
54 */
55 public function __invoke(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $request, array $options)
56 {
57 if (!isset($options['retries'])) {
58 $options['retries'] = 0;
59 }
60 $fn = $this->nextHandler;
61 return $fn($request, $options)->then($this->onFulfilled($request, $options), $this->onRejected($request, $options));
62 }
63 /**
64 * Execute fulfilled closure
65 *
66 * @return mixed
67 */
68 private function onFulfilled(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $req, array $options)
69 {
70 return function ($value) use($req, $options) {
71 if (!\call_user_func($this->decider, $options['retries'], $req, $value, null)) {
72 return $value;
73 }
74 return $this->doRetry($req, $options, $value);
75 };
76 }
77 /**
78 * Execute rejected closure
79 *
80 * @return callable
81 */
82 private function onRejected(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $req, array $options)
83 {
84 return function ($reason) use($req, $options) {
85 if (!\call_user_func($this->decider, $options['retries'], $req, null, $reason)) {
86 return \WPMailSMTP\Vendor\GuzzleHttp\Promise\rejection_for($reason);
87 }
88 return $this->doRetry($req, $options);
89 };
90 }
91 /**
92 * @return self
93 */
94 private function doRetry(\WPMailSMTP\Vendor\Psr\Http\Message\RequestInterface $request, array $options, \WPMailSMTP\Vendor\Psr\Http\Message\ResponseInterface $response = null)
95 {
96 $options['delay'] = \call_user_func($this->delay, ++$options['retries'], $response);
97 return $this($request, $options);
98 }
99 }
100