eugenganshorn / guzzle-bundle-retry-plugin
Guzzle Bundle 重试插件,一个用于构建 RESTful 网络服务客户端的 PHP HTTP 客户端库和框架
1.4.0
2023-09-20 12:55 UTC
Requires
- php: ^8.0
- caseyamcl/guzzle_retry_middleware: ^2.2
- eightpoints/guzzle-bundle: ^7.6|^8.0
- guzzlehttp/guzzle: ^6.3|^7.0
- symfony/dependency-injection: ^4.0|^5.0|^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.6
README
需求
- PHP 8.0 或更高版本
- Guzzle Bundle
- Guzzle 重试中间件
安装
使用 Composer
composer.json
{ "require": { "eugenganshorn/guzzle-bundle-retry-plugin": "^1.0" } }
命令行
$ composer require eugenganshorn/guzzle-bundle-retry-plugin
用法
启用组件
Symfony 4
插件将通过组件构造函数在 app/AppKernel.php
中激活/连接,例如:找到以下行
foreach ($contents as $class => $envs) { if (isset($envs['all']) || isset($envs[$this->environment])) { yield new $class(); } }
并替换为
foreach ($contents as $class => $envs) { if (isset($envs['all']) || isset($envs[$this->environment])) { if ($class === \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle::class) { yield new $class([ new \EugenGanshorn\Bundle\GuzzleBundleRetryPlugin\GuzzleBundleRetryPlugin(), ]); } else { yield new $class(); } } }
Symfony 5 & 6
重写 registerBundles
方法在 src/Kernel.php
中以将插件连接到组件
public function registerBundles(): iterable { $contents = require $this->getBundlesPath(); foreach ($contents as $class => $envs) { if ($envs[$this->environment] ?? $envs['all'] ?? false) { if ($class === EightPointsGuzzleBundle::class) { yield new $class([ new GuzzleBundleRetryPlugin(), ]); } else { yield new $class(); } } } }
基本配置
# app/config/config.yml // config/packages/eight_points_guzzle.yaml eight_points_guzzle: clients: your_client: base_url: "http://api.domain.tld" # plugin settings plugin: retry: ~
高级配置
查看中间件选项:https://github.com/caseyamcl/guzzle_retry_middleware#options
许可证
此中间件受 MIT 许可证的许可 - 有关详细信息,请参阅 LICENSE 文件