當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。