m6web / wsclient-bundle
v5.4.2
2015-06-12 15:50 UTC
Requires
- guzzlehttp/cache-subscriber: @stable
- symfony/stopwatch: @stable
Requires (Dev)
- atoum/atoum: ~1.0
- atoum/atoum-bundle: ~1.0
- guzzlehttp/guzzle: @stable
- m6web/coke: ~1.2
- m6web/symfony2-coding-standard: ~2.0
- symfony/symfony: ~2.3
Suggests
- m6web/redis-bundle: @stable
This package is not auto-updated.
Last update: 2022-02-01 12:33:00 UTC
README
建议使用https://github.com/M6Web/GuzzleHttpBundle
Bundle WSClient 
此bundle提供简单的Web服务客户端,用于调用外部URL。默认情况下,它基于Guzzle,但您也可以插入任何其他客户端库。
服务
没有定义默认服务。您必须设置配置以实例化一个或多个服务。
配置
主要配置键是m6_ws_client
。每个子键定义了一个Web服务客户端的实例。这些服务命名为m6_ws_client_
+ 子键,除了定义主要服务的default
子键以外,该子键定义了主要服务m6_ws_client
。对于每个实例,可以设置多个参数
base_url
:使用服务调用每个URL的基础域名。如果向客户端传递了绝对URL,则忽略基础URL。config
(可选):配置客户端的附加参数,必须是一个数组。请参阅http://guzzle.readthedocs.org/en/latest/clients.html#request-optionscache
(可选)ttl
:默认为86400秒。如果force_request_ttl为FALSE,则最大ttl;如果force_request_ttl为TRUE,则强制ttl。force_request_ttl
(可选):默认为FALSE。如果为TRUE,请求TTL与缓存TTL相同,否则请求TTL根据响应头计算。service
:底层缓存服务(必须实现M6Web\Bundle\WSClientBundle\Cache\CacheInterface)adpater
:适配器类名(必须实现\Doctrine\Common\Cache\Cache)- storage:存储类名(必须实现\GuzzleHttp\Subscriber\Cache\CacheStorageInterface)(可选)
- subscriber:订阅者类(必须实现\GuzzleHttp\Subscriber\Cache\SubscriberInterface)(可选)
- can_cache:确定是否可以缓存请求的可调用函数(可选)
以下是一个简单配置的示例
m6_ws_client: clients: default: base_url: 'toto.m6web.fr' config: timeout: 10 allow_redirects: {max: 5, strict: false, referer: true} exceptions: false cache: ttl: 3600 adapter: M6\Bundle\RedisBundle\Guzzle\RedisCacheAdapter service: m6_redis
简单用例
例如,在一个控制器中
$wsclient = $this->get('m6_ws_client'); $response = $wsclient->get('http://toto.m6web.fr/parse/?content=my_content'); echo $response->getBody();
单元测试
composer install --dev ./bin/atoum