当前位置: 首页>>代码示例>>PHP>>正文


PHP BeforeEvent::getClient方法代码示例

本文整理汇总了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);
 }
开发者ID:fillup,项目名称:walmart-partner-api-sdk-php,代码行数:31,代码来源:AuthSubscriber.php

示例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);
 }
开发者ID:bobozhangshao,项目名称:HeartCare,代码行数:11,代码来源:Progress.php

示例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);
 }
开发者ID:nafresne,项目名称:guzzle-ovh-plugin,代码行数:15,代码来源:OvhSubscriber.php

示例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());
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:13,代码来源:RequestBeforeSendEventTest.php

示例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);
 }
开发者ID:bdunogier,项目名称:guzzle-site-authenticator,代码行数:14,代码来源:AuthenticatorSubscriberSpec.php

示例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);
     }
 }
开发者ID:bdunogier,项目名称:guzzle-site-authenticator,代码行数:17,代码来源:AuthenticatorSubscriber.php

示例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);
 }
开发者ID:PodWhoo,项目名称:sitepoint_codes,代码行数:23,代码来源:Mock.php


注:本文中的GuzzleHttp\Event\BeforeEvent::getClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。