本文整理汇总了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));
}
}
示例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);
}
示例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);
}
示例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());
}
示例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));
}
}
示例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]);
}
}
示例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());
}
}
示例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());
}
}
示例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);
}
示例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));
}
示例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()]);
}
}
}
示例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']);
}
}
示例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']);
}
示例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()]);
}
}
示例15: onBefore
public function onBefore(BeforeEvent $event)
{
$request = $event->getRequest();
if (isset(self::$purgeMethods[$request->getMethod()])) {
$this->storage->purge($request);
}
}