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


PHP Message\Response类代码示例

本文整理汇总了PHP中GuzzleHttp\Message\Response的典型用法代码示例。如果您正苦于以下问题:PHP Response类的具体用法?PHP Response怎么用?PHP Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: parseQuery

 /**
  * @param Response $response
  * @return array
  */
 public static function parseQuery(Response $response)
 {
     $responseBody = $response->getBody();
     $params = [];
     parse_str($responseBody, $params);
     return $params;
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:11,代码来源:ResponseParser.php

示例2: createResponse

 /**
  * Taken from Mink\BrowserKitDriver
  *
  * @param Response $response
  *
  * @return \Symfony\Component\BrowserKit\Response
  */
 protected function createResponse(Response $response)
 {
     $contentType = $response->getHeader('Content-Type');
     $matches = null;
     if (!$contentType or strpos($contentType, 'charset=') === false) {
         $body = $response->getBody(true);
         if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
             $contentType .= ';charset=' . $matches[1];
         }
         $response->setHeader('Content-Type', $contentType);
     }
     $headers = $response->getHeaders();
     $status = $response->getStatusCode();
     $matchesMeta = null;
     $matchesHeader = null;
     $isMetaMatch = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $response->getBody(true), $matchesMeta);
     $isHeaderMatch = preg_match('~(\\d*);?url=(.*)~', (string) $response->getHeader('Refresh'), $matchesHeader);
     $matches = $isMetaMatch ? $matchesMeta : $matchesHeader;
     if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
         $uri = $this->getAbsoluteUri($matches[2]);
         $partsUri = parse_url($uri);
         $partsCur = parse_url($this->getHistory()->current()->getUri());
         foreach ($partsCur as $key => $part) {
             if ($key === 'fragment') {
                 continue;
             }
             if (!isset($partsUri[$key]) || $partsUri[$key] !== $part) {
                 $status = 302;
                 $headers['Location'] = $uri;
                 break;
             }
         }
     }
     return new BrowserKitResponse($response->getBody(), $status, $headers);
 }
开发者ID:alexanderkuz,项目名称:test-yii2,代码行数:42,代码来源:Guzzle.php

示例3: formatProvider

 public function formatProvider()
 {
     $request = new Request('PUT', '/', ['x-test' => 'abc'], Stream::factory('foo'));
     $response = new Response(200, ['X-Baz' => 'Bar'], Stream::factory('baz'));
     $err = new RequestException('Test', $request, $response);
     return [['{request}', [$request], (string) $request], ['{response}', [$request, $response], (string) $response], ['{request} {response}', [$request, $response], $request . ' ' . $response], ['{request} {response}', [$request], $request . ' '], ['{req_headers}', [$request], "PUT / HTTP/1.1\r\nx-test: abc"], ['{res_headers}', [$request, $response], "HTTP/1.1 200 OK\r\nX-Baz: Bar"], ['{res_headers}', [$request], 'NULL'], ['{req_body}', [$request], 'foo'], ['{res_body}', [$request, $response], 'baz'], ['{res_body}', [$request], 'NULL'], ['{method}', [$request], $request->getMethod()], ['{url}', [$request], $request->getUrl()], ['{resource}', [$request], $request->getResource()], ['{req_version}', [$request], $request->getProtocolVersion()], ['{res_version}', [$request, $response], $response->getProtocolVersion()], ['{res_version}', [$request], 'NULL'], ['{host}', [$request], $request->getHost()], ['{hostname}', [$request, $response], gethostname()], ['{hostname}{hostname}', [$request, $response], gethostname() . gethostname()], ['{code}', [$request, $response], $response->getStatusCode()], ['{code}', [$request], 'NULL'], ['{phrase}', [$request, $response], $response->getReasonPhrase()], ['{phrase}', [$request], 'NULL'], ['{error}', [$request, $response, $err], 'Test'], ['{error}', [$request], 'NULL'], ['{req_header_x-test}', [$request], 'abc'], ['{req_header_x-not}', [$request], ''], ['{res_header_X-Baz}', [$request, $response], 'Bar'], ['{res_header_x-not}', [$request, $response], ''], ['{res_header_X-Baz}', [$request], 'NULL']];
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:7,代码来源:FormatterTest.php

示例4: __construct

 /**
  * Constructor
  *
  * @param GuzzleResponse $response
  */
 public function __construct(GuzzleResponse $response)
 {
     $headers = $response->getHeaders();
     //-- this is a hack on my part and I'm terribly sorry it exists
     //-- but deal with it.
     foreach ($headers as $header => $value) {
         $this->headers[$header] = implode(',', array_values((array) $value));
     }
     $this->url = $response->getEffectiveUrl();
     $url_parts = explode('?', $this->url);
     if (isset($url_parts[1])) {
         $query = explode('&', $url_parts[1]);
         foreach ($query as $params) {
             $kv = explode('=', $params);
             $this->params[$kv[0]] = isset($kv[1]) ? $kv[1] : '';
         }
     }
     // $this->params = $response->request_parameters;
     // $this->method = $response->request_method;
     $this->json = $response->json();
     // $json = json_decode($this->json, TRUE);
     $this->data = isset($this->json['data']) ? $this->json['data'] : [];
     $this->meta = isset($this->json['meta']) ? $this->json['meta'] : [];
     if (isset($this->json['code']) && $this->json['code'] !== 200) {
         $this->meta = $this->json;
     }
     $this->pagination = isset($this->json['pagination']) ? $this->json['pagination'] : [];
     $this->user = isset($this->json['user']) ? $this->json['user'] : [];
     $this->access_token = isset($this->json['access_token']) ? $this->json['access_token'] : NULL;
     $this->limit = isset($this->headers[self::RATE_LIMIT_HEADER]) ? $this->headers[self::RATE_LIMIT_HEADER] : 0;
     $this->remaining = isset($this->headers[self::RATE_LIMIT_REMAINING_HEADER]) ? $this->headers[self::RATE_LIMIT_REMAINING_HEADER] : 0;
 }
开发者ID:delta98,项目名称:Instaphp,代码行数:37,代码来源:Response.php

示例5: handleResponse

 protected function handleResponse(Response $response)
 {
     if ($response->getStatusCode() == 200) {
         return $response->getBody()->getContents();
     }
     throw new ApiException('Request failed, received the following status: ' . $response->getStatusCode() . ' Body: ' . $response->getBody()->getContents());
 }
开发者ID:erikdubbelboer,项目名称:atomx-api-php,代码行数:7,代码来源:ApiClient.php

示例6: getMessages

 protected function getMessages(Response $response)
 {
     $body = (string) $response->getBody();
     if (empty($body)) {
         throw new InvalidResponseException('There was no messages returned from the server at: ' . $this->uri);
     }
     $messages = array();
     $messageCounter = 0;
     while ($body) {
         $lineLengthHex = substr($body, 0, 4);
         if (strlen($lineLengthHex) != 4) {
             throw new InvalidResponseException('A corrupt package was received from the server.  Uri: ' . $this->uri);
         }
         if ($lineLengthHex == '0000') {
             $messageCounter++;
             $body = substr_replace($body, '', 0, 4);
             continue;
         }
         $lineLength = hexdec($lineLengthHex);
         $line = substr($body, 4, $lineLength - 4);
         $body = substr_replace($body, '', 0, $lineLength);
         $messages[$messageCounter][] = trim($line);
     }
     return $messages;
 }
开发者ID:reliv,项目名称:git,代码行数:25,代码来源:Client.php

示例7: debug

 function debug(\GuzzleHttp\Message\Response $response)
 {
     $this->dump_respuesta = 'status: ' . $response->getStatusCode() . "<br/>body: <br/>" . $response->getBody();
     //un string encodeado utf-8
     $this->dump_url = $response->getEffectiveUrl();
     //un string encodeado utf-8
 }
开发者ID:emma5021,项目名称:toba,代码行数:7,代码来源:ci_cliente_rest.php

示例8: getResponse

 protected function getResponse($body)
 {
     $stream = Stream::factory($body);
     $response = new Response(200);
     $response->setBody($stream);
     return $response;
 }
开发者ID:eclipsegc,项目名称:acquia-sdk-php-cloud-api,代码行数:7,代码来源:GuzzleTestClient.php

示例9: makeResponse

 /**
  * Create a Response object from a stub.
  *
  * @param $stub
  * @return \GuzzleHttp\Message\Response
  */
 private function makeResponse($stub)
 {
     $response = new Response(200);
     $response->setHeader('Content-Type', 'application/json');
     $responseBody = Stream::factory(fopen('./tests/Destiny/stubs/' . $stub . '.txt', 'r+'));
     $response->setBody($responseBody);
     return $response;
 }
开发者ID:EVPohovich,项目名称:EVPohovich.github.io,代码行数:14,代码来源:TestCase.php

示例10: getMockWithCode

 private function getMockWithCode($code, $body = null)
 {
     $response = new Response($code, array());
     if (isset($body) === true) {
         $response->setBody(Stream::factory(json_encode($body)));
     }
     $this->mockResponse = new Mock(array($response));
 }
开发者ID:everlytic,项目名称:api-wrapper,代码行数:8,代码来源:ApiTester.php

示例11: __construct

 /**
  * Response constructor
  *
  * @param  HttpResponse $httpResponse
  * @return self
  */
 public function __construct(HttpResponse $httpResponse)
 {
     if (stripos($httpResponse->getHeader('Content-Type'), 'text/javascript') !== false) {
         $this->_response = $this->processJson($httpResponse->getBody());
     } else {
         $this->_response = $this->processXml($httpResponse->getBody());
     }
 }
开发者ID:zimbra-api,项目名称:soap,代码行数:14,代码来源:Response.php

示例12: addClientMock

 /**
  * Adds a mock repsonse to the response queue
  *
  * @param \GuzzleHttp\Stream\Stream $data Stream data object
  * @param int $response_code desired response code
  */
 protected function addClientMock($data, $response_code = 200)
 {
     //create a response with the data and response code
     $api_response = new Response($response_code);
     $api_response->setBody($data);
     $mock_response = $this->getMockObject();
     $mock_response->addResponse($api_response);
 }
开发者ID:chielsen,项目名称:guzzle5-oauth2-subscriber,代码行数:14,代码来源:ClientTestCase.php

示例13: wrapResponse

 private static function wrapResponse(Response $response)
 {
     $payload = $response->json(["object" => true]);
     // strip the envelope
     if (isset($payload->data) && isset($payload->meta)) {
         return new static($payload->data);
     }
     return new static($payload);
 }
开发者ID:purplapp,项目名称:purplapp-adn-lib,代码行数:9,代码来源:DataContainerTrait.php

示例14: saveResponseToFile

 protected function saveResponseToFile(Response &$response)
 {
     $fileName = __DIR__ . '\\json\\' . sizeof($this->fileHandles) . '.json';
     $reponseSavedToFile = file_put_contents($fileName, $response->getBody());
     if ($reponseSavedToFile != false) {
         $this->fileHandles[] = $fileName;
     }
     unset($response);
 }
开发者ID:EtienneLamoureux,项目名称:durmand-scriptorium,代码行数:9,代码来源:BatchRequestManager.php

示例15: validateBody

 public function validateBody(Response $response, Spec\Response $responseSpec)
 {
     $actualBody = (string) $response->getBody();
     $actualBodyData = json_decode($actualBody, true);
     if ($actualBodyData !== $responseSpec->getBody()) {
         $message = sprintf("\t\t<error>JSON in body of the response is invalid, actual:</error>\n%s\n\t\t<error>Expected:</error>\n%s", $this->getOutput()->formatArray($actualBodyData, 3), $this->getOutput()->formatArray($responseSpec->getBody(), 3));
         $this->addViolation($message);
     }
 }
开发者ID:talkrz,项目名称:rest-spec,代码行数:9,代码来源:Json.php


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