shpartko-packagist/guzzle-bundle-retry-plugin

为Guzzle Bundle提供的重试插件,Guzzle Bundle是一个PHP HTTP客户端库和框架,用于构建RESTful Web服务客户端

1.0.0 2023-08-10 08:10 UTC

This package is auto-updated.

Last update: 2024-09-10 10:17:32 UTC


README

Build Status Coverage Status

要求

安装

使用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文件