當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::getBody方法代碼示例

本文整理匯總了PHP中Response::getBody方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::getBody方法的具體用法?PHP Response::getBody怎麽用?PHP Response::getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Response的用法示例。


在下文中一共展示了Response::getBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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:softr,項目名稱:asaas-php-sdk,代碼行數:10,代碼來源:GuzzleHttpAdapter.php

示例2: testConstruct

 public function testConstruct()
 {
     $response = new Response(\Psc\Net\Service::OK, array('blubb' => 'blubb'));
     $this->assertEquals(array('blubb' => 'blubb'), $response->getBody());
     $this->assertEquals(\Psc\Net\Service::OK, $response->getStatus());
     $this->assertInstanceOf('Psc\\Net\\ServiceResponse', $response);
 }
開發者ID:pscheit,項目名稱:psc-cms,代碼行數:7,代碼來源:ResponseTest.php

示例3: handleError

 /**
  * @throws HttpException
  */
 protected function handleError()
 {
     $body = (string) $this->response->getBody();
     $code = (int) $this->response->getStatusCode();
     $content = json_decode($body);
     $error = $content->errors[0];
     throw new HttpException(isset($error) ? $error->description : 'Request not processed.', $code);
 }
開發者ID:skaisser,項目名稱:organizze,代碼行數:11,代碼來源:GuzzleHttpAdapter.php

示例4: testResponseValues

 public function testResponseValues()
 {
     $resource = $this->prophesize(Resource::CLASS);
     $resource->asJson()->willReturn('foobar');
     $response = new Response($resource->reveal());
     $this->assertSame(200, $response->getStatusCode());
     $this->assertSame('application/hal+json', $response->getHeaderLine('Content-Type'));
     $this->assertSame('foobar', (string) $response->getBody());
 }
開發者ID:asylgrp,項目名稱:workbench,代碼行數:9,代碼來源:ResponseTest.php

示例5: trim

 /**
  * @param Response $response
  */
 function __construct(Response $response)
 {
     $this->response = $response;
     if (($h = $response->getHeader("Content-Type", Header::class)) && $h->match("application/json", Header::MATCH_WORD) && ($failure = json_decode($response->getBody()))) {
         $message = $failure->message;
         if (isset($failure->errors)) {
             $this->errors = (array) $failure->errors;
         }
     } else {
         $message = trim($response->getBody()->toString());
     }
     if (!strlen($message)) {
         $message = $response->getTransferInfo("error");
     }
     if (!strlen($message)) {
         $message = $response->getResponseStatus();
     }
     parent::__construct($message, $response->getResponseCode(), null);
 }
開發者ID:m6w6,項目名稱:seekat,代碼行數:22,代碼來源:RequestException.php

示例6: construct

 /**
  * Verify basic functionality of the response object.
  *
  * @test
  * @covers ::__construct
  * @covers ::getHttpCode
  * @covers ::getHeaders
  * @covers ::getBody
  *
  * @return void
  */
 public function construct()
 {
     $httpCode = 200;
     $headers = ['Content-Type' => 'text/json'];
     $body = ['doesnt' => 'matter'];
     $response = new Response($httpCode, $headers, $body);
     $this->assertSame($httpCode, $response->getHttpCode());
     $this->assertSame($headers, $response->getHeaders());
     $this->assertSame($body, $response->getBody());
 }
開發者ID:chadicus,項目名稱:marvel-api-client,代碼行數:21,代碼來源:ResponseTest.php

示例7: sendBody

 /**
  * Sends the body of the response to the client.
  *
  * @return void
  */
 protected function sendBody()
 {
     $body = $this->response->getBody();
     // Response::setBody() makes an is_callable check when setting the value.
     // is_callable is a fairly heavy function due to the checks it has to
     // perform compared to is_string, so this is a safe and fast way, though
     // not necessarily intuitive way to structure the handling.
     if (is_string($body)) {
         echo $body;
     } else {
         call_user_func($body);
     }
 }
開發者ID:rawebone,項目名稱:wilson,代碼行數:18,代碼來源:Sender.php

示例8: __construct

 public function __construct(Response $parent)
 {
     $status = $parent->getStatus();
     $convertToJson = false;
     $ok = self::statusIsOK($status);
     if ($ok) {
         $contentType = $parent->getHeader('Content-Type');
         if (!empty($contentType)) {
             $convertToJson = stristr($contentType, '/json') !== false;
         }
     }
     $bodyString = $parent->getBody();
     parent::__construct($convertToJson ? json_decode($bodyString) : $bodyString, $parent->getHeaders(), $status);
     $this->ok = $ok;
 }
開發者ID:jonasvr,項目名稱:lockedornot,代碼行數:15,代碼來源:InfogramResponse.php

示例9: respond

 public function respond(Response $response)
 {
     $ajaxResponse = array();
     $ajaxResponse['components'] = array();
     $ajaxResponse['header'] = array();
     $ajaxResponse['script'] = $this->script;
     $headerResponse = new HeaderResponse($response);
     foreach ($this->components as $component) {
         $response->clean();
         $component->beforePageRender();
         $component->render();
         $value = $response->getBody();
         $response->clean();
         array_push($ajaxResponse['components'], array('id' => $component->getMarkupId(), 'value' => $value));
         $this->renderComponentHeader($component, $response, $headerResponse);
         $value = $response->getBody();
         array_push($ajaxResponse['header'], $value);
         $response->clean();
     }
     FeedbackModel::get()->cleanup();
     header('Content-Type: application/json');
     print json_encode($ajaxResponse);
 }
開發者ID:picon,項目名稱:picon-framework,代碼行數:23,代碼來源:AjaxRequestTarget.php

示例10: import

 /**
  * Import handler for the endpoint's underlying data
  *
  * \seekat\Call will call this when the request will have finished.
  *
  * @param Response $response
  * @return API self
  * @throws UnexpectedValueException
  * @throws RequestException
  * @throws \Exception
  */
 function import(Response $response) : API
 {
     $this->__log->info(__FUNCTION__ . ": " . $response->getInfo(), ["url" => (string) $this->__url]);
     if ($response->getResponseCode() >= 400) {
         $e = new RequestException($response);
         $this->__log->critical(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     if (!($type = $response->getHeader("Content-Type", Header::class))) {
         $e = new RequestException($response);
         $this->__log->error(__FUNCTION__ . ": Empty Content-Type -> " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     try {
         $this->__type = new ContentType($type);
         $this->__data = $this->__type->parseBody($response->getBody());
         if ($link = $response->getHeader("Link", Header::class)) {
             $this->__links = new Links($link);
         }
     } catch (\Exception $e) {
         $this->__log->error(__FUNCTION__ . ": " . $e->getMessage(), ["url" => (string) $this->__url]);
         throw $e;
     }
     return $this;
 }
開發者ID:m6w6,項目名稱:seekat,代碼行數:36,代碼來源:API.php

示例11: format

 /**
  * Convert guzzle response to data
  *
  * @param Response $response GuzzleHttp\Response
  *
  * @return string or array           data
  */
 public function format($response)
 {
     $data = (string) $response->getBody();
     if ($this->option('json') === true) {
         return $data;
     }
     return json_decode($data);
 }
開發者ID:contactmyreps,項目名稱:sunlight-php,代碼行數:15,代碼來源:BaseAPI.php

示例12: render

 protected function render($data = null, $nested = true)
 {
     extract($data);
     ob_start();
     // Include view files
     if ($nested) {
         include $this->getTemplatePathname('header.php');
     }
     foreach ($this->getTemplates() as $tpl) {
         include $tpl;
     }
     if ($nested) {
         include $this->getTemplatePathname('footer.php');
     }
     $output = ob_get_clean();
     Response::getBody()->write($output);
     return Container::get('response');
 }
開發者ID:featherbb,項目名稱:featherbb,代碼行數:18,代碼來源:View.php

示例13: getBody

 /**
  * Get the response body as string
  *
  * This method returns the body of the HTTP response (the content), as it
  * should be in it's readable version - that is, after decoding it (if it
  * was decoded), deflating it (if it was gzip compressed), etc.
  *
  * If you want to get the raw body (as transfered on wire) use
  * $this->getRawBody() instead.
  *
  * @return string
  */
 public function getBody()
 {
     if ($this->stream != null) {
         $this->readStream();
     }
     return parent::getBody();
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:19,代碼來源:Stream.php

示例14: getResponseBody

 /**
  * Get the response body after the request has been sent.
  * If redirects were allowed and several responses were received, the data references the last received response.
  * @return string
  */
 public function getResponseBody()
 {
     return $this->response->getBody();
 }
開發者ID:novotnyj,項目名稱:http-helper,代碼行數:9,代碼來源:Request.php

示例15: parseSignedJSON

 /**
  * Parse a signed JSON response
  *
  * @param Response $response
  * @param SignaturePublicKey $publicKey
  * @return mixed
  * @throws SignatureFailed
  * @throws TransferException
  */
 public function parseSignedJSON(Response $response, SignaturePublicKey $publicKey)
 {
     $code = $response->getStatusCode();
     if ($code >= 200 && $code < 300) {
         $body = (string) $response->getBody();
         $firstNewLine = \strpos($body, "\n");
         // There should be a newline immediately after the base64urlsafe-encoded signature
         if ($firstNewLine !== self::ENCODED_SIGNATURE_LENGTH) {
             throw new SignatureFailed(\sprintf("First newline found at position %s, expected %d.\n%s", \print_r($firstNewLine, true), \print_r(self::ENCODED_SIGNATURE_LENGTH, true), Base64::encode($body)));
         }
         $sig = Base64UrlSafe::decode(Binary::safeSubstr($body, 0, 88));
         $msg = Binary::safeSubstr($body, 89);
         if (!Asymmetric::verify($msg, $publicKey, $sig, true)) {
             throw new SignatureFailed();
         }
         return \Airship\parseJSON($msg, true);
     }
     throw new TransferException();
 }
開發者ID:paragonie,項目名稱:airship,代碼行數:28,代碼來源:Hail.php


注:本文中的Response::getBody方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。