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


PHP Middleware::mapRequest方法代码示例

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


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

示例1: getStackFunction

 public function getStackFunction()
 {
     return Middleware::mapRequest(function (RequestInterface $request) {
         // Notice that we have to return a request object
         return $request->withHeader('X-Vault-Token', $this->_token);
     });
 }
开发者ID:koshatul,项目名称:vault,代码行数:7,代码来源:VaultAuthToken.php

示例2: sayHelloBeforeTheRequest

 public function sayHelloBeforeTheRequest()
 {
     parent::$stack->push(Middleware::mapRequest(function (RequestInterface $request) {
         print 'Hello' . PHP_EOL;
         return $request;
     }));
 }
开发者ID:rbadillap,项目名称:twitterstreaming,代码行数:7,代码来源:MyGuzzleMiddleware.php

示例3: testSSO

 public function testSSO()
 {
     $pid = Helper::getSomeProject();
     $user = Helper::getSomeUser();
     Helper::getClient()->getProjects()->addUser($pid, $user['uid']);
     $targetUrl = "/#s=/gdc/projects/{$pid}|projectDashboardPage";
     $sso = new SSO(null, null, KBGDC_API_URL);
     $ssoLink = $sso->getUrl(KBGDC_USERNAME, KBGDC_SSO_KEY, KBGDC_SSO_PROVIDER, $targetUrl, $user['email'], 3600, KBGDC_SSO_KEY_PASS);
     $stack = \GuzzleHttp\HandlerStack::create();
     $lastRequest = null;
     $stack->push(\GuzzleHttp\Middleware::mapRequest(function (Request $request) use(&$lastRequest) {
         $lastRequest = $request;
         return $request;
     }));
     $client = new Client(['handler' => $stack, \GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => true, 'verify' => false]);
     try {
         $client->request('GET', $ssoLink, ['headers' => ['Accept' => 'application/json']]);
     } catch (RequestException $e) {
         if ($e->hasResponse()) {
             $response = $e->getResponse()->getBody();
             $this->fail("{$response} on link: {$ssoLink}");
         } else {
             $this->fail($e->getMessage() . " on link: {$ssoLink}");
         }
     }
     /** @var Request $lastRequest */
     $result = $lastRequest->getUri()->__toString();
     $this->assertStringEndsWith($targetUrl, urldecode($result));
 }
开发者ID:keboola,项目名称:gooddata-php-client,代码行数:29,代码来源:SSOTest.php

示例4: __construct

 /**
  * @param string $id
  * @param string $secret
  * @param string $url
  */
 public function __construct($id, $secret, $url)
 {
     $this->logger = new NullLogger();
     if (!strlen($id) || !strlen($secret)) {
         throw new InvalidArgumentException('api_id and api_secret must both be provided');
     }
     $validatedUrl = filter_var($url, FILTER_VALIDATE_URL);
     if (!$validatedUrl) {
         throw new InvalidArgumentException($url . ' is not a valid URL');
     }
     $this->id = $id;
     $this->secret = $secret;
     $this->baseUrl = $validatedUrl . '/page/api/';
     $handlerStack = HandlerStack::create(GuzzleHttp\choose_handler());
     $handlerStack->push(Middleware::mapRequest(function (RequestInterface $request) {
         $uri = $request->getUri();
         $query = new Query($uri->getQuery());
         /*
          * Add id and version to the query
          */
         $query = $query->merge(Query::createFromArray(['api_id' => $this->id, 'api_ver' => '2']));
         /*
          * Add timestamp to the query
          */
         if (!$query->hasKey('api_ts')) {
             $query = $query->merge(Query::createFromArray(['api_ts', time()]));
         }
         $query = $query->merge(Query::createFromArray(['api_mac' => $this->generateMac($uri->getPath(), $query)]));
         return $request->withUri($uri->withQuery((string) $query));
     }));
     $this->guzzleClient = new GuzzleClient(['handler' => $handlerStack]);
 }
开发者ID:JoelESvensson,项目名称:bsd-api-php-guzzle6,代码行数:37,代码来源:Client.php

示例5: createAuthStack

 private function createAuthStack()
 {
     $stack = HandlerStack::create();
     $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
         return $request->withHeader('Authorization', "Bearer " . $this->accessToken);
     }));
     return $stack;
 }
开发者ID:polidog,项目名称:esa-php,代码行数:8,代码来源:Client.php

示例6: getCallable

 /**
  * @return callable
  */
 public function getCallable()
 {
     return Middleware::mapRequest(function (RequestInterface $request) {
         if ($request->hasHeader(AbstractHttpClient::HEADER_HOST_YVES)) {
             $this->getLogger()->info(sprintf('Transfer request [%s] %s', $request->getMethod(), $request->getRequestTarget()), ['guzzle-body' => $request->getBody()->getContents()]);
         }
         return $request;
     });
 }
开发者ID:spryker,项目名称:ZedRequest,代码行数:12,代码来源:ZedRequestLogPlugin.php

示例7: getSigningMiddleware

 private function getSigningMiddleware()
 {
     $region = $this->getConnection()->hasParam('aws_region') ? $this->getConnection()->getParam('aws_region') : getenv('AWS_REGION');
     $signer = new SignatureV4('es', $region);
     $credProvider = $this->getCredentialProvider();
     return Middleware::mapRequest(function (RequestInterface $req) use($signer, $credProvider) {
         return $signer->signRequest($req, $credProvider()->wait());
     });
 }
开发者ID:ruflin,项目名称:elastica,代码行数:9,代码来源:AwsAuthV4.php

示例8: get

 public static function get(array $options, $key)
 {
     $stack = HandlerStack::create();
     $stack->unshift(Middleware::mapRequest(function (RequestInterface $request) use($key) {
         return $request->withUri(Uri::withQueryValue($request->getUri(), 'key', $key));
     }));
     $options['handler'] = $stack;
     return new Client($options);
 }
开发者ID:mcfedr,项目名称:youtubelivestreamsbundle,代码行数:9,代码来源:GuzzleClientFactory.php

示例9: create

 public static function create()
 {
     return Middleware::mapRequest(function (RequestInterface $request) {
         if ($request->getUri()->getHost() !== 'api.github.com') {
             return $request;
         }
         $authorization = 'token ' . getenv('GITHUB_TOKEN');
         return $request->withHeader('Authorization', $authorization);
     });
 }
开发者ID:hannesvdvreken,项目名称:psr7-demo,代码行数:10,代码来源:GithubAuth.php

示例10: getCallable

 /**
  * @return callable
  */
 public function getCallable()
 {
     return Middleware::mapRequest(function (RequestInterface $request) {
         if ($request->hasHeader('X-Yves-Host')) {
             $requestId = new RequestId();
             $request = $request->withAddedHeader('X-Request-ID', $requestId->getRequestId());
         }
         return $request;
     });
 }
开发者ID:spryker,项目名称:Application,代码行数:13,代码来源:ZedRequestHeaderMiddleware.php

示例11: setupBeforeClass

 public static function setupBeforeClass()
 {
     $baseUri = getenv('TEST_BASE_URL');
     $handler = HandlerStack::create();
     $handler->push(Middleware::mapRequest(function (RequestInterface $request) {
         $baseUri = $request->getUri();
         $baseUri = $baseUri->withPath('/app_test.php' . $baseUri->getPath());
         return $request->withUri($baseUri);
     }));
     self::$staticClient = new Client(['base_uri' => $baseUri, 'defaults' => ['exceptions' => false], 'handler' => $handler]);
     self::bootKernel();
 }
开发者ID:juuuuuu,项目名称:budget,代码行数:12,代码来源:ApiTestCase.php

示例12: getClient

 /**
  * @return \GuzzleHttp\Client
  */
 public function getClient()
 {
     if ($this->_client === null) {
         $this->_client = new Client($this->clientOptions);
         $handler = $this->_client->getConfig('handler');
         $handler->push(Middleware::mapRequest(function ($request) {
             $this->_restObject = new RestObject($request);
             return $request;
         }));
     }
     return $this->_client;
 }
开发者ID:mole-chen,项目名称:yii2,代码行数:15,代码来源:Client.php

示例13: __construct

 /**
  *
  * @param \Kazoo\SDK $sdk
  */
 public function __construct(SDK $sdk)
 {
     $this->setSDK($sdk);
     $sdk = $this->getSDK();
     $options = $sdk->getOptions();
     $handler = HandlerStack::create();
     $handler->push(Middleware::mapRequest(function (Request $request) {
         $sdk = $this->getSDK();
         $token = $sdk->getAuthToken()->getToken();
         return $request->withHeader('X-Auth-Token', $token);
     }));
     $handler->push(Middleware::mapResponse(function (GuzzleResponse $guzzleResponse) {
         $response = new Response($guzzleResponse);
         $code = $response->getStatusCode();
         switch ($code) {
             case 400:
                 throw new Validation($response);
             case 401:
                 // invalid creds
                 throw new Unauthenticated($response);
             case 402:
                 // not enough credit
                 throw new Billing($response);
             case 403:
                 // forbidden
                 throw new Unauthorized($response);
             case 404:
                 // not found
                 throw new NotFound($response);
             case 405:
                 // invalid method
                 throw new InvalidMethod($response);
             case 409:
                 // conflicting documents
                 throw new Conflict($response);
             case 429:
                 // too many requests
                 throw new RateLimit($response);
             default:
                 if ($code >= 400 && $code < 500) {
                     throw new ApiException($response);
                 } else {
                     if ($code > 500) {
                         throw new HttpException($response);
                     }
                 }
         }
         return $guzzleResponse;
     }));
     $options['handler'] = $handler;
     $this->setClient(new GuzzleClient($options));
 }
开发者ID:2600hz,项目名称:kazoo-php-sdk,代码行数:56,代码来源:HttpClient.php

示例14: mapRequest

 public function mapRequest()
 {
     return Middleware::mapRequest(function (RequestInterface $request) {
         if ($this->getConfig('auth') == 'bulk') {
             $token = $this->getAccessToken();
             if ($token !== null) {
                 $request = $request->withHeader('X-SFDC-Session', $token->getToken());
                 return $request;
             }
         }
         return $request;
     });
 }
开发者ID:frankkessler,项目名称:salesforce-laravel-oauth2-rest,代码行数:13,代码来源:BulkClient.php

示例15: getGuzzleHandler

 /**
  * @return HandlerStack
  */
 protected function getGuzzleHandler()
 {
     $handler = HandlerStack::create();
     $handler->push(Middleware::mapResponse(function (ResponseInterface $response) {
         $this->lastResponse = $response;
         return $response;
     }));
     $handler->push(Middleware::mapRequest(function (RequestInterface $request) {
         $this->lastRequest = $request;
         return $request;
     }));
     return $handler;
 }
开发者ID:survos,项目名称:platform-api-php,代码行数:16,代码来源:GuzzleListener.php


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