当前位置: 首页>>代码示例>>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;未经允许,请勿转载。