eugenganshorn/guzzle-bundle-retry-plugin

Retry Plugin for Guzzle Bundle, a PHP HTTP client library and framework for building RESTful web service clients

1.4.0 2023-09-20 12:55 UTC

This package is auto-updated.

Last update: 2024-03-20 14:55:59 UTC


README

Build Status Coverage Status

Requirements

Installation

Using composer:

composer.json
{
    "require": {
        "eugenganshorn/guzzle-bundle-retry-plugin": "^1.0"
    }
}
command line
$ composer require eugenganshorn/guzzle-bundle-retry-plugin

Usage

Enable bundle

Symfony 4

Plugin will be activated/connected through bundle constructor in app/AppKernel.php, like this: Find next lines:

foreach ($contents as $class => $envs) {
    if (isset($envs['all']) || isset($envs[$this->environment])) {
        yield new $class();
    }
}

and replace them by:

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

Override the registerBundles method in src/Kernel.php to connect the plugin to the bundle:

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();
            }
        }
    }
}

Basic configuration

# 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:
                    ~

Advanced configuration

See middleware options: https://github.com/caseyamcl/guzzle_retry_middleware#options

License

This middleware is licensed under the MIT License - see the LICENSE file for details