gregurco / guzzle-bundle-wsse-plugin
为Guzzle Bundle的WSSE插件,Guzzle Bundle是一个PHP HTTP客户端库和框架,用于构建RESTful Web服务客户端
v1.0.2
2017-11-16 08:19 UTC
Requires
- php: ^7.0
- eightpoints/guzzle-bundle: ~7.0
- guzzlehttp/guzzle: ^6.0
- symfony/config: ~2.7|~3.0|~4.0
- symfony/dependency-injection: ~2.7|~3.0|~4.0
- symfony/expression-language: ~2.7|~3.0|~4.0
- symfony/http-kernel: ~2.7|~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ~6.1
- satooshi/php-coveralls: ~1.0
This package is auto-updated.
Last update: 2024-09-05 18:18:14 UTC
README
此插件将WSSE功能集成到Guzzle Bundle中,Guzzle Bundle是一个用于构建RESTful Web服务客户端的扩展包。
要求
- PHP 7.0或更高版本
- Guzzle Bundle
安装
使用composer
composer.json
{ "require": { "gregurco/guzzle-bundle-wsse-plugin": "dev-master" } }
命令行
$ composer require gregurco/guzzle-bundle-wsse-plugin
用法
启用扩展包
Symfony 2.x和3.x
插件将通过扩展包构造函数在app/AppKernel.php
中激活/连接,如下所示
new EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle([ new Gregurco\Bundle\GuzzleBundleWssePlugin\GuzzleBundleWssePlugin(), ])
Symfony 4
Symfony 4中扩展包的注册方式已更改,现在您需要更改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 \Gregurco\Bundle\GuzzleBundleWssePlugin\GuzzleBundleWssePlugin(), ]); } else { yield new $class(); } } }
基本配置
# app/config/config.yml eight_points_guzzle: clients: api_payment: base_url: "http://api.domain.tld" # define headers, options # plugin settings plugin: wsse: username: "acme" password: "pa55w0rd" created_at: "-10 seconds" # optional
与Guzzle一起使用
<?php # Optional: Set third parameter by a expression (if not, current time will be used automatically) # https://php.ac.cn/manual/en/datetime.formats.relative.php # Useful if there is a small difference of time between client and server # DateTime object will be regenerated for every request $wsse = new \Gregurco\Bundle\GuzzleBundleWssePlugin\Middleware\WsseAuthMiddleware($username, $password); $stack = \GuzzleHttp\HandlerStack::create(); // Add the wsse middleware to the handler stack. $stack->push($wsse->attach()); $client = new \GuzzleHttp\Client(['handler' => $stack]); $response = $client->get('http://www.8points.de');
许可证
此中间件根据MIT许可证授权 - 有关详细信息,请参阅LICENSE文件。