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


PHP Middleware::mapResponse方法代码示例

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


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

示例1: notifyWhenResponseIsComplete

 public function notifyWhenResponseIsComplete()
 {
     parent::$stack->push(Middleware::mapResponse(function (ResponseInterface $response) {
         print 'Response!' . PHP_EOL;
         return $response;
     }));
 }
开发者ID:rbadillap,项目名称:twitterstreaming,代码行数:7,代码来源:MyGuzzleMiddleware.php

示例2: __construct

 public function __construct()
 {
     static::init();
     $Stack = new HandlerStack();
     $Stack->setHandler(new CurlHandler());
     /**
      * Здесь ставим ловушку, чтобы с помощью редиректов
      *   определить адрес сервера, который сможет отсылать сообщения
      */
     $Stack->push(Middleware::mapResponse(function (ResponseInterface $Response) {
         $code = $Response->getStatusCode();
         if ($code >= 301 && $code <= 303 || $code == 307 || $code == 308) {
             $location = $Response->getHeader('Location');
             preg_match('/https?://([^-]*-)client-s/', $location, $matches);
             if (array_key_exists(1, $matches)) {
                 $this->cloud = $matches[1];
             }
         }
         return $Response;
     }));
     /**
      * Ловушка для отлова хедера Set-RegistrationToken
      * Тоже нужен для отправки сообщений
      */
     $Stack->push(Middleware::mapResponse(function (ResponseInterface $Response) {
         $header = $Response->getHeader("Set-RegistrationToken");
         if (count($header) > 0) {
             $this->regToken = trim(explode(';', $header[0])[0]);
         }
         return $Response;
     }));
     //$cookieJar = new FileCookieJar('cookie.txt', true);
     $this->client = new Client(['handler' => $Stack, 'cookies' => true]);
 }
开发者ID:tafint,项目名称:skype,代码行数:34,代码来源:Transport.php

示例3: __construct

 /**
  * @param string $clientId
  * @param string $clientSecret
  */
 public function __construct($clientId, $clientSecret)
 {
     $stack = HandlerStack::create();
     $stack->push(Middleware::mapResponse(function (Response $response) {
         $jsonStream = new JsonStream($response->getBody());
         return $response->withBody($jsonStream);
     }));
     $guzzle = new Guzzle(['base_uri' => 'https://api.shutterstock.com/v2/', 'auth' => [$clientId, $clientSecret], 'handler' => $stack]);
     $this->guzzle = $guzzle;
 }
开发者ID:jacobemerick,项目名称:php-shutterstock-api,代码行数:14,代码来源:Client.php

示例4: getCallable

 /**
  * @return callable
  */
 public function getCallable()
 {
     return Middleware::mapResponse(function (ResponseInterface $response) {
         if ($response->hasHeader(AbstractHttpClient::HEADER_HOST_ZED)) {
             $message = sprintf('Transfer response [%s]', $response->getStatusCode());
             $this->getLogger()->info($message, ['guzzle-body' => $response->getBody()->getContents()]);
         }
         return $response;
     });
 }
开发者ID:spryker,项目名称:ZedRequest,代码行数:13,代码来源:ZedResponseLogPlugin.php

示例5: testConstructSetsJsonMiddleware

 public function testConstructSetsJsonMiddleware()
 {
     $stack = HandlerStack::create();
     $stack->push(Middleware::mapResponse(function (Response $response) {
         $jsonStream = new JsonStream($response->getBody());
         return $response->withBody($jsonStream);
     }));
     $guzzle = new Guzzle(['base_uri' => 'https://api.shutterstock.com/v2/', 'auth' => ['client_id', 'client_secret'], 'handler' => $stack]);
     $client = $this->getClient();
     $this->assertAttributeEquals($guzzle, 'guzzle', $client);
 }
开发者ID:jacobemerick,项目名称:php-shutterstock-api,代码行数:11,代码来源:ClientTest.php

示例6: errorHandler

 private function errorHandler()
 {
     $handler = \GuzzleHttp\HandlerStack::create();
     $handler->push(\GuzzleHttp\Middleware::mapResponse(function ($response) {
         if ($response->getStatusCode() >= 400) {
             $data = json_decode($response->getBody());
             throw new Exception(sprintf('%s %s – %s', $response->getStatusCode(), $data->error, $data->detail));
         }
         return $response;
     }));
     return $handler;
 }
开发者ID:taxjar,项目名称:taxjar-php,代码行数:12,代码来源:TaxJar.php

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

示例8: testMapsResponse

 public function testMapsResponse()
 {
     $h = new MockHandler([new Response(200)]);
     $stack = new HandlerStack($h);
     $stack->push(Middleware::mapResponse(function (ResponseInterface $response) {
         return $response->withHeader('Bar', 'foo');
     }));
     $comp = $stack->resolve();
     $p = $comp(new Request('PUT', 'http://www.google.com'), []);
     $p->wait();
     $this->assertEquals('foo', $p->wait()->getHeaderLine('Bar'));
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:12,代码来源:MiddlewareTest.php

示例9: mapResponse

 /**
  * @codeCoverageIgnore
  */
 public static function mapResponse(callable $fn) : callable
 {
     return GuzzleMiddleware::mapResponse($fn);
 }
开发者ID:php-opencloud,项目名称:common,代码行数:7,代码来源:Middleware.php

示例10: buildClientAndRequest

 private function buildClientAndRequest()
 {
     $this->logger->info("Getting Request Client");
     $stack = new HandlerStack();
     $stack->setHandler(new CurlHandler());
     $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
         return $this->addRequestHeaders($request);
     }));
     $stack->push(Middleware::mapResponse(function (ResponseInterface $response) {
         $this->logger->info('Response status code: ' . $response->getStatusCode());
         $this->validateResponse($response);
         return $response;
     }));
     $this->client = new Client(['handler' => $stack, 'base_uri' => $this->baseAddress, 'verify' => false]);
     $this->logger->info("Request URI : " . $this->mozuUrl->getUrl());
     $this->request = new Psr7\Request($this->mozuUrl->getVerb(), $this->mozuUrl->getUrl(), array(), $this->requestBody);
 }
开发者ID:sgorman,项目名称:mozu-php-sdk,代码行数:17,代码来源:MozuClient.php

示例11: testInvalidRight

 /**
  * Test invalid rights
  */
 public function testInvalidRight()
 {
     $this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException');
     $handlerStack = $this->client->getConfig('handler');
     $handlerStack->push(Middleware::mapResponse(function (Response $response) {
         $body = $response->getBody();
         $body->write('{\\"message\\":\\"Invalid credentials\\"}');
         return $response->withStatus(403)->withHeader('Content-Type', 'application/json; charset=utf-8')->withHeader('Content-Length', 37)->withBody($body);
     }));
     $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client);
     $invoker = self::getPrivateMethod('rawCall');
     $invoker->invokeArgs($api, ['GET', '/me']);
 }
开发者ID:ByScripts,项目名称:php-ovh,代码行数:16,代码来源:ApiTest.php

示例12: __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


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