shpartko-packagist / guzzle-bundle-retry-plugin
为Guzzle Bundle提供的重试插件,Guzzle Bundle是一个PHP HTTP客户端库和框架,用于构建RESTful Web服务客户端
1.0.0
2023-08-10 08:10 UTC
Requires
- php: ^7.3 || ^8.0
- caseyamcl/guzzle_retry_middleware: ^2.8
- eightpoints/guzzle-bundle: ^7.6|^8.0
- guzzlehttp/guzzle: ^6.3|^7.0
- symfony/dependency-injection: ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15|^3.20
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^8.1|^9.5
This package is auto-updated.
Last update: 2024-09-10 10:17:32 UTC
README
要求
- PHP 7.3或更高版本
- Guzzle Bundle
- Guzzle 重试中间件
安装
使用composer
composer.json
{ "require": { "eugenganshorn/guzzle-bundle-retry-plugin": "^1.0" } }
命令行
$ composer require eugenganshorn/guzzle-bundle-retry-plugin
使用方法
启用插件
Symfony 2.x和3.x
插件将通过app/AppKernel.php
中的Bundle构造函数被激活/连接,例如
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([ new EugenGanshorn\Bundle\GuzzleBundleRetryPlugin\GuzzleBundleRetryPlugin(), ])
Symfony 4
Symfony 4中改变了Bundle的注册方式,现在您需要更改src/Kernel.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(); } } }
基本配置
# 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](https://github.com/caseyamcl/guzzle_retry_middleware#options)
许可证
此中间件遵循MIT许可证 - 有关详细信息,请参阅LICENSE文件