doppiogancio/guzzle-bundle-base-path-plugin

一个Guzzle Bundle插件,可帮助您为客户端的每个请求设置基本路径。

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

This package is auto-updated.

Last update: 2024-08-31 00:36:03 UTC


README

一个Guzzle Bundle插件,可帮助您为客户端的每个请求设置基本路径。

先决条件

  • PHP 7.1或更高版本

安装

要安装此包,请在命令行中运行以下命令,您将从[Packagist][4]获取最新稳定版本。

composer require doppiogancio/guzzle-bundle-base-path

用法

启用包

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

基本配置

# 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"

选项

许可

此中间件采用MIT许可 - 有关详细信息,请参阅LICENSE文件。