slepic / psr-http-observing-client
PSR ClientInterface实现,它包装另一个实现,并使用slepic/http-transfer包中的ObserverInterfce来观察传输。
0.1.0
2019-07-07 01:25 UTC
Requires
- php: ^7.0
- psr/http-client: ^1.0
- slepic/http-transfer: ^0.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpunit/phpunit: ~5.0
Suggests
- slepic/http-transfer-observer-implementation: See existing observers to plug in your psr http client.
Provides
This package is auto-updated.
Last update: 2024-09-07 13:16:32 UTC
README
psr-http-observing-client
PSR ClientInterface实现,它包装另一个实现,并使用slepic/http-transfer包中的ObserverInterfce来观察传输。
要求
PHP 7
安装
使用composer安装
composer require slepic/psr-http-observing-client
使用方法
将任何\Psr\Http\Client\ClientInterface
实例包装在\Slepic\Psr\Http\ObservingClient\ObservingClient
中,并传入来自\Slepic\Http\Transfer\Observer\ObserverInterface
包的slepic/http-transfer
。
如果您现在通过ObservingClient发送所有请求,观察者将被通知所有传输的开始和结束。
查看示例,其中我们使用\Slepic\Http\Transfer\History\HistoryObserver
记录带时序的请求和响应。
$storage = new ArrayStorage();
$observer = new HistoryObserver($storage);
$psrClient = new SomePsrClient();
$client = new ObservingClient($psrClient, $observer);
try {
$response = $client->sendRequest($request);
} catch (\Exception $e) {
assert($storage[0]->getRequest() === $request);
assert($storage[0]->getException() === $e);
assert(0 < ($storage[0]->getEndTime() - $storage[0]->getStartTime()));
throw $e;
}
assert($storage[0]->getRequest() === $request);
assert($storage[0]->getResponse() === $response);
assert(0 < ($storage[0]->getEndTime() - $storage[0]->getStartTime()));
观察者
查看slepic/http-transfer-observer-implementation
以获取现有观察者的列表。