php GuzzleHttp-Event-BeforeEvent类(方法)实例源码

下面列出了php GuzzleHttp-Event-BeforeEvent 类(方法)源码代码实例,从而了解它的用法。

作者:callcolo    项目:GuzzleRecorde   
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));
     }
 }

作者:bshaffe    项目:google-auth-library-ph   
/**
  * 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']);
     }
 }

作者:sroz    项目:toleranc   
/**
  * @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']);
 }

作者:Quantomi    项目:guzzle5-oauth2-subscribe   
/**
  * Request before-send event handler.
  *
  * Adds the Authorization header if an access token was found.
  *
  * @param BeforeEvent $event Event received
  */
 public function onBefore(BeforeEvent $event)
 {
     $this->checkTokenData();
     if ($this->tokenData->accessToken) {
         $this->accessTokenSigner->sign($event->getRequest(), $this->tokenData->accessToken);
     }
 }

作者:przemcza    项目:puszek-sdk-bundl   
/**
  * @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()]);
     }
 }

作者:gunnartorfi    项目:plex_request   
public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (isset(self::$purgeMethods[$request->getMethod()])) {
         $this->storage->purge($request);
     }
 }

作者:JRW    项目:Brogrammers_HackWestern_201   
/**
  * Signs an API request using an authentication flow.
  *
  * @param BeforeEvent $event
  */
 public function sign(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if ($request->getMethod() === 'GET') {
         $this->authenticateGetRequest($request);
     }
 }

作者:45311120    项目:bb   
/**
  * @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);
 }

作者:onefasteur    项目:oauth-ap   
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]);
     }
 }

作者:v4sp    项目:LolApiBundl   
public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (!($response = $this->cache->fetch($request->__toString()))) {
         return;
     }
     $event->intercept($response);
 }

作者:hitoshi-t-pepe    项目:Instaph   
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());
 }

作者:ticketevolutio    项目:ticketevolution-ph   
/**
  * 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));
     }
 }

作者:notomat    项目:stream-ph   
public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     $this->context->signer()->sign(new Message($request));
     $headers = new MessageHeaders($request);
     $headers->set("Authorization", $headers->get("Signature"));
     $request->removeHeader("Signature");
 }

作者:rusowyle    项目:guzzle-wsse-auth-plugi   
/**
  * Add WSSE auth headers
  *
  * @param Event $event
  */
 public function onRequestCreate(\GuzzleHttp\Event\BeforeEvent $event)
 {
     $request = $event->getRequest();
     $nonce = call_user_func($this->noncer);
     $created = date('r');
     $digest = call_user_func($this->digester, $nonce, $created, $this->password);
     $request->addHeaders(array("Authorization" => "WSSE profile=\"UsernameToken\"", "X-WSSE" => "UsernameToken Username=\"{$this->username}\", PasswordDigest=\"{$digest}\", Nonce=\"{$nonce}\", Created=\"{$created}\""));
 }

作者:knedl    项目:twitter-nette-skeleto   
/**
  * Updates the request query with the developer key if auth is set to simple.
  *
  *   use Google\Auth\Subscriber\SimpleSubscriber;
  *   use GuzzleHttp\Client;
  *
  *   $my_key = 'is not the same as yours';
  *   $subscriber = new SimpleSubscriber(['key' => $my_key]);
  *
  *   $client = new Client([
  *      'base_url' => 'https://www.googleapis.com/discovery/v1/',
  *      'defaults' => ['auth' => 'simple']
  *   ]);
  *   $client->getEmitter()->attach($subscriber);
  *
  *   $res = $client->get('drive/v2/rest');
  *
  * @param BeforeEvent $event
  */
 public function onBefore(BeforeEvent $event)
 {
     // Requests using "auth"="simple" with the developer key.
     $request = $event->getRequest();
     if ($request->getConfig()['auth'] != 'simple') {
         return;
     }
     $request->getQuery()->overwriteWith($this->config);
 }

作者:onefasteur    项目:oauth-ap   
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());
     }
 }

作者:rolies10    项目:hma   
/**
  * 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());
     }
 }

作者:kanariezwar    项目:guzzle-oauth2-plugi   
/**
  * Add the Authorization header to requests.
  *
  * @param BeforeEvent $event Event received
  */
 public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if ($request->getConfig()->get('auth') == 'oauth2') {
         $token = $this->getAccessToken();
         if ($token !== null) {
             $request->setHeader('Authorization', 'Bearer ' . $token->getToken());
         }
     }
 }

作者:emanueleminott    项目:embedl   
/**
  * Guzzle event used to set the key parameter.
  *
  * @codeCoverageIgnore
  *
  * @param BeforeEvent $event
  */
 private function getBeforeEvent(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if ('api.embed.ly' === $request->getHost()) {
         $requestQuery = $request->getQuery();
         $requestQuery->setEncodingType(false);
         $requestQuery->set('key', $this->apiKey);
         $request->setQuery($requestQuery);
     }
 }

作者:thomaschaa    项目:cache-subscribe   
public function onBefore(BeforeEvent $event)
 {
     $request = $event->getRequest();
     if (isset(self::$purgeMethods[$request->getMethod()])) {
         $this->storage->purge($request->getUrl());
         if ('PURGE' === $request->getMethod()) {
             $event->intercept(new Response(204));
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号