doppiogancio/guzzle-bundle-base-path-plugin

A Plugin for Guzzle Bundle, that will help you setting a base path to each request of your client.

v1.0.0 2023-11-01 16:58 UTC

This package is auto-updated.

Last update: 2024-12-01 00:09:29 UTC


README

A Plugin for Guzzle Bundle, that will help you to set a base path to each request of your client.

Prerequisites

  • PHP 7.1 or above

Installation

To install this bundle, run the command below on the command line and you will get the latest stable version from [Packagist][4].

composer require doppiogancio/guzzle-bundle-base-path

Usage

Enable bundle

Find next lines in src/Kernel.php:

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 Doppiogancio\Bundle\GuzzleBundleBasePathPlugin\GuzzleBundleBasePathPlugin(),
            ]);
        } else {
            yield new $class();
        }
    }
}

Basic configuration

# app/config/config.yml

eight_points_guzzle:
    clients:
        api_payment:
            base_url: "http://api.domain.tld"
            
            options:
                auth: oauth2

            # plugin settings
            plugin:
                base_path:
                    base_path:       "/api/v3"

Options

License

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