← All changes
|
includes/sdk/google/guzzlehttp/guzzle/src/RetryMiddleware.php
+12
-12
1.2.3
→
1.4.2
View file →
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace Dudlewebs\WPMCS\GuzzleHttp; | |
| 3 | +namespace Dudlewebs\WPMCS\GCP\GuzzleHttp; | |
| 4 | 4 | |
| 5 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise as P; | |
| 6 | -use Dudlewebs\WPMCS\GuzzleHttp\Promise\PromiseInterface; | |
| 7 | -use Dudlewebs\WPMCS\Psr\Http\Message\RequestInterface; | |
| 8 | -use Dudlewebs\WPMCS\Psr\Http\Message\ResponseInterface; | |
| 5 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise as P; | |
| 6 | +use Dudlewebs\WPMCS\GCP\GuzzleHttp\Promise\PromiseInterface; | |
| 7 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\RequestInterface; | |
| 8 | +use Dudlewebs\WPMCS\GCP\Psr\Http\Message\ResponseInterface; | |
| 9 | 9 | /** |
| 10 | 10 | * Middleware that retries requests based on the boolean result of |
| 11 | 11 | * invoking the provided "decider" function. |
| 12 | 12 | * |
| @@ -46,13 +46,13 @@ | ||
| 46 | 46 | * Default exponential backoff delay function. |
| 47 | 47 | * |
| 48 | 48 | * @return int milliseconds. |
| 49 | 49 | */ |
| 50 | - public static function exponentialDelay(int $retries): int | |
| 50 | + public static function exponentialDelay(int $retries) : int | |
| 51 | 51 | { |
| 52 | 52 | return (int) 2 ** ($retries - 1) * 1000; |
| 53 | 53 | } |
| 54 | - public function __invoke(RequestInterface $request, array $options): PromiseInterface | |
| 54 | + public function __invoke(RequestInterface $request, array $options) : PromiseInterface | |
| 55 | 55 | { |
| 56 | 56 | if (!isset($options['retries'])) { |
| 57 | 57 | $options['retries'] = 0; |
| 58 | 58 | } |
| @@ -61,11 +61,11 @@ | ||
| 61 | 61 | } |
| 62 | 62 | /** |
| 63 | 63 | * Execute fulfilled closure |
| 64 | 64 | */ |
| 65 | - private function onFulfilled(RequestInterface $request, array $options): callable | |
| 65 | + private function onFulfilled(RequestInterface $request, array $options) : callable | |
| 66 | 66 | { |
| 67 | - return function ($value) use ($request, $options) { | |
| 67 | + return function ($value) use($request, $options) { | |
| 68 | 68 | if (!($this->decider)($options['retries'], $request, $value, null)) { |
| 69 | 69 | return $value; |
| 70 | 70 | } |
| 71 | 71 | return $this->doRetry($request, $options, $value); |
| @@ -73,11 +73,11 @@ | ||
| 73 | 73 | } |
| 74 | 74 | /** |
| 75 | 75 | * Execute rejected closure |
| 76 | 76 | */ |
| 77 | - private function onRejected(RequestInterface $req, array $options): callable | |
| 77 | + private function onRejected(RequestInterface $req, array $options) : callable | |
| 78 | 78 | { |
| 79 | - return function ($reason) use ($req, $options) { | |
| 79 | + return function ($reason) use($req, $options) { | |
| 80 | 80 | if (!($this->decider)($options['retries'], $req, null, $reason)) { |
| 81 | 81 | return P\Create::rejectionFor($reason); |
| 82 | 82 | } |
| 83 | 83 | return $this->doRetry($req, $options); |
| @@ -82,9 +82,9 @@ | ||
| 82 | 82 | } |
| 83 | 83 | return $this->doRetry($req, $options); |
| 84 | 84 | }; |
| 85 | 85 | } |
| 86 | - private function doRetry(RequestInterface $request, array $options, ?ResponseInterface $response = null): PromiseInterface | |
| 86 | + private function doRetry(RequestInterface $request, array $options, ?ResponseInterface $response = null) : PromiseInterface | |
| 87 | 87 | { |
| 88 | 88 | $options['delay'] = ($this->delay)(++$options['retries'], $response, $request); |
| 89 | 89 | return $this($request, $options); |
| 90 | 90 | } |