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


PHP Response::getBody方法代码示例

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


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

示例1: getEvents

 /**
  * Returns generator that yields new event when it's available on stream.
  *
  * @return Event[]
  */
 public function getEvents()
 {
     $buffer = '';
     $body = $this->response->getBody();
     while (true) {
         // if server close connection - try to reconnect
         if ($body->eof()) {
             // wait retry period before reconnection
             sleep($this->retry / 1000);
             $this->connect();
             // clear buffer since there is no sense in partial message
             $buffer = '';
         }
         $buffer .= $body->read(1);
         if (preg_match(self::END_OF_MESSAGE, $buffer)) {
             $parts = preg_split(self::END_OF_MESSAGE, $buffer, 2);
             $rawMessage = $parts[0];
             $remaining = $parts[1];
             $buffer = $remaining;
             $event = Event::parse($rawMessage);
             // if message contains id set it to last received message id
             if ($event->getId()) {
                 $this->lastId = $event->getId();
             }
             // take into account server request for reconnection delay
             if ($event->getRetry()) {
                 $this->retry = $event->getRetry();
             }
             (yield $event);
         }
     }
 }
开发者ID:obsh,项目名称:sse-client,代码行数:37,代码来源:Client.php

示例2: theResponseIsJson

 /**
  * @Then the response is JSON
  */
 public function theResponseIsJson()
 {
     $this->responseData = json_decode($this->response->getBody());
     $expectedType = 'object';
     $actualObject = $this->responseData;
     PHPUnit::assertInternalType($expectedType, $actualObject);
 }
开发者ID:rupertjeff,项目名称:ascension-card-db,代码行数:10,代码来源:ApiContext.php

示例3: __construct

 /**
  * Initialize
  *
  * @param HttpResponse $response
  */
 public function __construct(HttpResponse $response)
 {
     $this->response = $response;
     if ($this->isSuccessful()) {
         $this->messages = new MessageGroup(json_decode($this->response->getBody(), true));
     }
 }
开发者ID:goqihoo,项目名称:aliyun,代码行数:12,代码来源:Response.php

示例4: __construct

 public function __construct(\GuzzleHttp\Psr7\Response $response)
 {
     $json = false;
     $data = $response->getBody();
     $this->rawData = $data;
     $this->response = $response;
     if ($response->hasHeader('Content-Type')) {
         // Let's see if it is JSON
         $contentType = $response->getHeader('Content-Type');
         if (strstr($contentType[0], 'json')) {
             $json = true;
             $data = json_decode($data);
         }
     }
     if (!$json) {
         // We can do another test here
         $decoded = json_decode($response->getBody());
         if ($decoded) {
             $json = true;
             $data = $decoded;
         }
     }
     $this->setData($data);
     $this->setIsJson($json);
 }
开发者ID:webmakersteve,项目名称:instagram-php,代码行数:25,代码来源:Response.php

示例5: contents

 /**
  * Get the response body contents.
  *
  * @return string
  *   The original body contents.
  */
 public function contents()
 {
     $body = $this->response->getBody();
     if (!$body) {
         return null;
     }
     return $body->getContents();
 }
开发者ID:droath,项目名称:webmerge,代码行数:14,代码来源:ResponseData.php

示例6: correctIpReturnsDecodedInfo

 /**
  * @test
  */
 public function correctIpReturnsDecodedInfo()
 {
     $expected = ['foo' => 'bar', 'baz' => 'foo'];
     $response = new Response();
     $response->getBody()->write(json_encode($expected));
     $response->getBody()->rewind();
     $this->client->get('http://freegeoip.net/json/1.2.3.4')->willReturn($response)->shouldBeCalledTimes(1);
     $this->assertEquals($expected, $this->ipResolver->resolveIpLocation('1.2.3.4'));
 }
开发者ID:shlinkio,项目名称:shlink,代码行数:12,代码来源:IpLocationResolverTest.php

示例7: deduce

 /**
  * @return ErrorResponse|SuccessResponse
  */
 public function deduce()
 {
     /* @var array $response */
     $response = (array) json_decode($this->response->getBody()->getContents());
     if (array_key_exists('type', $response) && $response['type'] === 'error') {
         return new ErrorResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
     }
     return new SuccessResponse($this->response->getStatusCode(), $this->response->getHeaders(), $this->response->getBody());
 }
开发者ID:NeokamiCode,项目名称:box-php-sdk,代码行数:12,代码来源:Response.php

示例8: __construct

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

示例9: getResponse

 private function getResponse(HttpResponse $httpResponse)
 {
     $response = new Response();
     if ($httpResponse->getBody()) {
         $resp = (string) $httpResponse->getBody();
         $decoded = json_decode($resp, true);
         $response->setBody($decoded);
     }
     return $response;
 }
开发者ID:powellke,项目名称:neo4j-neoclient,代码行数:10,代码来源:GuzzleHttpClient.php

示例10: parse

 protected function parse(Response $response, $type = 'json')
 {
     switch ($type) {
         case 'json':
             return json_decode((string) $response->getBody(), true);
         case 'xml':
             return simplexml_load_file((string) $response->getBody());
         default:
             throw new Exception("Invalid repsonse type");
     }
 }
开发者ID:arleslie,项目名称:resellerclub-php-sdk,代码行数:11,代码来源:Helper.php

示例11: buildResponse

 /**
  * Create an array of the response object
  *
  * @param Response $response
  * @return array
  */
 private function buildResponse(Response $response)
 {
     $this->response['body'] = $response->getBody()->getContents();
     $this->response['size'] = $response->getBody()->getSize();
     $this->response['status_code'] = $response->getStatusCode();
     //Build the response headers
     $headers = $response->getHeaders();
     foreach ($headers as $name => $value) {
         $this->response['headers'][$name] = $value;
     }
     return $this->response;
 }
开发者ID:sebas7dk,项目名称:sainsburys-product-scraper,代码行数:18,代码来源:HttpClient.php

示例12: parseResponse

 /**
  * @param Response $response
  * @return array Parsed JSON result
  * @throws JotihuntApiException
  */
 public function parseResponse(Response $response)
 {
     try {
         $resultArray = json_decode($response->getBody()->getContents(), true);
         if (!is_array($resultArray)) {
             throw new JotihuntApiException('Jotihunt error: Unexpected result: ' . $response->getBody()->getContents());
         }
         if (array_key_exists('error', $resultArray)) {
             throw new JotihuntApiException('Jotihunt error: ' . $resultArray['error']);
         }
         return $resultArray;
     } catch (\RuntimeException $e) {
         throw new JotihuntApiException('Jotihunt error: ' . $e->getMessage());
     }
 }
开发者ID:stephangroen,项目名称:jotihunt-php-client,代码行数:20,代码来源:Connection.php

示例13: toXML

 /**
  * Returns response in XML format
  * @return \SimpleXMLElement
  * @throws Exception
  */
 public function toXML()
 {
     // Allow Internal Error Processing
     libxml_use_internal_errors(true);
     // Load Response to XML
     $xml = simplexml_load_string($this->response->getBody()->getContents());
     // Check for Errors
     $xml_error = libxml_get_last_error();
     if ($xml_error !== false) {
         // Clear errors for next request
         libxml_clear_errors();
         throw new Exception($xml_error->message, $xml_error->code);
     }
     return $xml;
 }
开发者ID:rearley,项目名称:ebay,代码行数:20,代码来源:Response.php

示例14: getJsonResponse

 public static function getJsonResponse(GuzzleHttp\Psr7\Response $res)
 {
     if ($res->getStatusCode() == 200) {
         return json_decode($res->getBody()->getContents(), true);
     }
     return [];
 }
开发者ID:jrm2k6,项目名称:laradit,代码行数:7,代码来源:APIRequestHelper.php

示例15: __construct

 /**
  * PlayerCommandsResponse constructor.
  * @param Response $response
  */
 public function __construct(Response $response)
 {
     $object = json_decode($response->getBody());
     foreach ($object->commands as $command) {
         $this->commands[] = new Command($command);
     }
 }
开发者ID:BuycraftPlugin,项目名称:Plugin-API-PHP,代码行数:11,代码来源:PlayerCommandsResponse.php


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