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


PHP BeforeEvent::getRequest方法代码示例

本文整理汇总了PHP中GuzzleHttp\Event\BeforeEvent::getRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP BeforeEvent::getRequest方法的具体用法?PHP BeforeEvent::getRequest怎么用?PHP BeforeEvent::getRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Event\BeforeEvent的用法示例。


在下文中一共展示了BeforeEvent::getRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (file_exists($this->getFullFilePath($request))) {
         $responsedata = file_get_contents($this->getFullFilePath($request));
         $mf = new MessageFactory();
         $event->intercept($mf->fromMessage($responsedata));
     }
 }
开发者ID:callcolor,项目名称:GuzzleRecorder,代码行数:9,代码来源:GuzzleRecorder.php

示例2: 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

示例3: 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 reading a response body
     $request = $event->getRequest();
     if ($this->readBodies && $request->getBody()) {
         while (!$request->getBody()->eof()) {
             $request->getBody()->read(8096);
         }
     }
     $saveTo = $event->getRequest()->getConfig()->get('save_to');
     if (null !== $saveTo) {
         $body = $item->getBody();
         if (is_resource($saveTo)) {
             fwrite($saveTo, $body);
         } elseif (is_string($saveTo)) {
             file_put_contents($saveTo, $body);
         } elseif ($saveTo instanceof StreamInterface) {
             $saveTo->write($body);
         }
     }
     $event->intercept($item);
 }
开发者ID:453111208,项目名称:bbc,代码行数:30,代码来源:Mock.php

示例4: sign

 public function sign(BeforeEvent $e)
 {
     $method = $e->getRequest()->getMethod();
     if (preg_match('/post|put|delete/i', $method)) {
         $e->getRequest()->setHeader('X-Insta-Forwarded-For', join('|', array($this->ip_address, hash_hmac('SHA256', $this->ip_address, $this->client_secret))));
     }
     // var_dump($e->getRequest()->getHeaders());
 }
开发者ID:hitoshi-t-pepe3,项目名称:Instaphp,代码行数:8,代码来源:InstagramSignedAuthEvent.php

示例5: sign

 /**
  * Check if the requested authentication type matches and set the
  * required X-Token and X-Signature headers
  *
  * @param BeforeEvent $event
  */
 public function sign(BeforeEvent $event)
 {
     if ($event->getRequest()->getConfig()['auth'] == 'tevoauth') {
         $request = $event->getRequest();
         $request->setHeader('X-Token', $this->_apiToken);
         $request->setHeader('X-Signature', $this->getSignature($request));
     }
 }
开发者ID:ticketevolution,项目名称:ticketevolution-php,代码行数:14,代码来源:TEvoAuth.php

示例6: auth

 public function auth(BeforeEvent $event, $name)
 {
     $cfg = $event->getRequest()->getConfig()['auth'];
     $request = $event->getRequest();
     if ($cfg == 'basic') {
         call_user_func_array([$this, 'basic' . ucfirst($this->_class) . 'Auth'], [$request]);
     }
 }
开发者ID:onefasteuro,项目名称:oauth-app,代码行数:8,代码来源:Auth.php

示例7: auth

 public function auth(BeforeEvent $event, $name)
 {
     $cfg = $event->getRequest()->getConfig()['auth'];
     $request = $event->getRequest();
     if ($cfg == 'basic') {
         //add the token to the query field
         $request->setQuery((string) $request->getQuery() . '&access_token=' . $this->service->getAppId() . '|' . $this->service->getAppSecret());
     }
 }
开发者ID:onefasteuro,项目名称:oauth-app,代码行数:9,代码来源:FacebookAuth.php

示例8: onBefore

 /**
  * The onBefore event that will add the hmac errors to the request headers
  *
  * @param BeforeEvent $event
  */
 public function onBefore(BeforeEvent $event)
 {
     if ($event !== null && $event->getRequest() !== null) {
         $hmac = (new Manager($this->adapter))->key($this->key)->data($this->data)->time($this->time)->encode()->getHmac();
         $event->getRequest()->setHeader($this->headerNames['hmac'], $hmac->getHmac());
         $event->getRequest()->setHeader($this->headerNames['data'], $hmac->getData());
         $event->getRequest()->setHeader($this->headerNames['time'], $hmac->getTime());
     }
 }
开发者ID:rolies106,项目名称:hmac,代码行数:14,代码来源:HmacHeadersGuzzleEvent.php

示例9: 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

示例10: onBefore

 public function onBefore(BeforeEvent $event)
 {
     if (!$this->loggedIn || !is_null($this->expires) && time() > $this->expires) {
         $details = $this->logIn();
         $this->query = $details['query'];
         $this->headers = $details['headers'];
     }
     $event->getRequest()->getQuery()->merge($this->query);
     $head = $event->getRequest()->getHeaders();
     $event->getRequest()->setHeaders(array_replace($head, $this->headers));
 }
开发者ID:keboola,项目名称:generic-extractor,代码行数:11,代码来源:LoginSubscriber.php

示例11: Auth

 public function Auth(BeforeEvent $event, $name)
 {
     $cfg = $event->getRequest()->getConfig()['auth'];
     if ($cfg == 'basic') {
         $basic = base64_encode($this->service->getAppId() . ':' . $this->service->getAppSecret());
         $event->getRequest()->setHeaders(['Authorization' => 'Basic ' . $basic]);
     } else {
         if ($cfg == 'bearer') {
             $event->getRequest()->setHeaders(['Authorization' => 'Bearer ' . $this->service->getAccessToken()]);
         }
     }
 }
开发者ID:onefasteuro,项目名称:oauth-app,代码行数:12,代码来源:TwitterAuth.php

示例12: onBefore

 /**
  * Updates the request with an Authorization header when auth is 'fetched_auth_token'.
  *
  *   use GuzzleHttp\Client;
  *   use Google\Auth\OAuth2;
  *   use Google\Auth\AuthTokenFetcher;
  *
  *   $config = [..<oauth config param>.];
  *   $oauth2 = new OAuth2($config)
  *   $scoped = new AuthTokenFetcher($oauth2,
  *                                  $cache = new Memcache(),
  *                                  [ 'prefix' => 'OAuth2::' ]);
  *   $client = new Client([
  *      'base_url' => 'https://www.googleapis.com/taskqueue/v1beta2/projects/',
  *      'defaults' => ['auth' => 'google_auth']
  *   ]);
  *
  *   $res = $client->('myproject/taskqueues/myqueue');
  */
 public function onBefore(BeforeEvent $event)
 {
     // Requests using "auth"="google_auth" will be authorized.
     $request = $event->getRequest();
     if ($request->getConfig()['auth'] != 'google_auth') {
         return;
     }
     // Use the cached value if its available.
     //
     // TODO: correct caching; update the call to setCachedValue to set the expiry
     // to the value returned with the auth token.
     //
     // TODO: correct caching; enable the cache to be cleared.
     $cached = $this->getCachedValue();
     if (!is_null($cached)) {
         $request->setHeader('Authorization', 'Bearer ' . $cached);
         return;
     }
     // Fetch the auth token.
     $auth_tokens = $this->fetcher->fetchAuthToken();
     if (array_key_exists('access_token', $auth_tokens)) {
         $request->setHeader('Authorization', 'Bearer ' . $auth_tokens['access_token']);
         $this->setCachedValue($auth_tokens['access_token']);
     }
 }
开发者ID:bshaffer,项目名称:google-auth-library-php,代码行数:44,代码来源:AuthTokenFetcher.php

示例13: onBefore

 /**
  * @param BeforeEvent $event
  */
 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     $span = $this->guzzleMessageSpanFactory->fromOutgoingRequest($request);
     $this->tracer->trace([$span]);
     $request->addHeaders(['X-B3-SpanId' => (string) $span->getIdentifier(), 'X-B3-TraceId' => (string) $span->getTraceIdentifier(), 'X-B3-ParentSpanId' => (string) $span->getParentIdentifier(), 'X-B3-Flags' => $span->getDebug() ? '1' : '0']);
 }
开发者ID:sroze,项目名称:tolerance,代码行数:10,代码来源:TracerSubscriber.php

示例14: onBefore

 /**
  * @param BeforeEvent $event
  */
 public function onBefore(BeforeEvent $event)
 {
     if ($this->logger) {
         $request = $event->getRequest();
         $this->logger->info($this->formatMessage($request->getMethod(), $request->getUrl()), ['requestHeaders' => $request->getHeaders(), 'requestBody' => (string) $request->getBody()]);
     }
 }
开发者ID:przemczan,项目名称:puszek-sdk-bundle,代码行数:10,代码来源:Logger.php

示例15: onBefore

 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (isset(self::$purgeMethods[$request->getMethod()])) {
         $this->storage->purge($request);
     }
 }
开发者ID:gunnartorfis,项目名称:plex_requests,代码行数:7,代码来源:PurgeSubscriber.php


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