本文整理汇总了PHP中GuzzleHttp\Event\BeforeEvent类的典型用法代码示例。如果您正苦于以下问题:PHP BeforeEvent类的具体用法?PHP BeforeEvent怎么用?PHP BeforeEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BeforeEvent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例3: 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
示例4: onBefore
/**
* 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);
}
}
开发者ID:Quantomic,项目名称:guzzle5-oauth2-subscriber,代码行数:14,代码来源:OAuth2Subscriber.php
示例5: 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
示例6: 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
示例7: sign
/**
* 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);
}
}
开发者ID:JRWu,项目名称:Brogrammers_HackWestern_2015,代码行数:12,代码来源:GooglePlacesApiAuthenticator.php
示例8: 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
示例9: 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
示例10: onBefore
public function onBefore(BeforeEvent $event)
{
$request = $event->getRequest();
if (!($response = $this->cache->fetch($request->__toString()))) {
return;
}
$event->intercept($response);
}
开发者ID:v4sp1,项目名称:LolApiBundle,代码行数:8,代码来源:CacheSubscriber.php
示例11: 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
示例12: 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
示例13: onBefore
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");
}
开发者ID:notomato,项目名称:stream-php,代码行数:8,代码来源:SignRequestSubscriber.php
示例14: onRequestCreate
/**
* 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}\""));
}
开发者ID:rusowyler,项目名称:guzzle-wsse-auth-plugin,代码行数:13,代码来源:WsseAuthPlugin.php
示例15: onBefore
/**
* 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);
}
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:28,代码来源:SimpleSubscriber.php
示例16: 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
示例17: 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
示例18: onBefore
/**
* 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());
}
}
}
开发者ID:kanariezwart,项目名称:guzzle-oauth2-plugin,代码行数:15,代码来源:Oauth2Subscriber.php
示例19: getBeforeEvent
/**
* 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);
}
}
开发者ID:emanueleminotto,项目名称:embedly,代码行数:17,代码来源:Client.php
示例20: onBefore
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));
}
}
}
开发者ID:thomaschaaf,项目名称:cache-subscriber,代码行数:10,代码来源:PurgeSubscriber.php
注:本文中的GuzzleHttp\Event\BeforeEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论