本文整理汇总了PHP中GuzzleHttp\Event\BeforeEvent::getClient方法的典型用法代码示例。如果您正苦于以下问题:PHP BeforeEvent::getClient方法的具体用法?PHP BeforeEvent::getClient怎么用?PHP BeforeEvent::getClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Event\BeforeEvent
的用法示例。
在下文中一共展示了BeforeEvent::getClient方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addAuthHeaders
public function addAuthHeaders(BeforeEvent $event)
{
/*
* Get Consumer ID and Private Key from auth and then unset it
*/
$auth = $event->getClient()->getDefaultOption('auth');
if ($auth === null) {
throw new \Exception('Http client is missing \'auth\' parameters', 1466965269);
}
$consumerId = $auth[0];
$privateKey = $auth[1];
$event->getClient()->setDefaultOption('auth', null);
/*
* Get Request URL, method, and timestamp to calculate signature
*/
$requestUrl = $event->getRequest()->getUrl();
//decode url back to normal to nextCursor issue. automatic url encoding
$requestUrl = rawurldecode($requestUrl);
$event->getRequest()->setUrl($requestUrl);
$requestMethod = $event->getRequest()->getMethod();
$timestamp = Utils::getMilliseconds();
$signature = Signature::calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp);
/*
* Add required headers to request
*/
$headers = ['WM_SVC.NAME' => 'Walmart Marketplace', 'WM_QOS.CORRELATION_ID' => base64_encode(Random::string(16)), 'WM_SEC.TIMESTAMP' => $timestamp, 'WM_SEC.AUTH_SIGNATURE' => $signature, 'WM_CONSUMER.ID' => $consumerId];
$currentHeaders = $event->getRequest()->getHeaders();
unset($currentHeaders['Authorization']);
$updatedHeaders = array_merge($currentHeaders, $headers);
$event->getRequest()->setHeaders($updatedHeaders);
}
示例2: onBefore
public function onBefore(BeforeEvent $event)
{
$body = $event->getRequest()->getBody();
// Only works when there is a body with a known size.
if (!$body || !$body->getSize()) {
return;
}
// Wrap the existing request body in an upload decorator.
$progressBody = new UploadProgressStream($body, $this->uploadProgress, $event->getClient(), $event->getRequest());
$event->getRequest()->setBody($progressBody);
}
示例3: onBefore
/**
* {@inheritdoc}
*/
public function onBefore(BeforeEvent $event, $name)
{
$client = $event->getClient();
$request = $event->getRequest();
$time = time() + $client->getTimeDrift();
$authenticated = $client->isAuthenticated();
$signature = null;
if ($authenticated) {
$signature = $this->getSignature($request, $time);
}
$this->createOvhHeader($request, $signature, $time);
}
示例4: testInterceptsWithEvent
public function testInterceptsWithEvent()
{
$response = new Response(200);
$res = null;
$t = new Transaction(new Client(), new Request('GET', '/'));
$t->getRequest()->getEmitter()->on('complete', function ($e) use(&$res) {
$res = $e;
});
$e = new BeforeEvent($t);
$e->intercept($response);
$this->assertTrue($e->isPropagationStopped());
$this->assertSame($res->getClient(), $e->getClient());
}
示例5: let
function let(SiteConfigBuilder $siteConfigBuilder, SiteConfig $siteConfig, Factory $authenticatorFactory, ClientInterface $guzzle, Emitter $emitter, BeforeEvent $beforeEvent, CompleteEvent $completeEvent, RequestInterface $request, ResponseInterface $response, Factory $authenticatorFactory)
{
$siteConfig->getHost()->willReturn('example.com');
$siteConfigBuilder->buildForHost('example.com')->willReturn($siteConfig);
$guzzle->getEmitter()->willReturn($emitter);
$request->getHost()->willReturn('example.com');
$beforeEvent->getRequest()->willReturn($request);
$beforeEvent->getClient()->willReturn($guzzle);
$response->getBody()->willReturn('<html></html>');
$completeEvent->getResponse()->willReturn($response);
$completeEvent->getRequest()->willReturn($request);
$completeEvent->getClient()->willReturn($guzzle);
$this->beConstructedWith($siteConfigBuilder, $authenticatorFactory);
}
示例6: loginIfRequired
public function loginIfRequired(BeforeEvent $event)
{
if (($config = $this->buildSiteConfig($event->getRequest())) === false) {
return;
}
if (!$config->requiresLogin()) {
return;
}
$client = $event->getClient();
$authenticator = $this->authenticatorFactory->buildFromSiteConfig($config);
if (!$authenticator->isLoggedIn($client)) {
$emitter = $client->getEmitter();
$emitter->detach($this);
$authenticator->login($client);
$emitter->attach($this);
}
}
示例7: onBefore
/**
* @throws \OutOfBoundsException|\Exception
*/
public function onBefore(BeforeEvent $event)
{
if (!($item = array_shift($this->queue))) {
throw new \OutOfBoundsException('Mock queue is empty');
} elseif ($item instanceof RequestException) {
throw $item;
}
// Emulate the receiving of the response headers
$request = $event->getRequest();
$transaction = new Transaction($event->getClient(), $request);
$transaction->setResponse($item);
$request->getEmitter()->emit('headers', new HeadersEvent($transaction));
// Emulate reading a response body
if ($this->readBodies && $request->getBody()) {
while (!$request->getBody()->eof()) {
$request->getBody()->read(8096);
}
}
$event->intercept($item);
}