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


PHP ResponseInterface::getBody方法代码示例

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


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

示例1: _getResult

 /**
  * @param ResponseInterface $response
  *
  * @return ApiResult
  */
 protected function _getResult($response)
 {
     if (!$response instanceof ResponseInterface) {
         throw new \InvalidArgumentException("{$response} should be an instance of ResponseInterface");
     }
     $result = new ApiResult();
     $result->setStatusCode($response->getStatusCode());
     $callId = $response->getHeader('X-Call-Id');
     if (!empty($callId)) {
         $result->setCallId($callId);
     }
     $decoded = json_decode((string) $response->getBody());
     if (isset($decoded->meta) && isset($decoded->data) && isset($decoded->meta->code) && $decoded->meta->code == $response->getStatusCode()) {
         $meta = $decoded->meta;
         $data = $decoded->data;
         if (isset($meta->message)) {
             $result->setStatusMessage($meta->message);
         }
         $result->setContent(json_encode($data));
     } else {
         $result->setContent((string) $response->getBody());
     }
     $result->setHeaders($response->getHeaders());
     return $result;
 }
开发者ID:fortifi,项目名称:api,代码行数:30,代码来源:Guzzle5Connection.php

示例2: save

 public function save(RequestInterface $request, ResponseInterface $response)
 {
     $ttl = (int) $request->getConfig()->get('cache.ttl');
     $key = $this->getCacheKey($request);
     // Persist the response body if needed
     if ($response->getBody() && $response->getBody()->getSize() > 0) {
         $this->cache->save($key, array('code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()), $ttl);
         $request->getConfig()->set('cache.key', $key);
     }
 }
开发者ID:QSimon,项目名称:CsaGuzzleBundle,代码行数:10,代码来源:CacheStorage.php

示例3: theCaldavHttpStatusCodeShouldBe

 /**
  * @Then The CalDAV HTTP status code should be :code
  */
 public function theCaldavHttpStatusCodeShouldBe($code)
 {
     if ((int) $code !== $this->response->getStatusCode()) {
         throw new \Exception(sprintf('Expected %s got %s', (int) $code, $this->response->getStatusCode()));
     }
     $body = $this->response->getBody()->getContents();
     if ($body && substr($body, 0, 1) === '<') {
         $reader = new Sabre\Xml\Reader();
         $reader->xml($body);
         $this->responseXml = $reader->parse();
     }
 }
开发者ID:gvde,项目名称:core,代码行数:15,代码来源:CalDavContext.php

示例4: formatBody

 /**
  * @param RequestInterface|ResponseInterface $message
  * @return string
  */
 protected function formatBody($message)
 {
     $header = $message->getHeader('Content-Type');
     if (JsonStringFormatter::isJsonHeader($header)) {
         $formatter = new JsonStringFormatter();
         return $formatter->format($message->getBody());
     } elseif (XmlStringFormatter::isXmlHeader($header)) {
         $formatter = new XmlStringFormatter();
         return $formatter->format($message->getBody());
     }
     $factory = new StringFactoryFormatter();
     return $factory->format($message->getBody());
 }
开发者ID:glooby,项目名称:debug-bundle,代码行数:17,代码来源:AbstractMessageFormatter.php

示例5: setStatusTestingApp

 protected function setStatusTestingApp($enabled)
 {
     $this->sendingTo($enabled ? 'post' : 'delete', '/cloud/apps/testing');
     $this->theHTTPStatusCodeShouldBe('200');
     $this->theOCSStatusCodeShouldBe('100');
     $this->sendingTo('get', '/cloud/apps?filter=enabled');
     $this->theHTTPStatusCodeShouldBe('200');
     if ($enabled) {
         PHPUnit_Framework_Assert::assertContains('testing', $this->response->getBody()->getContents());
     } else {
         PHPUnit_Framework_Assert::assertNotContains('testing', $this->response->getBody()->getContents());
     }
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:13,代码来源:AppConfiguration.php

示例6: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody();
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
 }
开发者ID:mix376,项目名称:DigitalOceanV2,代码行数:10,代码来源:GuzzleHttpAdapter.php

示例7: decode

 public function decode(ResponseInterface $raw, $totalTime = 0)
 {
     $executionTime = $callTime = 0;
     if ($raw->hasHeader('X-Execution-Time')) {
         $executionTime = $raw->getHeader('X-Execution-Time');
     }
     if ($raw->hasHeader('X-Call-Time')) {
         $callTime = $raw->getHeader('X-Call-Time');
     }
     $body = '';
     try {
         $body = (string) $raw->getBody();
         $result = $this->_getDecoder()->decode($body, self::FORMAT, $this->_getDecodeContext());
     } catch (\Exception $e) {
         if (!empty($body)) {
             $body = ' (' . $body . ')';
         }
         error_log("Invalid API Response: " . $body);
         throw new InvalidApiResponseException("Unable to decode raw api response.", 500, $e);
     }
     if (!property_exists($result, 'type') || !property_exists($result, 'status') || !property_exists($result, 'result') || !property_exists($result->status, 'message') || !property_exists($result->status, 'code')) {
         error_log("Invalid API Result: " . json_encode($result));
         throw new InvalidApiResponseException("Invalid api result", 500);
     }
     if ($executionTime === 0) {
         $executionTime = $totalTime;
     }
     if ($callTime === 0) {
         $callTime = $executionTime;
     }
     return ResponseBuilder::create(ApiCallData::create($result->type, $result->result, $result->status->code, $result->status->message, (double) str_replace([',', 'ms'], '', $totalTime), (double) str_replace([',', 'ms'], '', $executionTime), (double) str_replace([',', 'ms'], '', $callTime)));
 }
开发者ID:packaged,项目名称:api,代码行数:32,代码来源:AbstractApiFormat.php

示例8: decodeHttpResponse

 /**
  * Decode an HTTP Response.
  * @static
  * @throws Google_Service_Exception
  * @param GuzzleHttp\Message\RequestInterface $response The http response to be decoded.
  * @param GuzzleHttp\Message\ResponseInterface $response
  * @return mixed|null
  */
 public static function decodeHttpResponse(ResponseInterface $response, RequestInterface $request = null)
 {
     $body = (string) $response->getBody();
     $code = $response->getStatusCode();
     $result = null;
     // return raw response when "alt" is "media"
     $isJson = !($request && 'media' == $request->getQuery()->get('alt'));
     // set the result to the body if it's not set to anything else
     if ($isJson) {
         try {
             $result = $response->json();
         } catch (ParseException $e) {
             $result = $body;
         }
     } else {
         $result = $body;
     }
     // retry strategy
     if (intVal($code) >= 300) {
         $errors = null;
         // Specific check for APIs which don't return error details, such as Blogger.
         if (isset($result['error']) && isset($result['error']['errors'])) {
             $errors = $result['error']['errors'];
         }
         throw new Google_Service_Exception($body, $code, null, $errors);
     }
     return $result;
 }
开发者ID:OlivierBarbier,项目名称:google-api-php-client,代码行数:36,代码来源:REST.php

示例9: requestTagsForUser

    /**
     * Returns all tags for a given user
     *
     * @param string $user
     * @return array
     */
    private function requestTagsForUser($user)
    {
        try {
            $request = $this->client->createRequest('PROPFIND', $this->baseUrl . '/remote.php/dav/systemtags/', ['body' => '<?xml version="1.0"?>
<d:propfind  xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
  <d:prop>
    <oc:id />
    <oc:display-name />
    <oc:user-visible />
    <oc:user-assignable />
  </d:prop>
</d:propfind>', 'auth' => [$user, $this->getPasswordForUser($user)], 'headers' => ['Content-Type' => 'application/json']]);
            $this->response = $this->client->send($request);
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            $this->response = $e->getResponse();
        }
        $tags = [];
        $service = new Sabre\Xml\Service();
        $parsed = $service->parse($this->response->getBody()->getContents());
        foreach ($parsed as $entry) {
            $singleEntry = $entry['value'][1]['value'][0]['value'];
            if (empty($singleEntry[0]['value'])) {
                continue;
            }
            $tags[$singleEntry[0]['value']] = ['display-name' => $singleEntry[1]['value'], 'user-visible' => $singleEntry[2]['value'], 'user-assignable' => $singleEntry[3]['value']];
        }
        return $tags;
    }
开发者ID:stweil,项目名称:owncloud-core,代码行数:34,代码来源:TagsContext.php

示例10:

 function it_should_make_post_request(ResponseInterface $responce)
 {
     $responce->getHeader("Content-Type")->willReturn('blablaxmlblabla');
     $responce->getBody()->willReturn('<xml></xml>');
     $this->client->post(Argument::any(), Argument::any())->willReturn($responce);
     $responce->xml()->willReturn(new \SimpleXMLElement('<xml></xml>'));
     $this->post(Argument::type('string'))->shouldBeAnInstanceOf('Bxav\\Component\\ResellerClub\\Model\\XmlResponse');
 }
开发者ID:bxav,项目名称:service_handler,代码行数:8,代码来源:ResellerClubClientSpec.php

示例11: __construct

 /**
  * @param ResponseInterface $response raw json response
  * @param bool              $throw    Should throw API errors as exceptions
  *
  * @throws \Exception
  */
 public function __construct(ResponseInterface $response = null, $throw = true)
 {
     if ($response !== null) {
         $this->_executionTime = $response->getHeader('X-Execution-Time');
         $this->_callTime = $response->getHeader('X-Call-Time');
         $this->readJson((string) $response->getBody(), $throw);
     }
 }
开发者ID:jdi,项目名称:tntaffiliate,代码行数:14,代码来源:ApiResult.php

示例12:

 function it_should_return_a_service_response_when_verifying_an_ipn_message(Client $httpClient, Message $message, ResponseInterface $response)
 {
     $response->getBody()->willReturn('foo');
     $httpClient->post(Argument::type('string'), Argument::type('array'))->willReturn($response);
     $message->getAll()->willReturn(['foo' => 'bar']);
     $response = $this->verifyIpnMessage($message);
     $response->shouldHaveType('Mdb\\PayPal\\Ipn\\ServiceResponse');
     $response->getBody()->shouldReturn('foo');
 }
开发者ID:bogarin,项目名称:paypal-ipn-listener,代码行数:9,代码来源:GuzzleServiceSpec.php

示例13: getRawResponseBody

 /**
  * @param ResponseInterface|Response6Interface $response
  *
  * @return string
  *
  * @throws CommunicationException
  */
 public static function getRawResponseBody($response)
 {
     $statusCode = $response->getStatusCode();
     $rawResponse = $response->getBody()->getContents();
     if ($statusCode != 200) {
         throw CommunicationException::createFromHTTPResponse($statusCode, $rawResponse);
     }
     return $rawResponse;
 }
开发者ID:jerzinet,项目名称:webservice,代码行数:16,代码来源:Parser.php

示例14: handleError

 /**
  * @throws ApiException
  */
 protected function handleError($getCode = false)
 {
     $code = (int) $this->response->getStatusCode();
     if ($getCode) {
         return $code;
     }
     $content = (string) $this->response->getBody();
     $this->reportError($code, $content);
 }
开发者ID:malc0mn,项目名称:vultr-api-client,代码行数:12,代码来源:GuzzleHttpAdapter.php

示例15: processResponse

 /**
  * @param \GuzzleHttp\Message\ResponseInterface $response
  * @return Language[]
  */
 public function processResponse(\GuzzleHttp\Message\ResponseInterface $response)
 {
     $xml = simplexml_load_string($response->getBody()->getContents());
     $languages = [];
     foreach ($xml->string as $language) {
         $languages[] = new Language($language);
     }
     return $languages;
 }
开发者ID:badams,项目名称:microsoft-translator,代码行数:13,代码来源:GetLanguagesForTranslate.php


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