From b5ea5604064adc99eb3a555e17a099490b29eff5 Mon Sep 17 00:00:00 2001 From: Petr Levtonov Date: Sat, 5 Nov 2022 15:32:38 +0100 Subject: [PATCH] Loosen up php and dependency version constraints to allow a broader usage of this package --- CHANGELOG.md | 11 +++- composer.json | 11 ++-- composer.lock | 118 +++++++++++++++++------------------ src/RetryAfterMiddleware.php | 15 +++-- 4 files changed, 83 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b981aa..45f71d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ The format is based on [Keep a Changelog][1], and this project adheres to ## [Unreleased] +## [1.1.0] - 2022-11-05 + +### Changed + +- Loosen up php and dependency version constraints to allow a broader usage of this package. + ## [1.0.1] - 2022-11-05 ### Added @@ -31,6 +37,7 @@ The format is based on [Keep a Changelog][1], and this project adheres to [1]: https://keepachangelog.com/en/1.1.0/ [2]: https://semver.org/spec/v2.0.0.html -[Unreleased]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/compare/1.0.1...HEAD -[1.0.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.1 +[Unreleased]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/compare/1.1.0...HEAD +[1.1.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.1.0 +[1.0.1]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.1 [1.0.0]: https://github.com/Poor-Plebs/guzzle-retry-after-middleware/releases/1.0.0 diff --git a/composer.json b/composer.json index 6fc563d..e0c4678 100644 --- a/composer.json +++ b/composer.json @@ -50,13 +50,12 @@ "roave/security-advisories": "dev-latest" }, "require": { - "php": "^8.1.0", - "guzzlehttp/guzzle": "^7.5.0", - "guzzlehttp/promises": "^1.5.0", - "nesbot/carbon": "^2.62.0", + "php": "^8.0.0", + "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5", + "guzzlehttp/promises": "^1.0.0", + "nesbot/carbon": "^2.0.0", "psr/http-message": "^1.0.0", - "psr/log": "^3.0.0", - "psr/simple-cache": "^3.0.0" + "psr/simple-cache": "^1.0.0 || ^2.0.0 || ^3.0.0" }, "scripts": { "all": [ diff --git a/composer.lock b/composer.lock index 10cc0aa..134e1ae 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2b01426b64cf7f09621deb8ebe845b5e", + "content-hash": "3f32eb8784523388c55bcd7e244eb906", "packages": [ { "name": "guzzlehttp/guzzle", @@ -599,56 +599,6 @@ }, "time": "2016-08-06T14:39:51+00:00" }, - { - "name": "psr/log", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", - "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", - "shasum": "" - }, - "require": { - "php": ">=8.0.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "support": { - "source": "https://github.com/php-fig/log/tree/3.0.0" - }, - "time": "2021-07-14T16:46:02+00:00" - }, { "name": "psr/simple-cache", "version": "3.0.0", @@ -2955,18 +2905,68 @@ }, "time": "2019-01-08T18:20:26+00:00" }, + { + "name": "psr/log", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/fe5ea303b0887d5caefd3d431c3e61ad47037001", + "reference": "fe5ea303b0887d5caefd3d431c3e61ad47037001", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/3.0.0" + }, + "time": "2021-07-14T16:46:02+00:00" + }, { "name": "roave/security-advisories", "version": "dev-latest", "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "45470fe91508b361778c84cb492d17826c04bbd7" + "reference": "964c5d9ca40d0ec72db203b3dd6382a30abef616" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/45470fe91508b361778c84cb492d17826c04bbd7", - "reference": "45470fe91508b361778c84cb492d17826c04bbd7", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/964c5d9ca40d0ec72db203b3dd6382a30abef616", + "reference": "964c5d9ca40d0ec72db203b3dd6382a30abef616", "shasum": "" }, "conflict": { @@ -3015,7 +3015,7 @@ "cart2quote/module-quotation": ">=4.1.6,<=4.4.5|>=5,<5.4.4", "cartalyst/sentry": "<=2.1.6", "catfan/medoo": "<1.7.5", - "centreon/centreon": "<21.4.16|>=21.10,<21.10.8|>=22,<22.4.1", + "centreon/centreon": "<22.10-beta.1", "cesnet/simplesamlphp-module-proxystatistics": "<3.1", "codeception/codeception": "<3.1.3|>=4,<4.1.22", "codeigniter/framework": "<=3.0.6", @@ -3102,7 +3102,7 @@ "friendsofsymfony/user-bundle": ">=1.2,<1.3.5", "friendsoftypo3/mediace": ">=7.6.2,<7.6.5", "froala/wysiwyg-editor": "<3.2.7", - "froxlor/froxlor": "<0.10.38", + "froxlor/froxlor": "<0.10.39", "fuel/core": "<1.8.1", "gaoming13/wechat-php-sdk": "<=1.10.2", "genix/cms": "<=1.1.11", @@ -3219,7 +3219,7 @@ "onelogin/php-saml": "<2.10.4", "oneup/uploader-bundle": "<1.9.3|>=2,<2.1.5", "open-web-analytics/open-web-analytics": "<1.7.4", - "opencart/opencart": "<=3.0.3.2", + "opencart/opencart": "<=3.0.3.7", "openid/php-openid": "<2.3", "openmage/magento-lts": "<19.4.15|>=20,<20.0.13", "orchid/platform": ">=9,<9.4.4", @@ -3488,7 +3488,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T10:04:41+00:00" + "time": "2022-11-04T21:04:09+00:00" }, { "name": "sebastian/cli-parser", @@ -5658,7 +5658,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.1.0" + "php": "^8.0.0" }, "platform-dev": [], "plugin-api-version": "2.3.0" diff --git a/src/RetryAfterMiddleware.php b/src/RetryAfterMiddleware.php index ab30e4c..c3c358c 100644 --- a/src/RetryAfterMiddleware.php +++ b/src/RetryAfterMiddleware.php @@ -7,18 +7,19 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use GuzzleHttp\Exception\BadResponseException; -use GuzzleHttp\Promise\Create; use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\SimpleCache\CacheInterface; use Throwable; +use function GuzzleHttp\Promise\rejection_for; + class RetryAfterMiddleware { private const HEADER = 'Retry-After'; - public function __construct(protected readonly CacheInterface $cache) + public function __construct(protected CacheInterface $cache) { } @@ -33,7 +34,7 @@ public function __invoke(string $key): callable $now = new CarbonImmutable(); if ($retryAfter->greaterThanOrEqualTo($now)) { - return Create::rejectionFor(new RetryAfterException( + return rejection_for(new RetryAfterException( $this->retryAfterMessage($retryAfter, $now), $request, )); @@ -48,10 +49,14 @@ function (ResponseInterface $response) use ($key): mixed { }, function (Throwable $reason) use ($key): PromiseInterface { if ($reason instanceof BadResponseException) { - $this->checkHeader($reason->getResponse(), $key); + $response = $reason->getResponse(); + + if ($response instanceof ResponseInterface) { + $this->checkHeader($response, $key); + } } - return Create::rejectionFor($reason); + return rejection_for($reason); } ); };